views:

100

answers:

1

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.

+1  A: 

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 N Fetissov
Ah yes of course I cant believe I didn't see that. I've been frustrated by this for nearly an hours v.v
Alistair
Blame =, == and lines that are too long :)
schnaader