Scout Module API

Sniffer Sockets

Sniffer Sockets

A slice can bind a raw "sniffer" socket to a port owned by the slice to snoop IP datagrams sent and received on that port. Sniffer sockets are read-only and do not interfere with traffic. Creating a sniffer socket on a free port makes the slice the owner of that port, meaning no other slice can bind a socket to that port. A current limitation is that only one sniffer socket can be created per port.

To create a sniffer socket, it is necessary to call setsockopt on the socket before binding it to the port. Example:


    #include < planetlab.h >

    int tmp, sock;
    struct sockaddr_in sin;
 
    sock = socket(PF_INET, SOCK_RAW, IPPROTO_TCP);

    tmp = 1;
    setsockopt(sock, 0, SO_RAW_SNIFF, & tmp, sizeof(tmp));

    sin.sin_port = htons(1234);

    bind(sock, (struct sockaddr *)& sin, sizeof(sin));