Thread: binding to

  1. #1
    Registered User
    Join Date
    Jun 2010

    binding to

    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 to the broadcast address
    the issue is that when I bind to 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 it's always 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 */
    	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)
    	if(setsockopt(sockfd,SOL_SOCKET,SO_BROADCAST,(char *) &flags, sizeof(flags)) < 0)

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    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 is to ifconfig an interface to that address -- even then, I think the kernel won't like it very much.
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Late or early binding?
    By Sharke in forum C++ Programming
    Replies: 4
    Last Post: 08-17-2009, 12:28 PM
  2. inet_aton()... Noob needs help with sockets :|
    By Maz in forum C++ Programming
    Replies: 3
    Last Post: 11-22-2005, 04:33 PM
  3. dynamic/static binding
    By faze in forum C++ Programming
    Replies: 7
    Last Post: 07-10-2005, 12:26 PM
  4. dynamic binding
    By freethenet in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-26-2004, 03:31 PM
  5. Static Binding & Dynamic Binding :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 12-31-2001, 08:51 PM