Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

56. Sockets: Introduction > Creating a Socket: socket()

Creating a Socket: socket()

The socket() system call creates a new socket.

#include <sys/socket.h>

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

Note

Returns file descriptor on success, or -1 on error

The domain argument specifies the communication domain for the socket. The type argument specifies the socket type. This argument is usually specified as either SOCK_STREAM, to create a stream socket, or SOCK_DGRAM, to create a datagram socket.

The protocol argument is always specified as 0 for the socket types we describe in this book. Nonzero protocol values are used with some socket types that we don’t describe. For example, protocol is specified as IPPROTO_RAW for raw sockets (SOCK_RAW).


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint