zoukankan      html  css  js  c++  java
  • 网络编程常见类型定义

    in.h

    /* Standard well-defined IP protocols.  */
    enum
      {
        IPPROTO_IP = 0,       /* Dummy protocol for TCP.  */
    #define IPPROTO_IP        IPPROTO_IP
        IPPROTO_HOPOPTS = 0,   /* IPv6 Hop-by-Hop options.  */
    #define IPPROTO_HOPOPTS        IPPROTO_HOPOPTS
        IPPROTO_ICMP = 1,       /* Internet Control Message Protocol.  */
    #define IPPROTO_ICMP        IPPROTO_ICMP
        IPPROTO_IGMP = 2,       /* Internet Group Management Protocol. */
    #define IPPROTO_IGMP        IPPROTO_IGMP
        IPPROTO_IPIP = 4,       /* IPIP tunnels (older KA9Q tunnels use 94).  */
    #define IPPROTO_IPIP        IPPROTO_IPIP
        IPPROTO_TCP = 6,       /* Transmission Control Protocol.  */
    #define IPPROTO_TCP        IPPROTO_TCP
        IPPROTO_EGP = 8,       /* Exterior Gateway Protocol.  */
    #define IPPROTO_EGP        IPPROTO_EGP
        IPPROTO_PUP = 12,       /* PUP protocol.  */
    #define IPPROTO_PUP        IPPROTO_PUP
        IPPROTO_UDP = 17,       /* User Datagram Protocol.  */
    #define IPPROTO_UDP        IPPROTO_UDP
        IPPROTO_IDP = 22,       /* XNS IDP protocol.  */
    #define IPPROTO_IDP        IPPROTO_IDP
        IPPROTO_TP = 29,       /* SO Transport Protocol Class 4.  */
    #define IPPROTO_TP        IPPROTO_TP
        IPPROTO_DCCP = 33,       /* Datagram Congestion Control Protocol.  */
    #define IPPROTO_DCCP        IPPROTO_DCCP
        IPPROTO_IPV6 = 41,     /* IPv6 header.  */
    #define IPPROTO_IPV6        IPPROTO_IPV6
        IPPROTO_ROUTING = 43,  /* IPv6 routing header.  */
    #define IPPROTO_ROUTING        IPPROTO_ROUTING
        IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header.  */
    #define IPPROTO_FRAGMENT    IPPROTO_FRAGMENT
        IPPROTO_RSVP = 46,       /* Reservation Protocol.  */
    #define IPPROTO_RSVP        IPPROTO_RSVP
        IPPROTO_GRE = 47,       /* General Routing Encapsulation.  */
    #define IPPROTO_GRE        IPPROTO_GRE
        IPPROTO_ESP = 50,      /* encapsulating security payload.  */
    #define IPPROTO_ESP        IPPROTO_ESP
        IPPROTO_AH = 51,       /* authentication header.  */
    #define IPPROTO_AH        IPPROTO_AH
        IPPROTO_ICMPV6 = 58,   /* ICMPv6.  */
    #define IPPROTO_ICMPV6        IPPROTO_ICMPV6
        IPPROTO_NONE = 59,     /* IPv6 no next header.  */
    #define IPPROTO_NONE        IPPROTO_NONE
        IPPROTO_DSTOPTS = 60,  /* IPv6 destination options.  */
    #define IPPROTO_DSTOPTS        IPPROTO_DSTOPTS
        IPPROTO_MTP = 92,       /* Multicast Transport Protocol.  */
    #define IPPROTO_MTP        IPPROTO_MTP
        IPPROTO_ENCAP = 98,       /* Encapsulation Header.  */
    #define IPPROTO_ENCAP        IPPROTO_ENCAP
        IPPROTO_PIM = 103,       /* Protocol Independent Multicast.  */
    #define IPPROTO_PIM        IPPROTO_PIM
        IPPROTO_COMP = 108,       /* Compression Header Protocol.  */
    #define IPPROTO_COMP        IPPROTO_COMP
        IPPROTO_SCTP = 132,       /* Stream Control Transmission Protocol.  */
    #define IPPROTO_SCTP        IPPROTO_SCTP
        IPPROTO_UDPLITE = 136, /* UDP-Lite protocol.  */
    #define IPPROTO_UDPLITE        IPPROTO_UDPLITE
        IPPROTO_RAW = 255,       /* Raw IP packets.  */
    #define IPPROTO_RAW        IPPROTO_RAW
        IPPROTO_MAX
      };
    
    
    /* Type to represent a port.  */
    typedef uint16_t in_port_t;
    
    /* Standard well-known ports.  */
    enum
      {
        IPPORT_ECHO = 7,        /* Echo service.  */
        IPPORT_DISCARD = 9,        /* Discard transmissions service.  */
        IPPORT_SYSTAT = 11,        /* System status service.  */
        IPPORT_DAYTIME = 13,    /* Time of day service.  */
        IPPORT_NETSTAT = 15,    /* Network status service.  */
        IPPORT_FTP = 21,        /* File Transfer Protocol.  */
        IPPORT_TELNET = 23,        /* Telnet protocol.  */
        IPPORT_SMTP = 25,        /* Simple Mail Transfer Protocol.  */
        IPPORT_TIMESERVER = 37,    /* Timeserver service.  */
        IPPORT_NAMESERVER = 42,    /* Domain Name Service.  */
        IPPORT_WHOIS = 43,        /* Internet Whois service.  */
        IPPORT_MTP = 57,
    
        IPPORT_TFTP = 69,        /* Trivial File Transfer Protocol.  */
        IPPORT_RJE = 77,
        IPPORT_FINGER = 79,        /* Finger service.  */
        IPPORT_TTYLINK = 87,
        IPPORT_SUPDUP = 95,        /* SUPDUP protocol.  */
    
    
        IPPORT_EXECSERVER = 512,    /* execd service.  */
        IPPORT_LOGINSERVER = 513,    /* rlogind service.  */
        IPPORT_CMDSERVER = 514,
        IPPORT_EFSSERVER = 520,
    
        /* UDP ports.  */
        IPPORT_BIFFUDP = 512,
        IPPORT_WHOSERVER = 513,
        IPPORT_ROUTESERVER = 520,
    
        /* Ports less than this value are reserved for privileged processes.  */
        IPPORT_RESERVED = 1024,
    
        /* Ports greater this value are reserved for (non-privileged) servers.  */
        IPPORT_USERRESERVED = 5000
      };
    
    
    /* Internet address.  */
    typedef uint32_t in_addr_t;
    struct in_addr
    {
        in_addr_t s_addr;
    };
    
    
    /* Definitions of the bits in an Internet address integer.
    
       On subnets, host and network parts are found according to
       the subnet mask, not these masks.  */
    
    #define    IN_CLASSA(a)        ((((in_addr_t)(a)) & 0x80000000) == 0)
    #define    IN_CLASSA_NET        0xff000000
    #define    IN_CLASSA_NSHIFT    24
    #define    IN_CLASSA_HOST        (0xffffffff & ~IN_CLASSA_NET)
    #define    IN_CLASSA_MAX        128
    
    #define    IN_CLASSB(a)        ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
    #define    IN_CLASSB_NET        0xffff0000
    #define    IN_CLASSB_NSHIFT    16
    #define    IN_CLASSB_HOST        (0xffffffff & ~IN_CLASSB_NET)
    #define    IN_CLASSB_MAX        65536
    
    #define    IN_CLASSC(a)        ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
    #define    IN_CLASSC_NET        0xffffff00
    #define    IN_CLASSC_NSHIFT    8
    #define    IN_CLASSC_HOST        (0xffffffff & ~IN_CLASSC_NET)
    
    #define    IN_CLASSD(a)        ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
    #define    IN_MULTICAST(a)        IN_CLASSD(a)
    
    #define    IN_EXPERIMENTAL(a)    ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
    #define    IN_BADCLASS(a)        ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)
    
    /* Address to accept any incoming messages.  */
    #define    INADDR_ANY        ((in_addr_t) 0x00000000)
    /* Address to send to all hosts.  */
    #define    INADDR_BROADCAST    ((in_addr_t) 0xffffffff)
    /* Address indicating an error return.  */
    #define    INADDR_NONE        ((in_addr_t) 0xffffffff)
    
    /* Network number for local host loopback.  */
    #define    IN_LOOPBACKNET        127
    /* Address to loopback in software to local host.  */
    #ifndef INADDR_LOOPBACK
    # define INADDR_LOOPBACK    ((in_addr_t) 0x7f000001) /* Inet 127.0.0.1.  */
    #endif
    
    /* Defines for Multicast INADDR.  */
    #define INADDR_UNSPEC_GROUP    ((in_addr_t) 0xe0000000) /* 224.0.0.0 */
    #define INADDR_ALLHOSTS_GROUP    ((in_addr_t) 0xe0000001) /* 224.0.0.1 */
    #define INADDR_ALLRTRS_GROUP    ((in_addr_t) 0xe0000002) /* 224.0.0.2 */
    #define INADDR_MAX_LOCAL_GROUP  ((in_addr_t) 0xe00000ff) /* 224.0.0.255 */
    
    
    #if defined __UCLIBC_HAS_IPV6__ || !defined __UCLIBC_STRICT_HEADERS__
    /* IPv6 address */
    struct in6_addr
      {
        union
          {
        uint8_t    __u6_addr8[16];
    #if defined __USE_MISC || defined __USE_GNU
        uint16_t __u6_addr16[8];
        uint32_t __u6_addr32[4];
    #endif
          } __in6_u;
    #define s6_addr            __in6_u.__u6_addr8
    #if defined __USE_MISC || defined __USE_GNU
    # define s6_addr16        __in6_u.__u6_addr16
    # define s6_addr32        __in6_u.__u6_addr32
    #endif
      };
    
    #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
    #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
    
    #define INET6_ADDRSTRLEN 46
    #endif
    
    #ifdef __UCLIBC_HAS_IPV6__
    extern const struct in6_addr in6addr_any;        /* :: */
    extern const struct in6_addr in6addr_loopback;   /* ::1 */
    libc_hidden_proto(in6addr_loopback)
    #endif
    
    #define INET_ADDRSTRLEN 16
    
    
    #if 1 /*def __UCLIBC_HAS_IPV4__*/
    /* Structure describing an Internet socket address.  */
    struct sockaddr_in
      {
        __SOCKADDR_COMMON (sin_);
        in_port_t sin_port;            /* Port number.  */
        struct in_addr sin_addr;        /* Internet address.  */
    
        /* Pad to size of `struct sockaddr'.  */
        unsigned char sin_zero[sizeof (struct sockaddr) -
                   __SOCKADDR_COMMON_SIZE -
                   sizeof (in_port_t) -
                   sizeof (struct in_addr)];
      };
    #endif
    
    #if defined __UCLIBC_HAS_IPV6__ || !defined __UCLIBC_STRICT_HEADERS__
    /* Ditto, for IPv6.  */
    struct sockaddr_in6
      {
        __SOCKADDR_COMMON (sin6_);
        in_port_t sin6_port;    /* Transport layer port # */
        uint32_t sin6_flowinfo;    /* IPv6 flow information */
        struct in6_addr sin6_addr;    /* IPv6 address */
        uint32_t sin6_scope_id;    /* IPv6 scope-id */
      };
    #endif
    
    
    #if defined __USE_MISC || defined __USE_GNU
    /* IPv4 multicast request.  */
    struct ip_mreq
      {
        /* IP multicast address of group.  */
        struct in_addr imr_multiaddr;
    
        /* Local IP address of interface.  */
        struct in_addr imr_interface;
      };
    
    struct ip_mreq_source
      {
        /* IP multicast address of group.  */
        struct in_addr imr_multiaddr;
    
        /* IP address of source.  */
        struct in_addr imr_interface;
    
        /* IP address of interface.  */
        struct in_addr imr_sourceaddr;
      };
    #endif
    
    
    #if defined __UCLIBC_HAS_IPV6__ || !defined __UCLIBC_STRICT_HEADERS__
    /* Likewise, for IPv6.  */
    struct ipv6_mreq
      {
        /* IPv6 multicast address of group */
        struct in6_addr ipv6mr_multiaddr;
    
        /* local interface */
        unsigned int ipv6mr_interface;
      };
    #endif
    
    
    #if defined __USE_MISC || defined __USE_GNU
    /* Multicast group request.  */
    struct group_req
      {
        /* Interface index.  */
        uint32_t gr_interface;
    
        /* Group address.  */
        struct sockaddr_storage gr_group;
      };
    
    struct group_source_req
      {
        /* Interface index.  */
        uint32_t gsr_interface;
    
        /* Group address.  */
        struct sockaddr_storage gsr_group;
    
        /* Source address.  */
        struct sockaddr_storage gsr_source;
      };
    
    
    /* Full-state filter operations.  */
    struct ip_msfilter
      {
        /* IP multicast address of group.  */
        struct in_addr imsf_multiaddr;
    
        /* Local IP address of interface.  */
        struct in_addr imsf_interface;
    
        /* Filter mode.  */
        uint32_t imsf_fmode;
    
        /* Number of source addresses.  */
        uint32_t imsf_numsrc;
        /* Source addresses.  */
        struct in_addr imsf_slist[1];
      };
    
    #define IP_MSFILTER_SIZE(numsrc) (sizeof (struct ip_msfilter) 
                      - sizeof (struct in_addr)              
                      + (numsrc) * sizeof (struct in_addr))
    
    struct group_filter
      {
        /* Interface index.  */
        uint32_t gf_interface;
    
        /* Group address.  */
        struct sockaddr_storage gf_group;
    
        /* Filter mode.  */
        uint32_t gf_fmode;
    
        /* Number of source addresses.  */
        uint32_t gf_numsrc;
        /* Source addresses.  */
        struct sockaddr_storage gf_slist[1];
    };

    socket.h

    /* System-specific socket constants and types.  Linux version.
       Copyright (C) 1991,1992,1994-2001,2004,2006 Free Software Foundation, Inc.
       This file is part of the GNU C Library.
    
       The GNU C Library is free software; you can redistribute it and/or
       modify it under the terms of the GNU Lesser General Public
       License as published by the Free Software Foundation; either
       version 2.1 of the License, or (at your option) any later version.
    
       The GNU C Library is distributed in the hope that it will be useful,
       but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       Lesser General Public License for more details.
    
       You should have received a copy of the GNU Lesser General Public
       License along with the GNU C Library; if not, write to the Free
       Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
       02111-1307 USA.  */
    
    #ifndef __BITS_SOCKET_H
    #define __BITS_SOCKET_H
    
    #if !defined _SYS_SOCKET_H && !defined _NETINET_IN_H
    # error "Never include <bits/socket.h> directly; use <sys/socket.h> instead."
    #endif
    
    #define    __need_size_t
    #define __need_NULL
    #include <stddef.h>
    
    #include <limits.h>
    #include <sys/types.h>
    
    /* Type for length arguments in socket calls.  */
    #ifndef __socklen_t_defined
    typedef __socklen_t socklen_t;
    # define __socklen_t_defined
    #endif
    
    /* Types of sockets.  */
    enum __socket_type
    {
      SOCK_STREAM = 1,        /* Sequenced, reliable, connection-based
                       byte streams.  */
    #define SOCK_STREAM SOCK_STREAM
      SOCK_DGRAM = 2,        /* Connectionless, unreliable datagrams
                       of fixed maximum length.  */
    #define SOCK_DGRAM SOCK_DGRAM
      SOCK_RAW = 3,            /* Raw protocol interface.  */
    #define SOCK_RAW SOCK_RAW
      SOCK_RDM = 4,            /* Reliably-delivered messages.  */
    #define SOCK_RDM SOCK_RDM
      SOCK_SEQPACKET = 5,        /* Sequenced, reliable, connection-based,
                       datagrams of fixed maximum length.  */
    #define SOCK_SEQPACKET SOCK_SEQPACKET
      SOCK_PACKET = 10,        /* Linux specific way of getting packets
                       at the dev level.  For writing rarp and
                       other similar things on the user level. */
    #define SOCK_PACKET SOCK_PACKET
    
      /* Flags to be ORed into the type parameter of socket and socketpair and
         used for the flags parameter of paccept.  */
    
      SOCK_CLOEXEC = 02000000,    /* Atomically set close-on-exec flag for the
                       new descriptor(s).  */
    #define SOCK_CLOEXEC SOCK_CLOEXEC
      SOCK_NONBLOCK = 04000        /* Atomically mark descriptor(s) as
                       non-blocking.  */
    #define SOCK_NONBLOCK SOCK_NONBLOCK
    };
    
    /* Protocol families.  */
    #define    PF_UNSPEC    0    /* Unspecified.  */
    #define    PF_LOCAL    1    /* Local to host (pipes and file-domain).  */
    #define    PF_UNIX        PF_LOCAL /* Old BSD name for PF_LOCAL.  */
    #define    PF_FILE        PF_LOCAL /* Another non-standard name for PF_LOCAL.  */
    #define    PF_INET        2    /* IP protocol family.  */
    #define    PF_AX25        3    /* Amateur Radio AX.25.  */
    #define    PF_IPX        4    /* Novell Internet Protocol.  */
    #define    PF_APPLETALK    5    /* Appletalk DDP.  */
    #define    PF_NETROM    6    /* Amateur radio NetROM.  */
    #define    PF_BRIDGE    7    /* Multiprotocol bridge.  */
    #define    PF_ATMPVC    8    /* ATM PVCs.  */
    #define    PF_X25        9    /* Reserved for X.25 project.  */
    #define    PF_INET6    10    /* IP version 6.  */
    #define    PF_ROSE        11    /* Amateur Radio X.25 PLP.  */
    #define    PF_DECnet    12    /* Reserved for DECnet project.  */
    #define    PF_NETBEUI    13    /* Reserved for 802.2LLC project.  */
    #define    PF_SECURITY    14    /* Security callback pseudo AF.  */
    #define    PF_KEY        15    /* PF_KEY key management API.  */
    #define    PF_NETLINK    16
    #define    PF_ROUTE    PF_NETLINK /* Alias to emulate 4.4BSD.  */
    #define    PF_PACKET    17    /* Packet family.  */
    #define    PF_ASH        18    /* Ash.  */
    #define    PF_ECONET    19    /* Acorn Econet.  */
    #define    PF_ATMSVC    20    /* ATM SVCs.  */
    #define    PF_SNA        22    /* Linux SNA Project */
    #define    PF_IRDA        23    /* IRDA sockets.  */
    #define    PF_PPPOX    24    /* PPPoX sockets.  */
    #define    PF_WANPIPE    25    /* Wanpipe API sockets.  */
    #define    PF_LLC        26    /* Linux LLC.  */
    #define    PF_CAN        29    /* Controller Area Network.  */
    #define    PF_TIPC        30    /* TIPC sockets.  */
    #define    PF_BLUETOOTH    31    /* Bluetooth sockets.  */
    #define    PF_IUCV        32    /* IUCV sockets.  */
    #define    PF_RXRPC    33    /* RxRPC sockets.  */
    #define    PF_ISDN        34    /* mISDN sockets.  */
    #define    PF_PHONET    35    /* Phonet sockets.  */
    #define    PF_IEEE802154    36    /* IEEE 802.15.4 sockets.  */
    #define    PF_CAIF        37    /* CAIF sockets.  */
    #define    PF_ALG        38    /* Algorithm sockets.  */
    #define    PF_MAX        39    /* For now..  */
    
    /* Address families.  */
    #define    AF_UNSPEC    PF_UNSPEC
    #define    AF_LOCAL    PF_LOCAL
    #define    AF_UNIX        PF_UNIX
    #define    AF_FILE        PF_FILE
    #define    AF_INET        PF_INET
    #define    AF_AX25        PF_AX25
    #define    AF_IPX        PF_IPX
    #define    AF_APPLETALK    PF_APPLETALK
    #define    AF_NETROM    PF_NETROM
    #define    AF_BRIDGE    PF_BRIDGE
    #define    AF_ATMPVC    PF_ATMPVC
    #define    AF_X25        PF_X25
    #define    AF_INET6    PF_INET6
    #define    AF_ROSE        PF_ROSE
    #define    AF_DECnet    PF_DECnet
    #define    AF_NETBEUI    PF_NETBEUI
    #define    AF_SECURITY    PF_SECURITY
    #define    AF_KEY        PF_KEY
    #define    AF_NETLINK    PF_NETLINK
    #define    AF_ROUTE    PF_ROUTE
    #define    AF_PACKET    PF_PACKET
    #define    AF_ASH        PF_ASH
    #define    AF_ECONET    PF_ECONET
    #define    AF_ATMSVC    PF_ATMSVC
    #define    AF_SNA        PF_SNA
    #define    AF_IRDA        PF_IRDA
    #define    AF_PPPOX    PF_PPPOX
    #define    AF_WANPIPE    PF_WANPIPE
    #define    AF_LLC        PF_LLC
    #define    AF_CAN        PF_CAN
    #define    AF_TIPC        PF_TIPC
    #define    AF_BLUETOOTH    PF_BLUETOOTH
    #define    AF_IUCV        PF_IUCV
    #define    AF_RXRPC    PF_RXRPC
    #define    AF_ISDN        PF_ISDN
    #define    AF_PHONET    PF_PHONET
    #define    AF_IEEE802154    PF_IEEE802154
    #define    AF_CAIF        PF_CAIF
    #define    AF_ALG        PF_ALG
    #define    AF_MAX        PF_MAX
    
    /* Socket level values.  Others are defined in the appropriate headers.
    
       XXX These definitions also should go into the appropriate headers as
       far as they are available.  */
    #define SOL_RAW        255
    #define SOL_DECNET      261
    #define SOL_X25         262
    #define SOL_PACKET    263
    #define SOL_ATM        264    /* ATM layer (cell level).  */
    #define SOL_AAL        265    /* ATM Adaption Layer (packet level).  */
    #define SOL_IRDA    266
    
    /* Maximum queue length specifiable by listen.  */
    #define SOMAXCONN    128
    
    /* Get the definition of the macro to define the common sockaddr members.  */
    #include <bits/sockaddr.h>
    
    /* Structure describing a generic socket address.  */
    struct sockaddr
      {
        __SOCKADDR_COMMON (sa_);    /* Common data: address family and length.  */
        char sa_data[14];        /* Address data.  */
      };
    
    
    /* Structure large enough to hold any socket address (with the historical
       exception of AF_UNIX).  We reserve 128 bytes.  */
    #if ULONG_MAX > 0xffffffff
    # define __ss_aligntype    __uint64_t
    #else
    # define __ss_aligntype    __uint32_t
    #endif
    #define _SS_SIZE    128
    #define _SS_PADSIZE    (_SS_SIZE - (2 * sizeof (__ss_aligntype)))
    
    struct sockaddr_storage
      {
        __SOCKADDR_COMMON (ss_);    /* Address family, etc.  */
        __ss_aligntype __ss_align;    /* Force desired alignment.  */
        char __ss_padding[_SS_PADSIZE];
      };
    
    
    /* Bits in the FLAGS argument to `send', `recv', et al.  */
    enum
      {
        MSG_OOB        = 0x01,    /* Process out-of-band data.  */
    #define MSG_OOB        MSG_OOB
        MSG_PEEK        = 0x02,    /* Peek at incoming messages.  */
    #define MSG_PEEK    MSG_PEEK
        MSG_DONTROUTE    = 0x04,    /* Don't use local routing.  */
    #define MSG_DONTROUTE    MSG_DONTROUTE
    #ifdef __USE_GNU
        /* DECnet uses a different name.  */
        MSG_TRYHARD        = MSG_DONTROUTE,
    # define MSG_TRYHARD    MSG_DONTROUTE
    #endif
        MSG_CTRUNC        = 0x08,    /* Control data lost before delivery.  */
    #define MSG_CTRUNC    MSG_CTRUNC
        MSG_PROXY        = 0x10,    /* Supply or ask second address.  */
    #define MSG_PROXY    MSG_PROXY
        MSG_TRUNC        = 0x20,
    #define    MSG_TRUNC    MSG_TRUNC
        MSG_DONTWAIT    = 0x40, /* Nonblocking IO.  */
    #define    MSG_DONTWAIT    MSG_DONTWAIT
        MSG_EOR        = 0x80, /* End of record.  */
    #define    MSG_EOR        MSG_EOR
        MSG_WAITALL        = 0x100, /* Wait for a full request.  */
    #define    MSG_WAITALL    MSG_WAITALL
        MSG_FIN        = 0x200,
    #define    MSG_FIN        MSG_FIN
        MSG_SYN        = 0x400,
    #define    MSG_SYN        MSG_SYN
        MSG_CONFIRM        = 0x800, /* Confirm path validity.  */
    #define    MSG_CONFIRM    MSG_CONFIRM
        MSG_RST        = 0x1000,
    #define    MSG_RST        MSG_RST
        MSG_ERRQUEUE    = 0x2000, /* Fetch message from error queue.  */
    #define    MSG_ERRQUEUE    MSG_ERRQUEUE
        MSG_NOSIGNAL    = 0x4000, /* Do not generate SIGPIPE.  */
    #define    MSG_NOSIGNAL    MSG_NOSIGNAL
        MSG_MORE        = 0x8000  /* Sender will send more.  */
    #define    MSG_MORE    MSG_MORE
      };
    
    
    /* Structure describing messages sent by
       `sendmsg' and received by `recvmsg'.  */
    /* Note: do not change these members to match glibc; these match the
       SuSv3 spec already (e.g. msg_iovlen/msg_controllen).
       http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/socket.h.html */
    /* Note: linux kernel uses __kernel_size_t (which is 8bytes on 64bit
       platforms, and 4bytes on 32bit platforms) for msg_iovlen/msg_controllen */
    struct msghdr
      {
        void *msg_name;        /* Address to send to/receive from.  */
        socklen_t msg_namelen;    /* Length of address data.  */
    
        struct iovec *msg_iov;    /* Vector of data to send/receive into.  */
    #if __WORDSIZE == 32
        int msg_iovlen;        /* Number of elements in the vector.  */
    #else
        size_t msg_iovlen;        /* Number of elements in the vector.  */
    #endif
    
        void *msg_control;        /* Ancillary data (eg BSD filedesc passing). */
    #if __WORDSIZE == 32
        socklen_t msg_controllen;    /* Ancillary data buffer length.  */
    #else
        size_t msg_controllen;    /* Ancillary data buffer length.  */
    #endif
    
        int msg_flags;        /* Flags on received message.  */
      };
    
    /* Structure used for storage of ancillary data object information.  */
    struct cmsghdr
      {
        size_t cmsg_len;        /* Length of data in cmsg_data plus length
                       of cmsghdr structure.  */
        int cmsg_level;        /* Originating protocol.  */
        int cmsg_type;        /* Protocol specific type.  */
    #if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L
        __extension__ unsigned char __cmsg_data __flexarr; /* Ancillary data.  */
    #endif
      };
    
    /* Ancillary data object manipulation macros.  */
    #if (!defined __STRICT_ANSI__ && __GNUC__ >= 2) || __STDC_VERSION__ >= 199901L
    # define CMSG_DATA(cmsg) ((cmsg)->__cmsg_data)
    #else
    # define CMSG_DATA(cmsg) ((unsigned char *) ((struct cmsghdr *) (cmsg) + 1))
    #endif
    #define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg)
    #define CMSG_FIRSTHDR(mhdr) 
      ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr)              
       ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
    #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) 
                 & (size_t) ~(sizeof (size_t) - 1))
    #define CMSG_SPACE(len) (CMSG_ALIGN (len) 
                 + CMSG_ALIGN (sizeof (struct cmsghdr)))
    #define CMSG_LEN(len)   (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
    
    extern struct cmsghdr *__cmsg_nxthdr (struct msghdr *__mhdr,
                          struct cmsghdr *__cmsg) __THROW;
    libc_hidden_proto(__cmsg_nxthdr)
    #ifdef __USE_EXTERN_INLINES
    # ifndef _EXTERN_INLINE
    #  define _EXTERN_INLINE extern __inline
    # endif
    _EXTERN_INLINE struct cmsghdr *
    __NTH (__cmsg_nxthdr (struct msghdr *__mhdr, struct cmsghdr *__cmsg))
    {
      if ((size_t) __cmsg->cmsg_len < sizeof (struct cmsghdr))
        /* The kernel header does this so there may be a reason.  */
        return 0;
    
      __cmsg = (struct cmsghdr *) ((unsigned char *) __cmsg
                       + CMSG_ALIGN (__cmsg->cmsg_len));
      if ((unsigned char *) (__cmsg + 1) > ((unsigned char *) __mhdr->msg_control
                        + __mhdr->msg_controllen)
          || ((unsigned char *) __cmsg + CMSG_ALIGN (__cmsg->cmsg_len)
          > ((unsigned char *) __mhdr->msg_control + __mhdr->msg_controllen)))
        /* No more entries.  */
        return 0;
      return __cmsg;
    }
    #endif    /* Use `extern inline'.  */
    
    /* Socket level message types.  This must match the definitions in
       <linux/socket.h>.  */
    enum
      {
        SCM_RIGHTS = 0x01        /* Transfer file descriptors.  */
    #define SCM_RIGHTS SCM_RIGHTS
    #ifdef __USE_BSD
        , SCM_CREDENTIALS = 0x02    /* Credentials passing.  */
    # define SCM_CREDENTIALS SCM_CREDENTIALS
    #endif
      };
    
    /* User visible structure for SCM_CREDENTIALS message */
    
    struct ucred
    {
      pid_t pid;            /* PID of sending process.  */
      uid_t uid;            /* UID of sending process.  */
      gid_t gid;            /* GID of sending process.  */
    };
    
    /* Get socket manipulation related informations from kernel headers.  */
    #ifndef __GLIBC__
    #define __GLIBC__ 2
    #include <asm/socket.h>
    #undef __GLIBC__
    #else
    #include <asm/socket.h>
    #endif
    
    
    /* Structure used to manipulate the SO_LINGER option.  */
    struct linger
      {
        int l_onoff;        /* Nonzero to linger on close.  */
        int l_linger;        /* Time to linger.  */
      };
    
    #endif    /* bits/socket.h */

    sockaddr.h:

    #ifndef _BITS_SOCKADDR_H
    #define _BITS_SOCKADDR_H    1
    
    
    /* POSIX.1g specifies this type name for the `sa_family' member.  */
    typedef unsigned short int sa_family_t;
    
    /* This macro is used to declare the initial common members
       of the data types used for socket addresses, `struct sockaddr',
       `struct sockaddr_in', `struct sockaddr_un', etc.  */                                                                                                                                                      
    
    #define __SOCKADDR_COMMON(sa_prefix) 
      sa_family_t sa_prefix##family
      
    #define __SOCKADDR_COMMON_SIZE  (sizeof (unsigned short int))
        
    #endif  /* bits/sockaddr.h */

    aa

  • 相关阅读:
    修改root密码
    环境的搭建(四)--------samba服务
    16.统一异常处理(上)编写自定义处理函数
    15.集成限流功能到我们的服务中(花操作必看)
    14.go内置的rate包学习2(有花操作,必看)
    13.go内置的rate包学习1
    12.使用负载均衡的方式调用服务(随机方式)
    11.使用负载均衡的方式调用服务(轮询方式)
    10.根据命令行参数注册多个服务
    9.consul获取服务实例,调用测试
  • 原文地址:https://www.cnblogs.com/jingzhishen/p/5605201.html
Copyright © 2011-2022 走看看