1socket(3XNET)    X/Open Networking Services Library Functions    socket(3XNET)
2
3
4

NAME

6       socket - create an endpoint for communication
7

SYNOPSIS

9       cc [ flag ... ] file ... -lxnet [ library ... ]
10       #include <sys/socket.h>
11
12       int socket(int domain, int type, int protocol);
13
14

DESCRIPTION

16       The  socket()  function  creates  an unbound socket in a communications
17       domain, and returns a file descriptor that can be used in  later  func‐
18       tion calls that operate on sockets.
19
20
21       The <sys/socket.h> header defines at least the following values for the
22       domain argument:
23
24       AF_UNIX     File system pathnames.
25
26
27       AF_INET     Internet Protocol version 4 (IPv4) address.
28
29
30       AF_INET6    Internet Protocol version 6 (IPv6) address.
31
32
33
34       The type argument specifies  the  socket  type,  which  determines  the
35       semantics of communication over the socket.  The socket types supported
36       by the system  are  implementation-dependent.   Possible  socket  types
37       include:
38
39       SOCK_STREAM       Provides  sequenced, reliable, bidirectional, connec‐
40                         tion-mode byte streams, and may provide  a  transmis‐
41                         sion mechanism for out-of-band data.
42
43
44       SOCK_DGRAM        Provides  datagrams,  which  are connectionless-mode,
45                         unreliable messages of fixed maximum length.
46
47
48       SOCK_SEQPACKET    Provides sequenced, reliable, bidirectional,  connec‐
49                         tion-mode  transmission  path  for records.  A record
50                         can be sent using one or more output  operations  and
51                         received  using  one  or more input operations, but a
52                         single operation never transfers part  of  more  than
53                         one  record.   Record  boundaries  are visible to the
54                         receiver via the MSG_EOR flag.
55
56
57
58       If the protocol argument is non-zero, it must specify a  protocol  that
59       is  supported  by  the  address family.  The protocols supported by the
60       system are implementation-dependent.
61
62
63       The process may need to have appropriate privileges to use the socket()
64       function or to create some sockets.
65

PARAMETERS

67       The function takes the following arguments:
68
69       domain      Specifies the communications domain in which a socket is to
70                   be created.
71
72
73       type        Specifies the type of socket to be created.
74
75
76       protocol    Specifies a particular protocol to be used with the socket.
77                   Specifying  a  protocol  of  0  causes  socket()  to use an
78                   unspecified default protocol appropriate for the  requested
79                   socket type.
80
81
82
83       The domain argument specifies the address family used in the communica‐
84       tions domain.  The address families supported by the system are  imple‐
85       mentation-dependent.
86

USAGE

88       The documentation for specific address families specify which protocols
89       each address family supports.  The documentation for specific protocols
90       specify which socket types each protocol supports.
91
92
93       The application can determine if an address family is supported by try‐
94       ing to create a socket with domain set to the protocol in question.
95

RETURN VALUES

97       Upon successful completion, socket() returns a nonnegative integer, the
98       socket  file descriptor.  Otherwise a value of -1 is returned and errno
99       is set to indicate the error.
100

ERRORS

102       The socket() function will fail if:
103
104       EAFNOSUPPORT       The implementation does not  support  the  specified
105                          address family.
106
107
108       EMFILE             No  more  file  descriptors  are  available for this
109                          process.
110
111
112       ENFILE             No more file descriptors are available for the  sys‐
113                          tem.
114
115
116       EPROTONOSUPPORT    The protocol is not supported by the address family,
117                          or the protocol is not supported by the  implementa‐
118                          tion.
119
120
121       EPROTOTYPE         The socket type is not supported by the protocol.
122
123
124
125       The socket() function may fail if:
126
127       EACCES     The process does not have appropriate privileges.
128
129
130       ENOBUFS    Insufficient  resources were available in the system to per‐
131                  form the operation.
132
133
134       ENOMEM     Insufficient memory was available to fulfill the request.
135
136
137       ENOSR      There were insufficient STREAMS resources available for  the
138                  operation to complete.
139
140

ATTRIBUTES

142       See attributes(5) for descriptions of the following attributes:
143
144
145
146
147       ┌─────────────────────────────┬─────────────────────────────┐
148       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
149       ├─────────────────────────────┼─────────────────────────────┤
150       │Interface Stability          │Standard                     │
151       ├─────────────────────────────┼─────────────────────────────┤
152       │MT-Level                     │MT-Safe                      │
153       └─────────────────────────────┴─────────────────────────────┘
154

SEE ALSO

156       accept(3XNET),  bind(3XNET),  connect(3XNET),  getsockname(3XNET), get‐
157       sockopt(3XNET),    listen(3XNET),     recv(3XNET),     recvfrom(3XNET),
158       recvmsg(3XNET),  send(3XNET),  sendmsg(3XNET), setsockopt(3XNET), shut‐
159       down(3XNET), socketpair(3XNET), attributes(5), standards(5)
160
161
162
163SunOS 5.11                        10 Jun 2002                    socket(3XNET)
Impressum