perl ipfw table add IPPROTO_IP, IP_FW_TABLE_ADD [Raw&Packet Sockets]

Code:
static PyObject *
ipfw_table_add(PyObject *self, PyObject *args)
{
    int table,mask=32,value=0;
    char *ip_str;
    int i,s=-1;
    ipfw_table_entry ent;
    if (!PyArg_ParseTuple(args,"is|ii",&table,&ip_str,&mask,&value))
        return NULL;
    // Table add entry
    if(table<MIN_TABLE){ 
        PyErr_SetString(IPFWError, "m..");
        return NULL;
    }
    ent.value = value;
    ent.tbl = table;
    ent.masklen = mask;
    if(!inet_aton(ip_str, (struct in_addr*)&ent.addr)){
        PyErr_SetString(IPFWError, "ip address bad");
        return NULL;
    }
    s=socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
    if(s<0){ 
        PyErr_SetString(IPFWError, "socket fail");
        return NULL;
    }
    i = setsockopt(s, IPPROTO_IP, IP_FW_TABLE_ADD, &ent, sizeof(ent));
    if(i && errno != EEXIST){ // Allow add existent entry
        PyErr_SetString(IPFWError, "setsocket fail");
        close(s);
        return NULL;
    }
    close(s);
    Py_INCREF(Py_None);
    return Py_None;
}

http://bitbucket.org/hizel/py-ipfw/changeset/434dd0bc3cb7/



my script:
Code:
   #!/usr/local/bin/perl
    use Socket;
    use constant IPPROTO_RAW => 255;
    socket( SOCKET,AF_INET, SOCK_RAW, IPPROTO_RAW ) or die "Can't open raw socket: $!\n";
    setsockopt(SOCKET, IPPROTO_IP, IP_FW_TABLE_ADD, 1) or die "Can't send packet: $!\n";

Code:
./perl2.pl
Can't send packet: Protocol not available

How do? (ipfw_table_add(PyObject *self, PyObject *args) ??)

what is &ent, sizeof(ent)); ?
Code:
       i = setsockopt(s, IPPROTO_IP, IP_FW_TABLE_ADD, &ent, sizeof(ent));
 
Can't send packet: Protocol not available

For the 5th time on these forums, on BSD systems SOCK_RAW does not support TCP/IP.

what is &ent, sizeof(ent)); ?

&ent is pointer to the buffer where option values can be stored, sizeof(ent) is size of the buffer.
 
expl said:
on BSD systems SOCK_RAW does not support TCP/IP.
???
ipfw.c
Code:
   s=socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
? And what is this?

how to make that work by adding in ipfw table ipfw_table_add(PyObject *self, PyObject *args) on perl??
 
ProFTP said:
???
ipfw.c
Code:
   s=socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
? And what is this?

how to make that work by adding in ipfw table ipfw_table_add(PyObject *self, PyObject *args) on perl??

"Protocol not available" that means that raw socket does not support TCP/IP.
 
ok


how to make that work by adding in ipfw table ipfw_table_add(PyObject *self, PyObject *args) on perl?
 
Back
Top