binding to 0.0.0.0
The goal is to send a UDP packet adhering to the bootp and DHCP more specifically.
now I need to send it from a src ip of 0.0.0.0 to the broadcast address 255.255.255.255
the issue is that when I bind to 0.0.0.0 it is interpreted as INADDR_ANY
so what is happening is any interfaces that are 'up' and have an IP address that IP address is used so instead of sending the packet from 0.0.0.0 it's always 192.168.1.8 or whatever the IP address on the other interface is.
bcast.sin_family = AF_INET;
bcast.sin_port = htons(67);
bcast.sin_addr.s_addr = INADDR_BROADCAST;
src.sin_family = AF_INET;
src.sin_port = htons(68);
//src was zero'd earlier in execution so src.sin_addr.s_addr = 0
/* set IP to INADDR_ANY */
Bind(sockfd,(SA *) &src,sizeof(src));
if(setsockopt(sockfd,SOL_SOCKET,SO_BINDTODEVICE,(void *) &ifr,sizeof(ifr)) < 0)
if(setsockopt(sockfd,SOL_SOCKET,SO_BROADCAST,(char *) &flags, sizeof(flags)) < 0)
I think other implementations of this protocol use raw sockets, for this, among other, reasons.
The only way I'm aware of to actually bind to 0.0.0.0 is to ifconfig an interface to that address -- even then, I think the kernel won't like it very much.