IPTables-libiptc
view release on metacpan or search on metacpan
fallback/const-xs.inc view on Meta::CPAN
dTARGET;
#endif
STRLEN len;
int type;
IV iv;
/* NV nv; Uncomment this if you need to return NVs */
/* const char *pv; Uncomment this if you need to return PVs */
INPUT:
SV * sv;
const char * s = SvPV(sv, len);
PPCODE:
/* Change this to constant(aTHX_ s, len, &iv, &nv);
if you need to return both NVs and IVs */
type = constant(aTHX_ s, len, &iv);
/* Return 1 or 2 items. First is error message, or undef if no error.
Second, if present, is found value */
switch (type) {
case PERL_constant_NOTFOUND:
sv = sv_2mortal(newSVpvf("%s is not a valid IPTables::libiptc macro", s));
PUSHs(sv);
break;
# Listing related
##########################################
void
list_chains(self)
IPTables::libiptc self
PREINIT:
char * chain;
SV * sv;
int count = 0;
PPCODE:
sv = ST(0);
if (self == NULL) croak(ERRSTR_NULL_HANDLE);
else {
chain = (char *)iptc_first_chain(self);
while(chain) {
count++;
if (GIMME_V == G_ARRAY)
XPUSHs(sv_2mortal(newSVpv(chain, 0)));
chain = (char *)iptc_next_chain(self);
}
IPTables::libiptc self
ipt_chainlabel chain
char * type
PREINIT:
SV * sv;
int count = 0;
struct ipt_entry *entry;
int the_type;
char buf[100]; /* I should be enough with only 32 chars */
static char * errmsg = "Wrong listing type requested.";
PPCODE:
sv = ST(0);
if (self == NULL) croak(ERRSTR_NULL_HANDLE);
else {
if(iptc_is_chain(chain, self)) {
entry = (struct ipt_entry *)iptc_first_rule(chain, self);
/* Parse what type was requested */
if (strcasecmp(type, "dst") == 0) the_type = 'd';
else if (strcasecmp(type, "src") == 0) the_type = 's';
else croak(errmsg);
void
get_policy(self, chain)
IPTables::libiptc self
ipt_chainlabel chain
PREINIT:
struct ipt_counters counters;
SV * sv;
char * policy;
char * temp;
PPCODE:
sv = ST(0);
if (self == NULL) croak(ERRSTR_NULL_HANDLE);
else {
if((policy = (char *)iptc_get_policy(chain, &counters, self))) {
XPUSHs(sv_2mortal(newSVpv(policy, 0)));
asprintf(&temp, "%llu", counters.pcnt);
XPUSHs(sv_2mortal(newSVpv(temp, 0)));
free(temp);
asprintf(&temp, "%llu", counters.bcnt);
XPUSHs(sv_2mortal(newSVpv(temp, 0)));
ipt_chainlabel chain
ipt_chainlabel policy
unsigned int pkt_cnt
unsigned int byte_cnt
PREINIT:
struct ipt_counters * counters = NULL;
struct ipt_counters old_counters;
char * old_policy;
char * temp;
int retval;
PPCODE:
if (self == NULL) croak(ERRSTR_NULL_HANDLE);
else {
if(pkt_cnt && byte_cnt) {
counters = malloc(sizeof(struct ipt_counters));
counters->pcnt = pkt_cnt;
counters->bcnt = byte_cnt;
}
/* Read the old policy and counters */
old_policy = (char *)iptc_get_policy(chain, &old_counters, self);
( run in 1.024 second using v1.01-cache-2.11-cpan-5511b514fd6 )