📄 socket.h
字号:
/** Copyright (c) 1998-2001 by NETsilicon Inc.** This software is copyrighted by and is the sole property of* NETsilicon. All rights, title, ownership, or other interests* in the software remain the property of NETsilicon. This* software may only be used in accordance with the corresponding* license agreement. Any unauthorized use, duplication, transmission,* distribution, or disclosure of this software is expressly forbidden.** This Copyright notice may not be removed or modified without prior* written consent of NETsilicon.** NETsilicon, reserves the right to modify this software* without notice.** NETsilicon* 411 Waverley Oaks Road USA 781.647.1234* Suite 227 http://www.netsilicon.com* Waltham, MA 02452 AmericaSales@netsilicon.com*************************************************************************** $Name: Fusion 6.52 Fusion 6.51 $* $Date: 2001/12/11 09:29:47 $* $Source: M:/psisrc/stack/incl/rcs/socket.h $* $Revision: 1.16 $*************************************************************************** File Description: Definitions and Macros for dealing with the sockets***************************************************************************/#ifndef _SOCKET_#define _SOCKET_#include "config.h"#include "ccdep.h"#include "std.h"/* some basic types */typedef u8 a16[2];typedef u8 a32[4];typedef u8 a48[6];/* address families */#define AF_UNSPEC 0 /* unspecified */#define AF_INTRA 1 /* O/S-dependent path names */#define AF_INET 2 /* ARPA Internet address */#define AF_ARP 7 /* Address Resolution Protocol */#define AF_RARP 9 /* Reverse Address Resolution Protocol */#define AF_1 10 /* customer expansion */#define AF_2 11 /* "" */#if 0/* no longer supported in Fusion */#define AF_NS 3 /* Xerox Network Systems protocols */#define AF_NBS 4 /* NBS protocols */#define AF_CCITT 5 /* CCITT protocols, X.25 etc */#define AF_SNA 6 /* IBM SNA */#define AF_KDB 8 /* Kernel DeBug Protocol */#endif/* link layer address families */#define AF_LL AF_2 /* last address family */#define AF_PPP (AF_LL+1) /* Raw PPP */#define AF_ETHER (AF_LL+2) /* Raw Ethernet */#define AF_LOOPBACK (AF_LL+3) /* Loopback */#define AF_CMAN (AF_LL+4) /* Raw Serial Channel manager */#define AF_IMPLINK (AF_LL+5) /* IMP "host at IMP" addresses */#define AF_SLIP (AF_LL+6) /* SLIP link layers */#define AF_DDN (AF_LL+7) /* DDN X.25 */#define AF_TRN (AF_LL+8) /* Token Ring */#define AF_FDDI (AF_LL+9) /* Fddi addresses */#define AF_L3 (AF_LL+10) /* " */#define AF_L4 (AF_LL+11) /* " */#define MAX_AF AF_L4 /* last link layer address family */#define MIN_LLAF AF_PPP /* first link layer address family */#define MAX_LLAF MAX_AF /* last link layer address family */#define AF_UNIX AF_INTRA /* UNIX path names */#define IS_LAN_TYPE(type) ((type) == AF_ETHER || (type) == AF_TRN \ || (type) == AF_FDDI)/* although the following address families alluded to by Berkeley have * a dubious future under Fusion, nevertheless, their names are reserved: * AF_PUP Xerox PUP-I internet address * AF_CHAOS MIT CHAOS protocols * AF_ECMA European computer manufacturers * AF_DATAKIT datakit protocols *//* address family and link layer address family counts / macros */#define NAF (MAX_AF+1) /* number of AF's */#define NLLAF (MAX_LLAF-MIN_LLAF+1) /* number of link layer AF's */#define af_ix(a) (a) /* AF to index */#define aflim(a) bound((a),(u16)0,(u16)MAX_AF) /* bound AF */#define afok(a) ((u16)(a)<=(u16)MAX_AF&&ahp_tbl[a]->ah_valid)#define llaf_ix(a) ((a)-(u16)MIN_LLAF) /* link layer AF to index */#define llaflim(a) bound((a),(u16)MIN_LLAF,(u16)MAX_LLAF) /* bound link layer AF */#define llafok(a) inbound((a),(u16)MIN_LLAF,(u16)MAX_LLAF)/* socket types */#define SOCK_STREAM 1 /* virtual circuit */#define SOCK_DGRAM 2 /* datagram */#define SOCK_RAW 3 /* raw socket */#define SOCK_RDM 4 /* reliable-delivered message */#define SOCK_SEQPACKET 5 /* sequenced packet */#define SOCK_PACK_EX 6 /* packet exchange non Berkeley *//* level number for get/setsopt to apply to socket itself */#define SOL_SOCKET (unsigned)0xFFFF#ifdef SOCKET_USE_OLD_SOCKOPT_FUNCTIONS#define SO_DEBUG 0x1 /* turn on debugging */#define SO_ACCEPTCONN 0x2 /* socket has had listen() */#define SO_REUSEADDR 0x4 /* allow local address reuse */#define SO_KEEPALIVE 0x8 /* keep connections alive */#define SO_DONTROUTE 0x10 /* just use interface addresses */#define SO_LINGER 0x80 /* linger on close if data is present */#define SO_THROUGHPUT 0x100 /* large data transfer; handle efficiently */#define SO_EXPEDITE 0x200 /* responsive (e.g. interactive) data */ #define SO_DONTLINGER (~SO_LINGER)/* The following macros pertain only to options which have an on/off status */#define SET_SOCKET_OPTION_ON(s,n) s->so_options |= n#define SET_SOCKET_OPTION_OFF(s,n) s->so_options &= ~(n)/* The following returns the option-name itself if the option is set, or zero if it is not set */#define GET_SOCKET_OPTION_STATUS(s,n) ((s->so_options & n) ? n : 0 )#else /* definitions to go with the new socket function calls *//* socket options used with get/setsopt calls *//* Do not use value zero -- won't work in getsockopt */#define SO_DEBUG 1 /* turn on debugging */#define SO_ACCEPTCONN 2 /* socket has had listen() */#define SO_REUSEADDR 3 /* allow local address reuse */#define SO_KEEPALIVE 4 /* keep connections alive */#define SO_DONTROUTE 5 /* just use interface addresses */#define SO_LINGER 6 /* linger on close if data is present */#define SO_THROUGHPUT 7 /* large data transfer; handle efficiently */#define SO_EXPEDITE 8 /* responsive (e.g. interactive) data * transfer; handle expeditiously *//* Following options added for Fusion 5.5 and later -- not supported via old socket option functions */#define SO_BROADCAST 9 /* Permit sending of broadcast datagrams */#define SO_REUSEPORT 10 /* Allow local address/port reuse */#define SO_ERROR 20 /* Return pending error and clear error status */#define SO_MAXMSG 21 /* Return value of TCP MSS */#define SO_MYADDR 22 /* Return local IP address of socket */#define SO_NONBLOCK 23 /* Indicates/controls whether socket is non-blocking */#define SO_OOBINLINE 24 /* Requests out-of-band data go into normal input queue */#define SO_RCVBUF 25 /* Adjusts socket input buffer size */#define SO_RXDATA 26 /* Indicates number of bytes of data in socket rcv buffer */#define SO_SNDBUF 27 /* Adjusts socket output buffer size */#define SO_TYPE 28 /* Returns type of socket */#define SO_BIO 29 /* Sets socket to use blocking I/O */#define SO_NBIO 30 /* Sets socket to use non-blocking I/O *//* The following macros pertain only to options which have an on/off status */#define SET_SOCKET_OPTION_ON(s,n) s->so_options |= (1 << n)#define SET_SOCKET_OPTION_OFF(s,n) s->so_options &= ~(1 << n)/* The following returns the option-name itself if the option is set, or zero if it is not set */#define GET_SOCKET_OPTION_STATUS(s,n) ((s->so_options & (1 << n) ) ? n : 0 )#endif#define MAXOPTVALEN 32 /* max. size of socket option value *//* 4.2bsd send/recv standard flags */#define MSG_OOB 0x1 /* process out of band information */#define MSG_PEEK 0x2 /* peek at incoming message */#define MSG_DONTROUTE 0x4 /* send without using routing tables */#ifdef TCP_TRANSACTION_TCP#define MSG_EOF 0x8 /* In a send call, means that this is the last data on the connection. Equivalent to calling send followed by shutdown. */#endif /* TCP_TRANSACTION_TCP *//* 4.2bsd standard flag mask */#ifndef TCP_TRANSACTION_TCP#define MSG_FLAGS (MSG_OOB|MSG_PEEK|MSG_DONTROUTE)#else#define MSG_FLAGS (MSG_OOB|MSG_PEEK|MSG_DONTROUTE|MSG_EOF)#endif /* TCP_TRANSACTION_TCP *//* NRC value added */#define MSG_BLOCKING 0x8000 /* override any nonblocking state */#define MSG_NONBLOCKING 0x4000 /* override any blocking state */#define MSG_FDBROADCAST 0x2000 /* want full duplex broadcasts */#define MSG_TRUNCATE 0x1000 /* truncate received packet */#define MSG_URGENT 0x0800 /* urgent data */#define MSG_REXMIT 0x0400 /* represents a retransmission; inform any * lower layers that there may be problems */#define MSG_MASK (MSG_FLAGS|MSG_BLOCKING|MSG_NONBLOCKING|MSG_FDBROADCAST|MSG_TRUNCATE|MSG_URGENT|MSG_REXMIT)/* Following structures need to be packed *//* Address structures for all supported families */typedef struct ipa { /* DARPA Internet Protocol Address */ u16 ip_port; /* protocol port number */ u32 ip_nethost; /* network/host address */} ipa;/* Typed socket addresses for all supported address families */typedef struct sockaddr { /* Generic socket address */ short sa_type; char sa_data[22];} saddr;/* Congruent to the WNJ-style stuff in "un.h" */typedef struct lsockaddr { /* Intramachine (local) socket address */ short sa_type; /* AF_INTRA */ char sa_name[2]; /* null-terminated string (can be longer) */} lsaddr;/* Congruent to the stuff in "in.h" */typedef struct isockaddr { /* DARPA Internet socket address */ short sa_type; /* AF_INET */ ipa sa_ipa;} ipsaddr;#define isa_port sa_ipa.ip_port #define isa_nethost sa_ipa.ip_nethost /* converts a (saddr) to an (isaddr *) */#define isaddrp(saddr) ((ipsaddr *)(&(saddr)))/* macros to extract the above from an 'saddr' structure */#define sa_port(saddr) (isaddrp(saddr)->isa_port)#define sa_nethost(saddr) (isaddrp(saddr)->isa_nethost)typedef struct eaddr { /* Raw Ethernet socket address */ short sa_type; /* AF_ETHER */ a48 sa_ena;} esaddr;typedef struct tsaddr { /* Raw Token Ring socket address */ short sa_type; /* AF_TRN */ a48 sa_tra;} tsaddr;typedef struct faddr { /* Raw FDDI socket address */ short sa_type; /* AF_FDDI */ a48 sa_fddi;} fsaddr;typedef struct kiaaddr { /* AF_INTRA address w/i the kernel */ u16 ksa_type; /* AF_INTRA */ u16 ksa_pad1; struct str_t * ksa_str; /* ptr. to name structure */} kiaaddr;typedef union sa_u { /* union of all types of socket addresses */ saddr au_saddr; /* generic */ lsaddr au_lsaddr; /* AF_INTRA: local to this machine */ ipsaddr au_isaddr; /* AF_INET: DARPA Internet */ esaddr au_esaddr; /* AF_ETHER: Ethernet address */ tsaddr au_tsaddr; /* AF_TRN: Token Ring address */ fsaddr au_fsaddr; /* AF_FDDI: fddi address */} sa_u;/* Security structures for all address families */typedef struct secure { /* Generic security structure */ char sec_data[16];} secure;/* Route key structure */typedef struct rte { saddr rte_net; /* network number (partial address) */ saddr rte_gwy; /* gateway host (full host address) */ secure rte_secure; /* security structure */} rte;/* Socket option value structure */typedef struct socketopt { int so_optlen; /* length of optdata area */ char * so_optdata; /* pointer to data */} socketopt;/* linger option value structure */#ifdef SOCKET_USE_OLD_SOCKOPT_FUNCTIONStypedef struct lingeropt { int linger_on; /* Linger option on or off */ int linger_time; /* Linger timeout value in seconds */} lingeropt;#elsetypedef struct linger { int l_onoff; /* Linger option on or off */ int l_linger; /* Linger timeout value in seconds */} lingeropt;#endif/* Internal structure for socket addresses. Congruent to Berkeley 'saddr' * structure from 'a_type' down. */typedef struct { u16 a_lltype; /* now used as copy of link layer type */ u16 a_len; union { sa_u a_sa_u; kiaaddr a_kiaaddr; } a_u;} so_addr;/* End of packed structures *//* short-hand definitions to get into so_addr */#define a_saddr a_u.a_sa_u.au_saddr#define a_type a_saddr.sa_type#define a_data a_saddr.sa_data#define a_lsaddr a_u.a_sa_u.au_lsaddr#define a_isaddr a_u.a_sa_u.au_isaddr#define a_esaddr a_u.a_sa_u.au_esaddr#define a_tsaddr a_u.a_sa_u.au_tsaddr#define a_fsaddr a_u.a_sa_u.au_fsaddr#define a_ipa a_isaddr.sa_ipa#define a_ena a_esaddr.sa_ena#define a_fddi a_fsaddr.sa_fddi#define a_tra a_tsaddr.sa_tra#define a_intra a_u.a_kiaaddr.ksa_str#define addr_len(ap) (((ap)->a_type==AF_INTRA?(ap)->a_intra->st_len:(ap)->a_len)+sizeof(u16))#define addr_saddr(ap) ((ap)->a_type==AF_INTRA?(saddr *)&(ap)->a_intra->st_type:&(ap)->a_saddr)#endif /*_SOCKET_*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -