⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f-b1.html

📁 WinSock编程规范及应用
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb_2312-80">
<META NAME="Generator" CONTENT="Microsoft Word 97">
<TITLE>附录B Windows Sockets头文件</TITLE>
</HEAD>
<BODY>

<B><FONT FACE="宋体" LANG="ZH-CN" SIZE=6><P><A NAME="_Toc336626934"><A NAME="_Toc336793017"><A NAME="_Toc336793493">附录</FONT><FONT SIZE=6>B Windows Sockets</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=6>头文件</A></A></A></P>
</B></FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=3><P ALIGN="JUSTIFY"> </P>
</FONT><B><FONT FACE="黑体" LANG="ZH-CN" SIZE=5><P><A NAME="_Toc336626935"><A NAME="_Toc336793018"><A NAME="_Toc336793494">附录</FONT><FONT FACE="Arial" SIZE=5>B.1 Windows Sockets 1.1</FONT><FONT FACE="黑体" LANG="ZH-CN" SIZE=5>头文件</A></A></A></P>
</B></FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=3><P ALIGN="JUSTIFY"></P>
</FONT><FONT SIZE=3><P ALIGN="JUSTIFY">/* WINSOCK.H</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=3>-</FONT><FONT SIZE=3>definitions to be used with the WINSOCK.DLL</P>
<P ALIGN="JUSTIFY"> *</P>
<P ALIGN="JUSTIFY"> * This header file corresponds to version 1.1 of the Windows Sockets specification.</P>
<P ALIGN="JUSTIFY"> *</P>
<P ALIGN="JUSTIFY"> * This file includes parts which are Copyright (c) 1982-1986 Regents</P>
<P ALIGN="JUSTIFY"> * of the University of California.  All rights reserved.  The</P>
<P ALIGN="JUSTIFY"> * Berkeley Software License Agreement specifies the terms and</P>
<P ALIGN="JUSTIFY"> * conditions for redistribution.</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">#ifndef _WINSOCKAPI_</P>
<P ALIGN="JUSTIFY">#define _WINSOCKAPI_</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * Pull in WINDOWS.H if necessary</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY">#ifndef _INC_WINDOWS</P>
<P ALIGN="JUSTIFY">#include &lt;windows.h&gt;</P>
<P ALIGN="JUSTIFY">#endif /* _INC_WINDOWS */</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * Basic system type definitions, taken from the BSD file sys/types.h.</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY">typedef unsigned char   u_char;</P>
<P ALIGN="JUSTIFY">typedef unsigned short  u_short;</P>
<P ALIGN="JUSTIFY">typedef unsigned int    u_int;</P>
<P ALIGN="JUSTIFY">typedef unsigned long   u_long;</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * The new type to be used in all</P>
<P ALIGN="JUSTIFY"> * instances which refer to sockets.</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY">typedef u_int           SOCKET;</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * Select uses arrays of SOCKETs.  These macros manipulate such</P>
<P ALIGN="JUSTIFY"> * arrays.  FD_SETSIZE may be defined by the user before including</P>
<P ALIGN="JUSTIFY"> * this file, but the default here should be &gt;= 64.</P>
<P ALIGN="JUSTIFY"> *</P>
<P ALIGN="JUSTIFY"> * CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE</P>
<P ALIGN="JUSTIFY"> * INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY">#ifndef FD_SETSIZE</P>
<P ALIGN="JUSTIFY">#define FD_SETSIZE      64</P>
<P ALIGN="JUSTIFY">#endif /* FD_SETSIZE */</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">typedef struct fd_set {</P>
<P ALIGN="JUSTIFY">        u_short fd_count;               /* how many are SET? */</P>
<P ALIGN="JUSTIFY">        SOCKET  fd_array[FD_SETSIZE];   /* an array of SOCKETs */</P>
</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=3><P ALIGN="JUSTIFY">}</FONT><FONT SIZE=3> fd_set;</P>
</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=3><P ALIGN="JUSTIFY"></P>
</FONT><FONT SIZE=3><P ALIGN="JUSTIFY">extern int PASCAL FAR __WSAFDIsSet(SOCKET, fd_set FAR *);</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">#define FD_CLR(fd, set) do { \</P>
<P ALIGN="JUSTIFY">    u_int __i; \</P>
<P ALIGN="JUSTIFY">    for (__i = 0; __i &lt; ((fd_set FAR *)(set))-&gt;fd_count ; __i++) { \</P>
<P ALIGN="JUSTIFY">        if (((fd_set FAR *)(set))-&gt;fd_array[__i] == fd) { \</P>
<P ALIGN="JUSTIFY">            while (__i &lt; ((fd_set FAR *)(set))-&gt;fd_count-1) { \</P>
<P ALIGN="JUSTIFY">                ((fd_set FAR *)(set))-&gt;fd_array[__i] = \</P>
<P ALIGN="JUSTIFY">                    ((fd_set FAR *)(set))-&gt;fd_array[__i+1]; \</P>
<P ALIGN="JUSTIFY">                __i++; \</P>
<P ALIGN="JUSTIFY">            } \</P>
<P ALIGN="JUSTIFY">            ((fd_set FAR *)(set))-&gt;fd_count</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=3>-</FONT><FONT SIZE=3>; \</P>
<P ALIGN="JUSTIFY">            break; \</P>
<P ALIGN="JUSTIFY">        } \</P>
<P ALIGN="JUSTIFY">    } \</P>
<P ALIGN="JUSTIFY">} while(0)</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">#define FD_SET(fd, set) do { \</P>
<P ALIGN="JUSTIFY">    if (((fd_set FAR *)(set))-&gt;fd_count &lt; FD_SETSIZE) \</P>
<P ALIGN="JUSTIFY">        ((fd_set FAR *)(set))-&gt;fd_array[((fd_set FAR *)(set))-&gt;fd_count++]=fd;\</P>
<P ALIGN="JUSTIFY">} while(0)</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">#define FD_ZERO(set) (((fd_set FAR *)(set))-&gt;fd_count=0)</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">#define FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)fd, (fd_set FAR *)set)</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * Structure used in select() call, taken from the BSD file sys/time.h.</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY">struct timeval {</P>
<P ALIGN="JUSTIFY">        long    tv_sec;         /* seconds */</P>
<P ALIGN="JUSTIFY">        long    tv_usec;        /* and microseconds */</P>
<P ALIGN="JUSTIFY">};</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * Operations on timevals.</P>
<P ALIGN="JUSTIFY"> *</P>
<P ALIGN="JUSTIFY"> * NB: timercmp does not work for &gt;= or &lt;=.</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY">#define timerisset(tvp)         ((tvp)-&gt;tv_sec || (tvp)-&gt;tv_usec)</P>
<P ALIGN="JUSTIFY">#define timercmp(tvp, uvp, cmp) \</P>
<P ALIGN="JUSTIFY">        ((tvp)-&gt;tv_sec cmp (uvp)-&gt;tv_sec || \</P>
<P ALIGN="JUSTIFY">         (tvp)-&gt;tv_sec == (uvp)-&gt;tv_sec &amp;&amp; (tvp)-&gt;tv_usec cmp (uvp)-&gt;tv_usec)</P>
<P ALIGN="JUSTIFY">#define timerclear(tvp)         (tvp)-&gt;tv_sec = (tvp)-&gt;tv_usec = 0</P>
</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=3><P ALIGN="JUSTIFY"></P>
</FONT><FONT SIZE=3><P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.</P>
<P ALIGN="JUSTIFY"> *</P>
<P ALIGN="JUSTIFY"> *</P>
<P ALIGN="JUSTIFY"> * Ioctl's have the command encoded in the lower word,</P>
<P ALIGN="JUSTIFY"> * and the size of any in or out parameters in the upper</P>
<P ALIGN="JUSTIFY"> * word.  The high 2 bits of the upper word are used</P>
<P ALIGN="JUSTIFY"> * to encode the in/out status of the parameter; for now</P>
<P ALIGN="JUSTIFY"> * we restrict parameters to at most 128 bytes.</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY">#define IOCPARM_MASK    0x7f            /* parameters must be &lt; 128 bytes */</P>
<P ALIGN="JUSTIFY">#define IOC_VOID        0x20000000      /* no parameters */</P>
<P ALIGN="JUSTIFY">#define IOC_OUT         0x40000000      /* copy out parameters */</P>
<P ALIGN="JUSTIFY">#define IOC_IN          0x80000000      /* copy in parameters */</P>
<P ALIGN="JUSTIFY">#define IOC_INOUT       (IOC_IN|IOC_OUT)</P>
<P ALIGN="JUSTIFY">                                        /* 0x20000000 distinguishes new &amp;</P>
<P ALIGN="JUSTIFY">                                           old ioctl's */</P>
<P ALIGN="JUSTIFY">#define _IO(x,y)        (IOC_VOID|(x&lt;&lt;8)|y)</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">#define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&amp;IOCPARM_MASK)&lt;&lt;16)|(x&lt;&lt;8)|y)</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">#define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&amp;IOCPARM_MASK)&lt;&lt;16)|(x&lt;&lt;8)|y)</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">#define FIONREAD    _IOR('f', 127, u_long) /* get # bytes to read */</P>
<P ALIGN="JUSTIFY">#define FIONBIO     _IOW('f', 126, u_long) /* set/clear non-blocking i/o */</P>
<P ALIGN="JUSTIFY">#define FIOASYNC    _IOW('f', 125, u_long) /* set/clear async i/o */</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/* Socket I/O Controls */</P>
<P ALIGN="JUSTIFY">#define SIOCSHIWAT  _IOW('s',  0, u_long)  /* set high watermark */</P>
<P ALIGN="JUSTIFY">#define SIOCGHIWAT  _IOR('s',  1, u_long)  /* get high watermark */</P>
<P ALIGN="JUSTIFY">#define SIOCSLOWAT  _IOW('s',  2, u_long)  /* set low watermark */</P>
<P ALIGN="JUSTIFY">#define SIOCGLOWAT  _IOR('s',  3, u_long)  /* get low watermark */</P>
<P ALIGN="JUSTIFY">#define SIOCATMARK  _IOR('s',  7, u_long)  /* at oob mark? */</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * Structures returned by network data base library, taken from the</P>
<P ALIGN="JUSTIFY"> * BSD file netdb.h.  All addresses are supplied in host order, and</P>
<P ALIGN="JUSTIFY"> * returned in network order (suitable for use in system calls).</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">struct  hostent {</P>
<P ALIGN="JUSTIFY">        char    FAR * h_name;           /* official name of host */</P>
<P ALIGN="JUSTIFY">        char    FAR * FAR * h_aliases;  /* alias list */</P>
<P ALIGN="JUSTIFY">        short   h_addrtype;             /* host address type */</P>
<P ALIGN="JUSTIFY">        short   h_length;               /* length of address */</P>
<P ALIGN="JUSTIFY">        char    FAR * FAR * h_addr_list; /* list of addresses */</P>
<P ALIGN="JUSTIFY">#define h_addr  h_addr_list[0]          /* address, for backward compat */</P>
<P ALIGN="JUSTIFY">};</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * It is assumed here that a network number</P>
<P ALIGN="JUSTIFY"> * fits in 32 bits.</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY">struct  netent {</P>
<P ALIGN="JUSTIFY">        char    FAR * n_name;           /* official name of net */</P>
<P ALIGN="JUSTIFY">        char    FAR * FAR * n_aliases;  /* alias list */</P>
<P ALIGN="JUSTIFY">        short   n_addrtype;             /* net address type */</P>
<P ALIGN="JUSTIFY">        u_long  n_net;                  /* network # */</P>
<P ALIGN="JUSTIFY">};</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">struct  servent {</P>
<P ALIGN="JUSTIFY">        char    FAR * s_name;           /* official service name */</P>
<P ALIGN="JUSTIFY">        char    FAR * FAR * s_aliases;  /* alias list */</P>
<P ALIGN="JUSTIFY">        short   s_port;                 /* port # */</P>
<P ALIGN="JUSTIFY">        char    FAR * s_proto;          /* protocol to use */</P>
<P ALIGN="JUSTIFY">};</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">struct  protoent {</P>
<P ALIGN="JUSTIFY">        char    FAR * p_name;           /* official protocol name */</P>
<P ALIGN="JUSTIFY">        char    FAR * FAR * p_aliases;  /* alias list */</P>
<P ALIGN="JUSTIFY">        short   p_proto;                /* protocol # */</P>
<P ALIGN="JUSTIFY">};</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * Constants and structures defined by the internet system,</P>
<P ALIGN="JUSTIFY"> * Per RFC 790, September 1981, taken from the BSD file netinet/in.h.</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * Protocols</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY">#define IPPROTO_IP              0               /* dummy for IP */</P>
<P ALIGN="JUSTIFY">#define IPPROTO_ICMP            1               /* control message protocol */</P>
<P ALIGN="JUSTIFY">#define IPPROTO_GGP             2               /* gateway^2 (deprecated) */</P>
<P ALIGN="JUSTIFY">#define IPPROTO_TCP             6               /* tcp */</P>
<P ALIGN="JUSTIFY">#define IPPROTO_PUP             12              /* pup */</P>
<P ALIGN="JUSTIFY">#define IPPROTO_UDP             17              /* user datagram protocol */</P>
<P ALIGN="JUSTIFY">#define IPPROTO_IDP             22              /* xns idp */</P>
<P ALIGN="JUSTIFY">#define IPPROTO_ND              77              /* UNOFFICIAL net disk proto */</P>
</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=3><P ALIGN="JUSTIFY"></P>
</FONT><FONT SIZE=3><P ALIGN="JUSTIFY">#define IPPROTO_RAW             255             /* raw IP packet */</P>
<P ALIGN="JUSTIFY">#define IPPROTO_MAX             256</P>
<P ALIGN="JUSTIFY"></P>
<P ALIGN="JUSTIFY">/*</P>
<P ALIGN="JUSTIFY"> * Port/socket numbers: network standard functions</P>
<P ALIGN="JUSTIFY"> */</P>
<P ALIGN="JUSTIFY">#define IPPORT_ECHO             7</P>
<P ALIGN="JUSTIFY">#define IPPORT_DISCARD          9</P>
<P ALIGN="JUSTIFY">#define IPPORT_SYSTAT           11</P>
<P ALIGN="JUSTIFY">#define IPPORT_DAYTIME          13</P>
<P ALIGN="JUSTIFY">#define IPPORT_NETSTAT          15</P>
<P ALIGN="JUSTIFY">#define IPPORT_FTP              21</P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -