Sendto fail.errno is -1.What "errno==-1" indicates?Every macro of errno is positive number.

roctwo
Posts: 95
Joined: Mon Nov 28, 2016 3:12 am

Sendto fail.errno is -1.What "errno==-1" indicates?Every macro of errno is positive number.

Postby roctwo » Sat Aug 05, 2017 3:32 am

Data transmission through wifi,using UDP,call sendto API.errno is -1.What "errno==-1" indicates?From errno.h,every macro of errno is positive number.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Sendto fail.errno is -1.What "errno==-1" indicates?Every macro of errno is positive number.

Postby kolban » Sat Aug 05, 2017 4:41 am

Have a look at the following:

https://linux.die.net/man/2/sendto

If we look down to return values it states:
On success, these calls return the number of characters sent. On error, -1 is returned, and errno is set appropriately.
This means that sendto() returns the number of characters sent and not "errno". The "errno" is a C global variable. Commonly the return code from a C function returns a success/error indication and the underlying error can be found as the current value of errno global.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

roctwo
Posts: 95
Joined: Mon Nov 28, 2016 3:12 am

Re: Sendto fail.errno is -1.What "errno==-1" indicates?Every macro of errno is positive number.

Postby roctwo » Sat Aug 05, 2017 5:47 am

kolban wrote:Have a look at the following:

https://linux.die.net/man/2/sendto

If we look down to return values it states:
On success, these calls return the number of characters sent. On error, -1 is returned, and errno is set appropriately.
This means that sendto() returns the number of characters sent and not "errno". The "errno" is a C global variable. Commonly the return code from a C function returns a success/error indication and the underlying error can be found as the current value of errno global.

Code: Select all

ret=sendto(sock,start,SEND_START_LEN,0,(struct sockaddr *)&toAddr,sizeof(toAddr))
if(ret<0)
{
	printf("errno is %d\n",errno);
}
else
{
	printf("send success\n");
}
I knows the return value of sendto indicate and errno indicates.What I said "errno==-1" is based on the return value of sendto is -1.So my question is:What "errno==-1" indicates based on sendto fails.
Sorry for my bad English,and my bad expression and the bad ability of expression.

Who is online

Users browsing this forum: gunar.kroeger and 26 guests