473,406 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 12754
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sashan | last post by:
I'm writing a program using sockets. I'm binding to a port like this: PORT = 5000 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST,...
3
by: Thomas Hervé | last post by:
My problem is not really python specific but as I do my implementation in python I hope someone here can help me. I have two programs that talk through a socket. Here is the code : <server>...
2
by: Christian von Essen | last post by:
Hi, As I don't know if my problem is python, platform or non-specific, I try to post my question here, as you may have made similar experiences. I try to write a simple chatserver, using the...
6
by: Clarence Gardner | last post by:
I've got a problem that I don't see how to program around. A socket server that was running fine, today started getting an exception from the bind() call (errno 22, Invalid argument) and yet the...
4
by: mfaujour | last post by:
I HAVE THIS PYTHON PROGRAMM: $ cat socpb.py import BaseHTTPServer, SocketServer, os, socket, threading # the server initialisation server = SocketServer.TCPServer((socket.gethostname(),...
5
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a...
14
by: ahlongxp | last post by:
Hi, everyone, I'm implementing a simple client/server protocol. Now I've got a situation: client will send server command,header paires and optionally body. server checks headers and decides...
6
by: ahlongxp | last post by:
socket.makefile() may lose data when "connection reset by peer". and socket.recv() will never lose the data. change the "1" to "0" in the client code to see the difference. confirmed on both...
3
WhiteRider
by: WhiteRider | last post by:
I have some basic knowledge of socket programming in Python. Up to now all I have been able to do when establishing a socket is sending a string to a client, what I would like to know is what else...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.