获取设置套接字选项:getsockopt, setsockopt

首先看个文件

环境cygwin

asm/socket.h

//$ cat socket.h
/* asm/socket.h

This file is part of Cygwin.

This software is a copyrighted work licensed under the terms of the
Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
details. */

#ifndef _ASM_SOCKET_H
#define _ASM_SOCKET_H

#include <cygwin/if.h>

#define IOCPARM_MASK    0x7f            /* parameters must be < 128 bytes */
#define IOC_VOID        0x20000000      /* no parameters */
#define IOC_OUT         0x40000000      /* copy out parameters */
#define IOC_IN          0x80000000      /* copy in parameters */

#define _IO(x,y)        (IOC_VOID|(x<<8)|y)
#define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)
#define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|(x<<8)|y)

#define SIOCATMARK  _IOR('s',  7, long)  /* at oob mark? */
#define FIONREAD    _IOR('f', 127, long) /* get # bytes to read */
#define SIOCINQ     FIONREAD
/* Compatible with termios.h */
#define FIONBIO     0x8004667e           /* set/clear non-blocking i/o */
#define FIOASYNC    _IOW('f', 125, long) /* set/clear async i/o */
#define SIOCSHIWAT  _IOW('s',  0, long)  /* set high watermark */
#define SIOCGHIWAT  _IOR('s',  1, long)  /* get high watermark */
#define SIOCSLOWAT  _IOW('s',  2, long)  /* set low watermark */
#define SIOCGLOWAT  _IOR('s',  3, long)  /* get low watermark */

/* Needed for if queries */
#define SIOCGIFCONF     _IOW('s', 100, struct ifconf) /* get if list */
#define SIOCGIFFLAGS    _IOW('s', 101, struct ifreq) /* Get if flags */
#define SIOCGIFADDR     _IOW('s', 102, struct ifreq) /* Get if addr */
#define SIOCGIFBRDADDR  _IOW('s', 103, struct ifreq) /* Get if broadcastaddr */
#define SIOCGIFNETMASK  _IOW('s', 104, struct ifreq) /* Get if netmask */
#define SIOCGIFHWADDR   _IOW('s', 105, struct ifreq) /* Get hw addr */
#define SIOCGIFMETRIC   _IOW('s', 106, struct ifreq) /* get metric */
#define SIOCGIFMTU      _IOW('s', 107, struct ifreq) /* get MTU size */
#define SIOCGIFINDEX    _IOW('s', 108, struct ifreq) /* get if index */
#define SIOGIFINDEX SIOCGIFINDEX /* backward compatibility w/ Linux typo. */
#define SIOCGIFFRNDLYNAM _IOW('s', 109, struct ifreq) /* get friendly if name */
#define SIOCGIFDSTADDR  _IOW('s', 110, struct ifreq) /* Get if dstaddr */

#define SOL_SOCKET      0xffff          /* options for socket level */

#define SO_DEBUG        0x0001          /* turn on debugging info recording */
#define SO_ACCEPTCONN   0x0002          /* socket has had listen() */
#define SO_REUSEADDR    0x0004          /* allow local address reuse */
#define SO_KEEPALIVE    0x0008          /* keep connections alive */
#define SO_DONTROUTE    0x0010          /* just use interface addresses */
#define SO_BROADCAST    0x0020          /* permit sending of broadcast msgs */
#define SO_USELOOPBACK  0x0040          /* bypass hardware when possible */
#define SO_LINGER       0x0080          /* linger on close if data present */
#define SO_OOBINLINE    0x0100          /* leave received OOB data in line */
#define SO_DONTLINGER   (unsigned int)(~SO_LINGER)
#define SO_PEERCRED     0x0200          /* same as getpeereid */
#define SO_PASSCRED     0x0400          /* enable receiving of credentials */

/*
 * Additional options.
 */
