Page 1 of 1

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

Posted: Sat Aug 05, 2017 3:32 am
by roctwo
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.

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

Posted: Sat Aug 05, 2017 4:41 am
by kolban
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.

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

Posted: Sat Aug 05, 2017 5:47 am
by roctwo
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.