LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-21-2012, 10:57 PM   #1
jayadhanesh
Member
 
Registered: Feb 2009
Location: Bangalore
Posts: 61

Rep: Reputation: 15
RAW socket bind error


Hi,

I have a raw socket created socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)).

I trying to bind it to eth3 in the host with the following function:
int32_t BindRawSocket(int32_t sd, char *intf)
{
int32_t rc = 0;
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, "eth3", IFNAMSIZ);
printf("Bind %u to interface: %s\n", sd, intf);

rc = setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr));
printf("Bind rc %d \n", rc);
perror("bind: ");
if (rc != 0) {
printf("setsockopt failed in bind socket");
rc = -1;
}

return rc;
}
The bind did not return any error, but the raw socket is not bound to eth3. It is receiving packets received on another interface. What could be the problem.

Thanks,
Dhanesh.
 
Old 11-22-2012, 02:12 AM   #2
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
See the note regarding SO_BINDTODEVICE on this page

SO_BINDTODEVICE does not work with raw sockets

PS
There is a decidated programming section where programming questions are better suited. You can report your opening post and ask a moderator to move this thread there.
And you obviously will post your future programming questions there

Last edited by Wim Sturkenboom; 11-22-2012 at 02:17 AM. Reason: Added PS
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Raw SCTP socket cannot bind with port? JohnJLewis Linux - Networking 1 07-26-2010 02:14 PM
Raw socket and bind question, how to implement correctly. coolsti Linux - Networking 1 06-28-2009 11:49 PM
Raw socket creation error (IPPROTO_IP not supported) linfreak Programming 1 06-17-2004 12:37 PM
Raw socket creation error (IPPROTO_IP not supported) linfreak Linux - Networking 1 06-17-2004 10:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration