Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 0 or 1 valid return values for socket() function call

Tags:

People also ask

What is the return value of socket?

RETURN VALUE Upon successful completion, socket() shall return a non-negative integer, the socket file descriptor. Otherwise, a value of -1 shall be returned and errno set to indicate the error.

Can a socket return 0?

socket() on Linux and macOS On unix-like platforms (Berkeley sockets), socket() returns an int . This return value will be 0 or positive if the call succeeded, and it will be negative if it failed.

What is socket Call return?

The socket( ) system call returns a file descriptor. In fact, a socket is similar to an opened file because it is possible to read and write data on it by means of the usual read( ) and write( ) system calls.

What are the parameters of socket ()?

socket() call parameters The AF_INET and AF_INET6 constant is defined in the socket. h header file. The type parameter specifies the type of socket created. These socket type constants are defined in the socket.


Could the socket function call in C return 0 or 1 as the value for the socket descriptor?

   int socket(int domain, int type, int protocol);

According to the man page I have:

RETURN VALUE
   -1 is returned if an error occurs; otherwise the  return  value  is  a
   descriptor referencing the socket.

It seems like it could, or at least the man page makes no mention of any reserved values. Is it written somewhere else that valid socket descriptors need to be 2 or greater?

I'm specifically running on a linux 2.4.22 kernel, but I'm curious to know for any unix based implementation of socket.