Alistair
Alistair

Reputation: 23

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.

Upvotes: 0

Views: 1037

Answers (2)

user1151738
user1151738

Reputation:

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

Upvotes: 0

Nikolai Fetissov
Nikolai Fetissov

Reputation: 84239

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

Upvotes: 1

Related Questions