UDP Sockets

Hi, I’m trying to set up a UDP socket that waits until a certain stream of data has been sent and then replies to the host.

So far I have:

  1. Created the socket using socket()
  2. Set options using setsockopt() - set to blocking IO
  3. Bound the socket to options using bind()

All three of these returned successfully but when I try to receive from the socket using recvfrom() I get an error.

My code for recvfrom:

retval = recvfrom(sockFD, dataBuffer, BUFFER_SIZE, 0, (struct sockaddr *) &hostSockAddr, &hostSockAddrSize);

I get error 22 - /* Invalid argument */.

Anyone know what I’m doing wrong?

I’ve attached part of my code.


Just before calling recvfrom add the following:
hostSockAddrSize = sizeof(struct sockaddr);

hostSockAddrSize does double duty. It tells recvfrom the size of the address structure and will receive the size that recvfrom set.