Search code examples
csocketsudpwinsocksendto

C windows sendto()


I am trying to send over UDP using the following code, but i'm getting strange results.

    if((sendto(newSocket, sendBuf, totalLength, 0, (SOCKADDR *)&sendAddr, sizeof(sendAddr)) == bytesSent) < 0)
    {
    printf("Send error! - %d\n", WSAGetLastError());

    }

However say when the totalLength variable is set to 30 the sendto function actually returns 2292556, should it not be returning something at least around the 30 mark? I have checked the totalLength variable before using sendto and it will happily return a value i agree with, but then sendto returns a massive value. Total length is never bigger then the actual buffer size.

WSAGetLastError is just returning 0.

Thanks.


Solution

  • I think your problem is the == bytesSent) < 0) part of the conditional. Should'n this be something along the lines of if (( bytesSent = sendto( ... )) < 0 )?