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.
|