Passing argument to setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, intr)

Jeff Epler jepler at unpythonic.net
Wed Apr 21 08:33:21 EDT 2004


On Wed, Apr 21, 2004 at 12:22:41PM +0000, Richard Taylor wrote:
> The answer is:
> 
> s.setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,struct.pack("%ds" %
> (len("eth0")+1,), "eth0"))
> Richard Taylor wrote:

Maybe this is simpler:
    #dev = "eth0"
    s.setsockopt(..., dev + '\0')
I think it has the same effect as your code, but it is a little clearer
to me that the setsockopt call needs a zero-terminated C string as its
argument.

Jeff




More information about the Python-list mailing list