socket中的damain和type

socket创建插口时的系统调用函数:

       #include           /* See NOTES */
       #include 

       int socket(int domain, int type, int protocol);
第一个参数是指域,网络通信中常用的域如下:

       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)
第二个参数是socket类型, 有如下一些常用类型:

       SOCK_STREAM     Provides sequenced, reliable, two-way, connection-based byte streams.   An  out-
                       of-band data transmission mechanism 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 guarantee ordering.

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

第三个参数protocol,一般都是0, 除了一些特殊的通信协议

因为域和socket类型两个参数往往已经决定了协议类型了。

你可能感兴趣的:(socket)