UDP sendto error

I send data from a Net+50 (server) to a PC (client) using an UDP socket. The ethernet packets sent by the Net+50 contain destination MAC address 0xffffffffffff instead of the correct MAC of the PC. The PC has sent a packet to the before, so the Net+50 should know the IP and MAC address already. I guess it’s not my business to mess around with MAC addresses, that’s the job of the IP stack, isn’t it? Did I miss something? What I do is: s=socket(AF_INET,SOCK_DGRAM,0); int i=1; setsockopt(s,SOL_SOCKET,SO_BIO,(char*)&i,sizeof(int)); bind(s,&myAddress,sizeof(myAddress)); recvfrom(s,buff,length,0,&clientAddr,&addrSize); sendto(s,buff,length,0,&clientAddr,sizeof(clientAddr)); Regards -Stefan

It works if I set the IP address to zero in the address struct used in bind(). myAddress.sin_family = AF_INET; myAddress.sin_addr.s_addr = htonl(0); myAddress.sin_port = htons(UDP_PORT); bind(s,&myAddress,sizeof(myAddress)); I thought that bind() was used to assign an IP-address and port number to my socket… Does the socket with s_addr=0 accept any packet on the network??? Or does the MAC layer already filter packets that are not for me? Who tells the MAC layer (and ARP routines) the IP address(es) of the device?

For me is a bug in arp. I built an UDP server that receives an UDP packet and send it back to the sender. All packets sent by the server were addressed to mac FF:FF:FF:FF:FF:FF ! This is strange. If you received a packet from the pair IP_A/MAC_A, this pair should be kept in arp table to avoiding a new arp resolution. However, when the server send the reply, the destination mac is wrong. But, as reported by uniton, the problem is even worst since sendto seems not to work.

StefanCan you attach a network trace of the exchange? Ether-real or Etherpeek? Yes it’s the job of the stack to collect the MAC address, however, the stack will do only as told. Note that the exchange starts with a recvfrom, and that’s the packet of interest. In fact, if you can’t get a network trace, the contents of the clientAddr structure will do. Paul

If you check the documentation, bind with and address set to zero (same as using INADDR_ANY) will make it possible to receive a packet from any IP address with your port.

I think that you rather bind to a local network adapter. Hence it makes sense to use your IP address in the bind() call. When I first used NetOS6 (I skipped version 5) after using version 4 I noticed that you cannot receive broadcasts if you bind() to your local IP address, you have to bind to 0 (which means any local adapter and is by chance the same as INADDR_ANY, the “wildcard Internet address”).

An additional information: for multicast the sendto works properly. I suppose this is due to the special mac generation for multicast. There is no arp involved in this case. Again, I think is a arp flaw.