socket编程常见宏定义和数据结构

本文详细介绍了socket编程中的宏定义,包括SO_DEBUG、SO_REUSEADDR等,以及相关数据结构如struct sockaddr、struct sockaddr_in等。这些定义和结构在设置套接字选项、地址操作等方面起着关键作用,对于理解和使用socket编程至关重要。
摘要由CSDN通过智能技术生成

一 socket.h 宏定义

/*
 * For setsockopt(2)
 *
 * This defines are ABI conformant as far as Linux supports these ...
 */
#define SOL_SOCKET    0xffff

#define SO_DEBUG    0x0001    /* Record debugging information.  */
#define SO_REUSEADDR    0x0004    /* Allow reuse of local addresses.  */
#define SO_KEEPALIVE    0x0008    /* Keep connections alive and send
                   SIGPIPE when they die.  */
#define SO_DONTROUTE    0x0010    /* Don't do local routing.  */
#define SO_BROADCAST    0x0020    /* Allow transmission of
                   broadcast messages.  */
#define SO_LINGER    0x0080    /* Block on close of a reliable
                   socket to transmit pending data.  */
#define SO_OOBINLINE 0x0100    /* Receive out-of-band data in-band.  */
#if 0
To add: #define SO_REUSEPORT 0x0200    /* Allow local address and port reuse.  */
#endif

#define SO_TYPE        0x1008    /* Compatible name for SO_STYLE.  */
#define SO_STYLE    SO_TYPE    /* Synonym */
#define SO_ERROR    0x1007    /* get error status and clear */
#define SO_SNDBUF    0x1001    /* Send buffer size. */
#define SO_RCVBUF    0x1002    /* Receive buffer. */
#define SO_SNDLOWAT    0x1003    /* send low-water mark */
#define SO_RCVLOWAT    0x1004    /* receive low-water mark */
#define SO_SNDTIMEO    0x1005    /* send timeout */
#define SO_RCVTIMEO     0x1006    /* receive timeout */
#define SO_ACCEPTCONN    0x1009
#define SO_PROTOCOL    0x1028    /* protocol type */
#define SO_DOMAIN    0x1029    /* domain/socket family */

/* linux-specific, might as well be the same as on i386 */
#define SO_NO_CHECK    11
#define SO_PRIORITY    12
#define SO_BSDCOMPAT    14

#define SO_PASSCRED    17
#define SO_PEERCRED    18

/* Socket filtering */
#define SO_ATTACH_FILTER        26
#define SO_DETACH_FILTER        27

#define SO_PEERNAME             28
#define SO_TIMESTAMP        29
#define SCM_TIMESTAMP        SO_TIMESTAMP

#define SO_PEERSEC        30
#define SO_SNDBUFFORCE        31
#define SO_RCVBUFFORCE        33
#define SO_PASSSEC        34
#define SO_TIMESTAMPNS        35
#define SCM_TIMESTAMPNS        SO_TIMESTAMPNS

#define SO_MARK            36

#define SO_TIMESTAMPING        37
#define SCM_TIMESTAMPING    SO_TIMESTAMPING

#define SO_RXQ_OVFL             40

/** sock_type - Socket types
 *
 * Please notice that for binary compat reasons MIPS has to
 * override the enum sock_type in include/linux/net.h, so
 * we define ARCH_HAS_SOCKET_TYPES here.
 *
 * @SOCK_DGRAM - datagram (conn.less) socket
 * @SOCK_STREAM - stream (connection) socket
 * @SOCK_RAW - raw socket
 * @SOCK_RDM - reliably-delivered message
 * @SOCK_SEQPACKET - sequential packet socket
 * @SOCK_PACKET - linux specific way of getting packets at the dev level.
 *          For writing rarp and other similar things on the user level.
 */
enum sock_type {
    SOCK_DGRAM    = 1,
    SOCK_STREAM    = 2,
    SOCK_RAW    = 3,
    SOCK_RDM    = 4,
    SOCK_SEQPACKET    = 5,
    SOCK_DCCP    = 6,
    SOCK_PACKET    = 10,
};

#define SOCK_MAX (SOCK_PACKET + 1)
/* Mask which covers at least up to SOCK_MASK-1.  The
 *  * remaining bits are used as flags. */
#define SOCK_TYPE_MASK 0xf

/* Flags for socket, socketpair, paccept */
#define SOCK_CLOEXEC    O_CLOEXEC
#define SOCK_NONBLOCK    O_NONBLOCK


/* Address to accept any incoming messages. */
#define    INADDR_ANY        ((unsigned long int) 0x00000000)

/* Address to send to all hosts. */
#define    INADDR_BROADCAST    ((unsigned long int) 0xffffffff)

/* Address indicating an error return. */
#define    INADDR_NONE        ((unsigned long int) 0xffffffff)

/* Network number for local host loopback. */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值