Passing argument to setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, intr)
Richard Taylor
rjt-usenet at thegrindstone.me.uk
Wed Apr 21 09:35:58 EDT 2004
Jeff Epler wrote:
> 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
You are right. I did not realise that you could append a null in that way.
Thanks.
Richard
More information about the Python-list
mailing list