0

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.

Alistair
  • 23
  • 1
  • 4

2 Answers2

1

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 )?

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
0

You are checing if sendto(...) is equal to bytesSent instead of probably bytesSent=sendto