UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2013-01-15 04:18 PM

pankaj_b9
Guest

SO_BINDTODEVICE only works for root user

Hi, setsockopt SO_BINDTODEVICE option only works for root user. Is there any other better option for this.

#2 2013-01-15 09:18 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: SO_BINDTODEVICE only works for root user

Well, the traditional method is just to use regular old bind() to the specific IP of the interface you want to be bound to...  Is there some reason that won't work for whatever your needs are?

Offline

#3 2013-01-16 08:41 AM

pankajdev
Member
Registered: 2009-07-15
Posts: 14

Re: SO_BINDTODEVICE only works for root user

Thanks for reply..
I have used bind for binding to specific IP address for client side. It runs fine when i run client and server on same machine but when i run on different machine  connect system call block. When i look into netstat on client side
I get following output.
tcp        0      1 169.49.169.84:48634     169.35.74.26:5555       SYN_SENT    5535/SocketClient

Is any thing is pending from my side...
I have tried to ping on interface card id address through which i want to connect from server machine but it not giving output

Last edited by pankajdev (2013-01-16 08:51 AM)

Offline

#4 2013-01-16 02:06 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: SO_BINDTODEVICE only works for root user

Are you sure you have a correct route to reach the other machine via that interface?  Also, are there maybe firewalls either on the machines or between them, which could be blocking the connection from completing?

The SYN_SENT state means your machine is in the initial stages of the 3-way handshake to try to open a connection: it has sent the initial SYN, but received no response...  This could mean there's no way to reach the destination via that route, or it could mean a firewall is just dropping your SYNs on the floor and ignoring you...

But, why do you need to bind to a specific interface in the first place?  Why not remain completely unbound on the client side (or at least bind INADDR_ANY, if you really need to bind a specific port), and let your OS figure out which interface it should use to reach the destination?

Offline

Board footer

Powered by FluxBB