469,643 Members | 1,280 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

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


Hi

Does anyone know the correct way to pass the 'device' argument to setsockopt
with the SO_BINDTODEVICE flag?

I have tried various methods:

setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,"e th0")
setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,in et_aton("eth0"))
setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,st ruct.pack("s","eth0"))
setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,st ruct.pack("p","eth0"))

None of these work. I just get a "socket.error: (19, 'No such device')".

I do have an "eth0" device :-)

Many thanks

Richard

Jul 18 '05 #1
4 12202
Richard Taylor wrote:

Hi

Does anyone know the correct way to pass the 'device' argument to
setsockopt with the SO_BINDTODEVICE flag?

I have tried various methods:

setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,"e th0")
setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,in et_aton("eth0"))
setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,st ruct.pack("s","eth0"))
setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,st ruct.pack("p","eth0"))

None of these work. I just get a "socket.error: (19, 'No such device')".

I do have an "eth0" device :-)

Many thanks

Richard


Solved it!

So for others that find this in the news archive...

The answer is:

s.setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE, struct.pack("%ds" %
(len("eth0")+1,), "eth0"))

Richard
Jul 18 '05 #2
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

Jul 18 '05 #3
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

Jul 18 '05 #4
> Does anyone know the correct way to pass the 'device' argument to
setsockopt with the SO_BINDTODEVICE flag?

I have tried various methods:

setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,"e th0")
setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,in et_aton("eth0"))
setsockopt(socket.SOL_SOCKET,IN.SO_BINDTODEVICE,st ruct.pack("s","eth0"))


I think you need
struct.pack("5s","eth0")
--
Дамјан (jabberID:da****@bagra.net.mk)

A: Because it reverses the logical flow of converstion.
Q: Why is top posting frowned upon?
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by sashan | last post: by
3 posts views Thread by Thomas Herv | last post: by
2 posts views Thread by Christian von Essen | last post: by
6 posts views Thread by Clarence Gardner | last post: by
4 posts views Thread by mfaujour | last post: by
6 posts views Thread by ahlongxp | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.