1SOCKET(3P)                 POSIX Programmer's Manual                SOCKET(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       socket - create an endpoint for communication
13

SYNOPSIS

15       #include <sys/socket.h>
16
17       int socket(int domain, int type, int protocol);
18
19

DESCRIPTION

21       The socket() function shall create an unbound socket  in  a  communica‐
22       tions  domain,  and  return a file descriptor that can be used in later
23       function calls that operate on sockets.
24
25       The socket() function takes the following arguments:
26
27       domain Specifies the communications domain in which a socket is  to  be
28              created.
29
30       type   Specifies the type of socket to be created.
31
32       protocol
33              Specifies  a  particular  protocol  to  be used with the socket.
34              Specifying a protocol of 0 causes socket() to use an unspecified
35              default protocol appropriate for the requested socket type.
36
37
38       The domain argument specifies the address family used in the communica‐
39       tions domain. The address families supported by the system  are  imple‐
40       mentation-defined.
41
42       Symbolic constants that can be used for the domain argument are defined
43       in the <sys/socket.h> header.
44
45       The type argument specifies  the  socket  type,  which  determines  the
46       semantics  of communication over the socket. The following socket types
47       are defined; implementations may specify additional socket types:
48
49       SOCK_STREAM
50              Provides  sequenced,  reliable,  bidirectional,  connection-mode
51              byte  streams, and may provide a transmission mechanism for out-
52              of-band data.
53
54       SOCK_DGRAM
55              Provides datagrams, which  are  connectionless-mode,  unreliable
56              messages of fixed maximum length.
57
58       SOCK_SEQPACKET
59              Provides  sequenced,  reliable,  bidirectional,  connection-mode
60              transmission paths for records. A record can be sent  using  one
61              or  more  output operations and received using one or more input
62              operations, but a single operation never transfers part of  more
63              than  one  record. Record boundaries are visible to the receiver
64              via the MSG_EOR flag.
65
66
67       If the protocol argument is non-zero, it shall specify a protocol  that
68       is  supported  by the address family. If the protocol argument is zero,
69       the default protocol for this address family and type  shall  be  used.
70       The protocols supported by the system are implementation-defined.
71
72       The process may need to have appropriate privileges to use the socket()
73       function or to create some sockets.
74

RETURN VALUE

76       Upon successful completion, socket() shall return a non-negative  inte‐
77       ger,  the  socket  file  descriptor.  Otherwise, a value of -1 shall be
78       returned and errno set to indicate the error.
79

ERRORS

81       The socket() function shall fail if:
82
83       EAFNOSUPPORT
84
85              The implementation does not support the specified  address  fam‐
86              ily.
87
88       EMFILE No more file descriptors are available for this process.
89
90       ENFILE No more file descriptors are available for the system.
91
92       EPROTONOSUPPORT
93
94              The protocol is not supported by the address family, or the pro‐
95              tocol is not supported by the implementation.
96
97       EPROTOTYPE
98              The socket type is not supported by the protocol.
99
100
101       The socket() function may fail if:
102
103       EACCES The process does not have appropriate privileges.
104
105       ENOBUFS
106              Insufficient resources were available in the system  to  perform
107              the operation.
108
109       ENOMEM Insufficient memory was available to fulfill the request.
110
111
112       The following sections are informative.
113

EXAMPLES

115       None.
116

APPLICATION USAGE

118       The  documentation for specific address families specifies which proto‐
119       cols each address family supports. The documentation for specific  pro‐
120       tocols specifies which socket types each protocol supports.
121
122       The application can determine whether an address family is supported by
123       trying to create a socket with domain set to the protocol in question.
124

RATIONALE

126       None.
127

FUTURE DIRECTIONS

129       None.
130

SEE ALSO

132       accept(), bind(),  connect(),  getsockname(),  getsockopt(),  listen(),
133       recv(),  recvfrom(),  recvmsg(), send(), sendmsg(), setsockopt(), shut‐
134       down(),    socketpair(),    the    Base    Definitions    volume     of
135       IEEE Std 1003.1-2001, <netinet/in.h>, <sys/socket.h>
136
138       Portions  of  this text are reprinted and reproduced in electronic form
139       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
140       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
141       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
142       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
143       event of any discrepancy between this version and the original IEEE and
144       The  Open Group Standard, the original IEEE and The Open Group Standard
145       is the referee document. The original Standard can be  obtained  online
146       at http://www.opengroup.org/unix/online.html .
147
148
149
150IEEE/The Open Group                  2003                           SOCKET(3P)
Impressum