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



## ProFTP (Apr 9, 2010)

```
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:

```
#!/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";
```


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

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

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

```
i = setsockopt(s, IPPROTO_IP, IP_FW_TABLE_ADD, &ent, sizeof(ent));
```


----------



## expl (Apr 9, 2010)

> 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.


----------



## ProFTP (Apr 10, 2010)

expl said:
			
		

> on BSD systems SOCK_RAW does not support TCP/IP.


???
ipfw.c

```
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??


----------



## expl (Apr 10, 2010)

ProFTP said:
			
		

> ???
> ipfw.c
> 
> ```
> ...



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


----------



## ProFTP (Apr 10, 2010)

ok


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


----------

