Penguin
Annotated edit history of socket(2) version 5, including all changes. View license author blame.
Rev Author # Line
1 perry 1 !!NAME
5 PerryLorier 2 socket - create an endpoint for communication
1 perry 3
4 !!SYNOPSIS
5 PerryLorier 5 __#include <sys/types.h>__
6 __#include <sys/socket.h>__
1 perry 7
5 PerryLorier 8 __int socket(int__ ''domain''__, int__ ''type''__, int__ ''protocol''__);__
1 perry 9
10 !!DESCRIPTION
5 PerryLorier 11 socket(2) creates an endpoint for communication and returns a descriptor.
1 perry 12
5 PerryLorier 13 The ''domain'' parameter specifies a communication domain; this selects the protocol family which will be used for communication. These families are defined in
14 __<sys/socket.h>__. The currently understood formats include:
15 |__Name__|__Purpose__|Man page
16 |PF_UNIX,PF_LOCAL|Local communication|unix(7)
17 |PF_INET|IPv4 Internet protocols|ip(7)
18 |PF_INET6|IPv6 Internet protocols|
19 |PF_IPX|IPX - Novell protocols|
20 |PF_NETLINK|Kernel user interface device|netlink(7)
21 |PF_X25|ITU&#8208;T X.25 / ISO&#8208;8208 protocol|x25(7)
22 |PF_AX25|Amateur radio AX.25 protocol|
23 |PF_ATMPVC|Access to raw ATM PVCs|
24 |PF_APPLETALK|Appletalk|ddp(7)
25 |PF_PACKET|Low level packet interface|packet(7)
1 perry 26
27 The socket has the indicated ''type'', which specifies the communication semantics. Currently defined types are:
5 PerryLorier 28 ;__SOCK_STREAM__: Provides sequenced, reliable, two-way, connection-based byte streams. An out-of-band data transmission mechanism may be supported.
29 ;__SOCK_DGRAM__: Supports datagrams (connectionless, unreliable messages of a fixed maximum length).
30 ;__SOCK_SEQPACKET__: Provides a sequenced, reliable, two-way connection-based data transmission path for datagrams of fixed maximum length; a consumer is required to read an entire packet with each read system call.
31 ;__SOCK_RAW__: Provides raw network protocol access.
32 ;__SOCK_RDM__: Provides a reliable datagram layer that does not guarantee ordering.
33 ;__SOCK_PACKET__: Obsolete and should not be used in new programs; see packet(7).
1 perry 34
5 PerryLorier 35 Some socket types may not be implemented by all protocol families; for example, __SOCK_SEQPACKET__ is not implemented for __AF_INET__.
1 perry 36
5 PerryLorier 37 The ''protocol'' specifies a particular protocol to be used with the socket. Normally only a single protocol exists to support a particular socket type within a given protocol family. However, it is possible that many protocols may exist, in which case a particular protocol must be specified in this manner. The protocol number to use is specific to the ``communication domain'' in which communication is to take place; see protocols(5). See getprotoent(3) on how to map protocol name strings to
1 perry 38 protocol numbers.
39
5 PerryLorier 40 Sockets of type __SOCK_STREAM__ are full-duplex byte streams, similar to pipes. They do not preserve record boundaries. A stream socket must be in a ''connected''
41 state before any data may be sent or received on it. A connection to another socket is created with a connect(2) call. Once connected, data may be transferred using read(2) and write(2) calls or some variant of the send(2) and recv(2) calls. When a session has been completed a close(2) may be performed. Out-of-band data may also be transmitted as described in send(2) and received as described in recv(2).
1 perry 42
5 PerryLorier 43 The communications protocols which implement a __SOCK_STREAM__ ensure that data is not lost or duplicated. If a piece of data for which the peer protocol has buffer space cannot be successfully transmitted within a reasonable length of time, then the connection is considered to be dead. When __SO_KEEPALIVE__ is enabled on the socket the protocol checks in a protocol-specific manner if the other end is still alive. A [SIGPIPE] signal is raised if a process sends or receives on a broken stream;
44 this causes naive processes, which do not handle the signal, to exit. __SOCK_SEQPACKET__ sockets employ the same system calls as __SOCK_STREAM__ sockets. The only
45 difference is that read(2) calls will return only the amount of data requested, and any remaining in the arriving packet will be discarded. Also all message boundaries in
1 perry 46 incoming datagrams are preserved.
47
5 PerryLorier 48 __SOCK_DGRAM__ and __SOCK_RAW__ sockets allow sending of datagrams to correspondents named in send(2) calls. Datagrams are generally received with recvfrom(2), which returns the next datagram with its return address.
1 perry 49
5 PerryLorier 50 __SOCK_PACKET__ is an obsolete socket type to receive raw packets directly from the device driver. Use packet(7) instead.
1 perry 51
5 PerryLorier 52 An fcntl(2) call with the the __F_SETOWN__ argument can be used to specify a process group to receive a [SIGURG] signal when the out-of-band data arrives or [SIGPIPE] signal when a __SOCK_STREAM__ connection breaks unexpectedly. It may also be used to set the process or process group that receives the I/O and asynchronous notification of I/O events via [SIGIO]. Using __F_SETOWN__ is equivalent to an ioctl(2) call with the SIOSETOWN argument.
1 perry 53
5 PerryLorier 54 When the network signals an error condition to the protocol module (e.g. using a ICMP message for IP) the pending error flag is set for the socket. The next operation on this socket will return the error code of the pending error. For some protocols it is possible to enable a per-socket error queue to retrieve detailed information about the error; see __IP_RECVERR__ in ip(7).
1 perry 55
5 PerryLorier 56 The operation of sockets is controlled by socket level ''options''. These options are defined in __<sys/socket.h>__. Setsockopt(2) and getsockopt(2) are used to set and get options, respectively.
1 perry 57
58 !!RETURN VALUE
5 PerryLorier 59 -1 is returned if an error occurs; otherwise the return value is a descriptor referencing the socket.
1 perry 60
61 !!ERRORS
5 PerryLorier 62 ;[EPROTONOSUPPORT]: The protocol type or the specified protocol is not supported within this domain.
63 ;[ENFILE]: Not enough kernel memory to allocate a new socket structure.
64 ;[EMFILE]: Process file table overflow.
65 ;[EACCES]: Permission to create a socket of the specified type and/or protocol is denied.
66 ;[ENOBUFS] or [ENOMEM]: Insufficient memory is available. The socket cannot be created until sufficient resources are freed.
67 ;[EINVAL]: Unknown protocol, or protocol family not available.
1 perry 68
5 PerryLorier 69 Other errors may be generated by the underlying protocol modules.
1 perry 70
71 !!CONFORMING TO
5 PerryLorier 72 4.4BSD (the __socket__ function call appeared in 4.2BSD). Generally portable to/from non-BSD systems supporting clones of the BSD socket layer (including System V variants).
1 perry 73
74 !!NOTE
5 PerryLorier 75 The manifest constants used under BSD 4.* for protocol families are PF_UNIX, PF_INET, etc., while AF_UNIX etc. are used for address families. However, already the BSD man page promises:
1 perry 76
77 !!BUGS
5 PerryLorier 78 __SOCK_UUCP__ is not implemented yet.
1 perry 79
80 !!SEE ALSO
5 PerryLorier 81 accept(2), bind(2), connect(2), getprotoent(3), getsockname(2), getsockopt(2), ioctl(2), listen(2), read(2), recv(2), select(2), send(2), shutdown(2), socketpair(2), write(2)
1 perry 82
5 PerryLorier 83 ``An Introductory 4.3 BSD Interprocess Communication Tutorial'' is reprinted in ''UNIX Programmer's Supplementary Documents Volume 1.''
1 perry 84
5 PerryLorier 85 ``BSD Interprocess Communication Tutorial'' is reprinted in ''UNIX Programmer's Supplementary Documents Volume 1.''
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.

PHP Warning

lib/blame.php:177: Warning: Invalid argument supplied for foreach() (...repeated 9 times)