By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,766 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,766 IT Pros & Developers. It's quick & easy.

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

P: n/a

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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
> 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.