LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   RAW socket bind error (https://www.linuxquestions.org/questions/linux-software-2/raw-socket-bind-error-4175438219/)

jayadhanesh 11-21-2012 10:57 PM

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.

Wim Sturkenboom 11-22-2012 02:12 AM

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 :)


All times are GMT -5. The time now is 11:56 AM.