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.
Code:
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
memcpy(&ifr.ifr_addr,&src,sizeof(src));
snprintf(ifr.ifr_name,sizeof(ifr.ifr_name),"%s",argv[1]);
printf("%s\n",ifr.ifr_name);
/* set IP to INADDR_ANY */
if(ioctl(sockfd,SIOCSIFADDR,&ifr)<0) {
err_quit("ioctl error\n");
}
Bind(sockfd,(SA *) &src,sizeof(src));
if(setsockopt(sockfd,SOL_SOCKET,SO_BINDTODEVICE,(void *) &ifr,sizeof(ifr)) < 0)
err_quit("setsockopt\n");
if(setsockopt(sockfd,SOL_SOCKET,SO_BROADCAST,(char *) &flags, sizeof(flags)) < 0)
err_quit("setsockopt\n");