socket()

头文件:

       #include <sys/types.h>          /* See NOTES */
       #include <sys/socket.h>

函数原型:

 int socket(int domain, int type, int protocol);

函数说明:

创建一个通信端点,并返回一个设备描述符。

参数说明:

domain:指定一个通信域;

    -可取的值:

       Name                Purpose                          Man page
       AF_UNIX, AF_LOCAL   Local communication              unix(7)
       AF_INET             IPv4 Internet protocols          ip(7)
       AF_INET6            IPv6 Internet protocols          ipv6(7)
       AF_IPX              IPX - Novell protocols
       AF_NETLINK          Kernel user interface device     netlink(7)
       AF_X25              ITU-T X.25 / ISO-8208 protocol   x25(7)
       AF_AX25             Amateur radio AX.25 protocol
       AF_ATMPVC           Access to raw ATM PVCs
       AF_APPLETALK        AppleTalk                        ddp(7)
       AF_PACKET           Low level packet interface       packet(7)
       AF_ALG              Interface to kernel crypto API

type:套接字的指定类型。

    -可取的值:

       SOCK_STREAM     Provides sequenced, reliable, two-way, connection-based
                       byte  streams.  An out-of-band data transmission mecha‐
                       nism may be supported.

       SOCK_DGRAM      Supports datagrams (connectionless, unreliable messages
                       of a fixed maximum length).

       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 input system call.

       SOCK_RAW        Provides raw network protocol access.

       SOCK_RDM        Provides a reliable datagram layer that does not  guar‐
                       antee ordering.

       SOCK_PACKET     Obsolete  and  should  not be used in new programs; see
                       packet(7).


protocol:指定特别的socket协议,通常为0.


猜你喜欢

转载自blog.csdn.net/wolf_tong/article/details/76646275