gtpc1m4g | Transmission Control Protocol/Internet Protocol |
The socket function creates an endpoint for communication and
returns a socket descriptor representing the endpoint. Different types
of sockets provide different communication services.
Format
#include <socket.h>
int socket(int domain,
int type,
int protocol);
- domain
- The address domain requested. Use the value
AF_INET. The domain parameter specifies a domain
in which communication is to take place.
- type
- Specifies the type of socket created. The type is analogous with
the semantics of the communication requested. Use one of the following
values:
- SOCK_STREAM
- Provides sequenced, duplex byte streams that are reliable and
connection-oriented. They support a mechanism for out-of-band
data.
- SOCK_DGRAM
- Provides datagrams, which are connectionless messages of a fixed maximum
length whose reliability is not guaranteed. Datagrams can be corrupted,
received out of order, lost, or delivered multiple times.
- SOCK_RAW
- Provides the interface to internal protocols (such as IP).
- protocol
- The protocol requested. Use one of the following values:
- 0
- Default protocol based on the domain and
type.
- IPPROTO_IP
- Specifies the Internet Protocol.
- IPPROTO_ICMP
- Specifies the Internet Control Message protocol.
- IPPROTO_TCP
- Specifies the Transmission Control Protocol (TCP). This is the
default for a type of SOCK_STREAM.
- IPPROTO_UDP
- Specifies the User Datagram Protocol (UDP). This is the default for
a type of SOCK_DGRAM.
- IPPROTO_RAW
- Specifies a raw IP packet.
The protocol parameter specifies a particular protocol to be
used with the socket. In most cases, a single protocol exists to
support a particular type of socket in a particular addressing family (not
true with raw sockets). If the protocol field is set to 0, the system
selects the default protocol number for the domain and socket type
requested. Currently, protocol defaults are TCP for stream sockets and
UDP for datagram sockets. There is no default for raw sockets.
Normal Return
A nonnegative socket descriptor indicates success.
Error Return
A return code equal to -1 indicates an error. You can get the
specific error code by calling sock_errno. See Appendix C, Socket Error Return Codes for more information about socket errors.
- Note:
- Unless otherwise stated in the description, the following error codes can be
returned for either TCP/IP offload support or TCP/IP native stack
support.
- Value
- Description
- SOCNOBUFS
- There is not enough space to create a new socket because the socket block
table is full. This error code is returned only for TCP/IP native stack
support.
- SOCPROTONOSUPPORT
- The protocol is not supported in this domain or this protocol is not
supported for this socket type.
- SOCPROTOTYPE
- The protocol is the wrong type for the socket. This error code is
returned only for TCP/IP offload support.
- SOCAFNOSUPPORT
- The address family is not supported.
- SOCSOCKTNOSUPPORT
- The socket type is not supported.
- E1052STATE
- The socket was not created because the system was in or cycling down to
1052 state.
- EINACT
- All offload devices associated with the socket descriptor have been
disconnected. The socket is closed. This error code is returned
only for TCP/IP offload support.
Programming Considerations
When both TCP/IP native stack support and TCP/IP offload support are
defined in the TPF system, the select TCP/IP support (USOK) user exit is
called to select the appropriate TCP/IP support to use when a
socket function is called. See TPF
System Installation Support Reference for information about the select
TCP/IP support user exit.
Examples
In the following example, a stream socket is created.
#include <socket.h>
·
·
·
int server_sock;
·
·
·
server_sock = socket(AF_INET, SOCK_STREAM, 0);
Related Information