#define SO_SNDBUF       0x1001          /* send buffer size */
#define SO_RCVBUF       0x1002          /* receive buffer size */
#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_ERROR        0x1007          /* get error status and clear */
#define SO_TYPE         0x1008          /* get socket type */

#endif /* _ASM_SOCKET_H */

sys/socket.h

//$ cat sys/socket.h
/* sys/socket.h

This file is part of Cygwin.

This software is a copyrighted work licensed under the terms of the
Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
details. */

#ifndef _SYS_SOCKET_H
#define _SYS_SOCKET_H

#include <features.h>
#include <cygwin/socket.h>

#ifdef __cplusplus
extern "C"
{
#endif

#ifndef __INSIDE_CYGWIN_NET__
  int accept (int, struct sockaddr *__peer, socklen_t *);
  int accept4 (int, struct sockaddr *__peer, socklen_t *, int flags);
  int bind (int, const struct sockaddr *__my_addr, socklen_t __addrlen);
  int connect (int, const struct sockaddr *, socklen_t);
  int getpeername (int, struct sockaddr *__peer, socklen_t *);
  int getsockname (int, struct sockaddr *__addr, socklen_t *);
  int listen (int, int __n);
  ssize_t recv (int, void *__buff, size_t __len, int __flags);
  ssize_t recvfrom (int, void *__buff, size_t __len, int __flags,
                    struct sockaddr *__from, socklen_t *__fromlen);
  ssize_t recvmsg(int s, struct msghdr *msg, int flags);
  ssize_t send (int, const void *__buff, size_t __len, int __flags);
  ssize_t sendmsg(int s, const struct msghdr *msg, int flags);
  ssize_t sendto (int, const void *, size_t __len, int __flags,
                  const struct sockaddr *__to, socklen_t __tolen);
  int setsockopt (int __s, int __level, int __optname, const void *optval,
                  socklen_t __optlen);
  int getsockopt (int __s, int __level, int __optname, void *__optval,
                  socklen_t *__optlen);
  int shutdown (int, int);
  int socket (int __family, int __type, int __protocol);
  int sockatmark (int __fd);
  int socketpair (int __domain, int __type, int __protocol, int __fds[2]);

  struct servent *getservbyname (const char *__name, const char *__proto);
#endif

#ifdef __cplusplus
};
#endif

#if __SSP_FORTIFY_LEVEL > 0
#include <ssp/socket.h>
#endif

#endif /* _SYS_SOCKET_H */

说明

 SOL_SOCKET
------------------------------------------------------------------------
SO_BROADCAST      允许发送广播数据            int
SO_DEBUG        允许调试                int
SO_DONTROUTE      不查找路由               int
SO_ERROR        获得套接字错误             int
SO_KEEPALIVE      保持连接                int
SO_LINGER        延迟关闭连接              struct linger
SO_OOBINLINE      带外数据放入正常数据流         int
SO_RCVBUF        接收缓冲区大小             int
SO_SNDBUF        发送缓冲区大小             int
SO_RCVLOWAT       接收缓冲区下限             int
SO_SNDLOWAT       发送缓冲区下限             int
SO_RCVTIMEO       接收超时                struct timeval
SO_SNDTIMEO       发送超时                struct timeval
SO_REUSERADDR      允许重用本地地址和端口         int
SO_TYPE         获得套接字类型             int
SO_BSDCOMPAT      与BSD系统兼容              int
========================================================================
            IPPROTO_IP
------------------------------------------------------------------------
IP_HDRINCL       在数据包中包含IP首部          int
IP_OPTINOS       IP首部选项               int
IP_TOS         服务类型
IP_TTL         生存时间                int
========================================================================
            IPPRO_TCP
------------------------------------------------------------------------
TCP_MAXSEG       TCP最大数据段的大小           int
TCP_NODELAY       不使用Nagle算法             int
========================================================================
链接:https://blog.csdn.net/qq_41097897/article/details/82845404

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页