mercredi 1 mars 2017

Why am I getting "Invalid argument" from this sendto()?

So I'm passing an argument to my main which is an IP as char* name ipStr.

Then I'm initialising a variable to hold the length of it before calling sendto():

sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
char buffer[8];
socklen_t ipLen = sizeof(ipStr);

            res = sendto(sock, buffer, sizeof(buffer), 0,
                    (struct sockaddr*) &ipStr, ipLen);

Yet I'm still getting Invalid argument as a returned error.

I'm getting no compile errors with g++ so I'm not sure where the problem is.

EDIT

I noticed I hadn't deleted sizeof before ipLen, changed the above and still getting Invalid argument.

Aucun commentaire:

Enregistrer un commentaire