socket详解

Syntax
  #include <sys/types.h>
  #include <sys/socket.h>

  int socket(int address_family,
             int type,
             int protocol)

  Service Program Name: QSOSRV1

  Default Public Authority: *USE

  Threadsafe: Yes

The socket() function is used to create an end point for communications. The end point is represented by the socket descriptor returned by the socket() function.


Parameters

address_family
(Input) The address family to be used with the socket. Supported values are:
AF_INET For interprocess communications between processes on the same system or different systems in the Internet domain using the Internet Protocol (IPv4).
AF_INET6 For interprocess communications between processes on the same system or different systems in the Internet domain using the Internet Protocol (IPv6 or IPv4).
AF_NS For interprocess communications between processes on the same system or different systems in the domain defined by the Novell or Xerox protocol definitions.

Note: The AF_NS address family is no longer supported as of V5R2.

AF_UNIX For interprocess communications between processes on the same system in the UNIX domain.
AF_UNIX_CCSID For interprocess communications between processes on the same system in the UNIX domain using the Qlg_Path_Name_T structure.
AF_TELEPHONY For interprocess communications between processes on the same system in the telephony domain.

Note: The AF_TELEPHONY address family is no longer supported as of V5R3.

type
(Input) The type of communications desired. Supported values are:

SOCK_DGRAM Indicates a datagram socket is desired.
SOCK_SEQPACKET Indicates a full-duplex sequenced packet socket is desired. Each input and output operation consists of exactly one record.
SOCK_STREAM Indicates a full-duplex stream socket is desired.
SOCK_RAW Indicates communication is directly to the network protocols. A process must have the appropriate privilege*ALLOBJ to use this type of socket. Used by users who want to access the lower-level protocols directly.


protocol
(Input) The protocol to be used on the socket. Supported values are:

0 Indicates that the default protocol for the type selected is to be used. For example, IPPROTO_TCP is chosen for the protocol if the type was set to SOCK_STREAM and the address family is AF_INET.
IPPROTO_IP Equivalent to specifying the value zero (0).
IPPROTO_TCP Indicates that the TCP protocol is to be used.
IPPROTO_UDP Indicates that the UDP protocol is to be used.
IPPROTO_RAW Indicates that communications is to the IP layer.
IPPROTO_ICMP Indicates that the Internet Control Message Protocol (ICMP) is to be used.
IPPROTO_ICMPV6 Indicates that the Internet Control Message Protocol (ICMPv6) is to be used.
TELPROTO_TEL Equivalent to specifying the value zero (0).


Note: When the type is SOCK_RAW, the protocol can be set to some predefined protocol number from 0-255. See Usage Notes for further details.


Authorities

When the SOCKET being created is of type SOCK_RAW, the thread must have *ALLOBJ special authority. When the thread does not have this authority, the EACCES is returned for errno.


Return Value

socket() returns an integer. Possible values are:

  • -1 (unsuccessful)
  • n (successful), where n is a socket descriptor.


转于:http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=%2Fapis%2Fsocket.htm

你可能感兴趣的:(socket,System,domain,internet,Descriptor,protocols)