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

NAME

6       socket - create an endpoint for communication
7

SYNOPSIS

9       #include <sys/socket.h>
10
11       int socket(int domain, int type, int protocol);
12
13

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

109       None.
110

APPLICATION USAGE

112       The documentation for specific address families specifies which  proto‐
113       cols  each address family supports. The documentation for specific pro‐
114       tocols specifies which socket types each protocol supports.
115
116       The application can determine whether an address family is supported by
117       trying to create a socket with domain set to the protocol in question.
118

RATIONALE

120       None.
121

FUTURE DIRECTIONS

123       None.
124

SEE ALSO

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