附录 B Windows Sockets 头文件
附录 B.1 Windows Sockets 1.1 头文件
/* WINSOCK.H-definitions to be used with the WINSOCK.DLL
*
- This header file corresponds to version 1.1 of the Windows Sockets specification.
*
-
This file includes parts which are Copyright (c) 1982-1986 Regents
-
of the University of California. All rights reserved. The
-
Berkeley Software License Agreement specifies the terms and
-
conditions for redistribution.
*/
#ifndef _WINSOCKAPI_ #define _WINSOCKAPI_
/*
- Pull in WINDOWS.H if necessary
*/
#ifndef _INC_WINDOWS #include <windows.h> #endif /* _INC_WINDOWS */
/*
- Basic system type definitions, taken from the BSD file sys/types.h.
*/
typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned int u_int; typedef unsigned long u_long;
/*
-
The new type to be used in all
-
instances which refer to sockets.
*/
typedef u_int SOCKET;
/*
-
Select uses arrays of SOCKETs. These macros manipulate such
-
arrays. FD_SETSIZE may be defined by the user before including
-
this file, but the default here should be >= 64.
*
-
CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
-
INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
*/
#ifndef FD_SETSIZE
#define FD_SETSIZE 64
#endif /* FD_SETSIZE */
typedef struct fd_set {
u_short fd_count; /* how many are SET? */ SOCKET fd_array[FD_SETSIZE]; /* an array of SOCKETs */
} fd_set;
extern int PASCAL FAR WSAFDIsSet(SOCKET, fd_set FAR *); #define FD_CLR(fd, set) do { \
u_int i; \
for ( i = 0; i < ((fd_set FAR *)(set))->fd_count ; i++) { \
if (((fd_set FAR *)(set))->fd_array[ i] == fd) { \
while ( i < ((fd_set FAR *)(set))->fd_count-1) { \ ((fd_set FAR *)(set))->fd_array[ i] = \
((fd_set FAR *)(set))->fd_array[ i+1]; \
i++; \
} \
((fd_set FAR *)(set))->fd_count-; \ break; \
} \
} \
} while(0)
#define FD_SET(fd, set) do { \
if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))-
>fd_count++]=fd;\
} while(0)
#define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
#define FD_ISSET(fd, set) WSAFDIsSet((SOCKET)fd, (fd_set FAR *)set)
/*
- Structure used in select() call, taken from the BSD file sys/time.h.
*/
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
/*
- Operations on timevals.
*
- NB: timercmp does not work for >= or <=.
*/
#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) #define timercmp(tvp, uvp, cmp) \
((tvp)->tv_sec cmp (uvp)->tv_sec || \
(tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)-
>tv_usec)
#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
/*
- Commands for ioctlsocket(), taken from the BSD file fcntl.h.
*
*
-
Ioctl's have the command encoded in the lower word,
-
and the size of any in or out parameters in the upper
-
word. The high 2 bits of the upper word are used
-
to encode the in/out status of the parameter; for now
-
we restrict parameters to at most 128 bytes.
*/
#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 IOC_INOUT (IOC_IN|IOC_OUT)
/* 0x20000000 distinguishes
new &
old ioctl's */
#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 FIONREAD _IOR('f', 127, u_long) /* get # bytes to read */ #define FIONBIO _IOW('f', 126, u_long) /* set/clear non-blocking i/o
*/
#define FIOASYNC _IOW('f', 125, u_long) /* set/clear async i/o */
/* Socket I/O Controls */
#define |
SIOCSHIWAT |
_IOW('s', |
0, |
u_long) |
/* |
set |
high watermark */ |
---|---|---|---|---|---|---|---|
#define |
SIOCGHIWAT |
_IOR('s', |
1, |
u_long) |
/* |
get |
high watermark */ |
#define |
SIOCSLOWAT |
_IOW('s', |
2, |
u_long) |
/* |
set |
low watermark */ |
#define |
SIOCGLOWAT |
_IOR('s', |
3, |
u_long) |
/* |
get |
low watermark */ |
#define SIOCATMARK _IOR('s', 7, u_long) /* at oob mark? */
/*
-
Structures returned by network data base library, taken from the
-
BSD file netdb.h. All addresses are supplied in host order, and
-
returned in network order (suitable for use in system calls).
*/
struct hostent {
char FAR * h_name; /* official name of host */ char FAR * FAR * h_aliases; /* alias list */
short h_addrtype; /* host address type */
short h_length; /* length of address */ char FAR * FAR * h_addr_list; /* list of addresses */
#define h_addr h_addr_list[0] /* address, for backward compat
*/
};
/*
-
It is assumed here that a network number
-
fits in 32 bits.
*/
struct netent {
char FAR * n_name; /* official name of net */ char FAR * FAR * n_aliases; /* alias list */
short n_addrtype; /* net address type */
u_long n_net; /* network # */
};
struct servent {
char FAR * s_name; /* official service name */ char FAR * FAR * s_aliases; /* alias list */
short s_port; /* port # */
char FAR * s_proto; /* protocol to use */
};
struct |
protoent { char FAR * p_name; |
/* |
official protocol name */ |
---|---|---|---|
}; |
char FAR * FAR * p_aliases; short p_proto; |
/* /* |
alias list */ protocol # */ |
/*
-
Constants and structures defined by the internet system,
-
Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
*/
/*
- Protocols
*/
#define IPPROTO_IP |
0 |
/* |
dummy for IP */ |
---|---|---|---|
#define IPPROTO_ICMP |
1 |
/* |
control message |
protocol */ |
|||
#define IPPROTO_GGP |
2 |
/* |
gateway^2 |
(deprecated) */ |
|||
#define IPPROTO_TCP |
6 |
/* |
tcp */ |
#define IPPROTO_PUP |
12 |
/* |
pup */ |
#define IPPROTO_UDP |
17 |
/* |
user datagram |
protocol */ |
|||
#define IPPROTO_IDP |
22 |
/* |
xns idp */ |
#define IPPROTO_ND 77 /* UNOFFICIAL net disk proto */
#define IPPROTO_RAW 255 /* raw IP packet */ #define IPPROTO_MAX 256
/*
- Port/socket numbers: network standard functions
*/
#define IPPORT_ECHO 7
#define IPPORT_DISCARD 9
#define IPPORT_SYSTAT 11
#define IPPORT_DAYTIME 13
#define IPPORT_NETSTAT 15
#define IPPORT_FTP 21
#define IPPORT_TELNET 23
#define IPPORT_SMTP 25
#define IPPORT_TIMESERVER 37
#define IPPORT_NAMESERVER 42
#define IPPORT_WHOIS 43
#define IPPORT_MTP 57
/*
- Port/socket numbers: host specific functions
*/
#define |
IPPORT_TFTP |
69 |
||||
---|---|---|---|---|---|---|
#define |
IPPORT_RJE |
77 |
||||
#define |
IPPORT_FINGER |
79 |
||||
#define |
IPPORT_TTYLINK |
87 |
||||
#define |
IPPORT_SUPDUP |
95 |
||||
/* * UNIX */ #define |
TCP sockets IPPORT_EXECSERVER |
512 |
||||
#define |
IPPORT_LOGINSERVER |
513 |
||||
#define |
IPPORT_CMDSERVER |
514 |
||||
#define |
IPPORT_EFSSERVER |
520 |
||||
/* * UNIX */ #define |
UDP sockets IPPORT_BIFFUDP |
512 |
||||
#define |
IPPORT_WHOSERVER |
513 |
||||
#define |
IPPORT_ROUTESERVER |
520 |
/* 520+1 |
also |
used |
*/ |
/* |
-
Ports < IPPORT_RESERVED are reserved for
-
privileged processes (e.g. root).
*/
#define IPPORT_RESERVED 1024
/*
- Link numbers
*/
#define IMPLINK_IP 155
#define IMPLINK_LOWEXPER 156
#define IMPLINK_HIGHEXPER 158
/*
- Internet address (old style... should be updated)
*/
struct in_addr {
union {
} S_un;
struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b; struct { u_short s_w1,s_w2; } S_un_w;
u_long S_addr;
#define s_addr S_un.S_addr
/* can be used for most tcp & ip code */
#define s_host S_un.S_un_b.s_b2
#define #define |
s_net s_imp |
/* S_un.S_un_b.s_b1 /* S_un.S_un_w.s_w2 |
host on imp */ network */ |
---|---|---|---|
/* |
imp */ |
||
#define |
s_impno |
S_un.S_un_b.s_b4 |
|
/* |
imp # */ |
||
#define |
s_lh |
S_un.S_un_b.s_b3 |
|
/* |
logical host */ |
};
/*
-
Definitions of bits in internet address integers.
-
On subnets, the decomposition of addresses to host and net parts
-
is done according to subnet mask, not the masks here.
*/
#define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0) #define IN_CLASSA_NET 0xff000000
#define IN_CLASSA_NSHIFT 24
#define IN_CLASSA_HOST 0x00ffffff
#define IN_CLASSA_MAX 128
#define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
#define IN_CLASSB_NET 0xffff0000
#define IN_CLASSB_NSHIFT 16
#define IN_CLASSB_HOST 0x0000ffff
#define IN_CLASSB_MAX 65536
#define IN_CLASSC(i) (((long)(i) & 0xc0000000) == 0xc0000000)
#define IN_CLASSC_NET 0xffffff00
#define IN_CLASSC_NSHIFT 8
#define IN_CLASSC_HOST 0x000000ff
#define INADDR_ANY (u_long)0x00000000
#define INADDR_LOOPBACK 0x7f000001
#define INADDR_BROADCAST (u_long)0xffffffff #define INADDR_NONE 0xffffffff
/*
- Socket address, internet style.
*/
struct sockaddr_in {
short sin_family; u_short sin_port;
struct in_addr sin_addr; char sin_zero[8];
};
#define WSADESCRIPTION_LEN 256
#define WSASYS_STATUS_LEN 128
typedef struct WSAData {
WORD wVersion;
WORD wHighVersion;
char szDescription[WSADESCRIPTION_LEN+1];
char szSystemStatus[WSASYS_STATUS_LEN+1];
unsigned short iMaxSockets;
unsigned short iMaxUdpDg;
char FAR * lpVendorInfo;
} WSADATA;
typedef WSADATA FAR *LPWSADATA;
/*
- Options for use with [gs]etsockopt at the IP level.
*/
#define IP_OPTIONS 1 /* set/get IP per-packet options */
/*
-
Definitions related to sockets: types, address families, options,
-
taken from the BSD file sys/socket.h.
*/
/*
-
This is used instead of -1, since the
-
SOCKET type is unsigned.
*/
#define INVALID_SOCKET (SOCKET)(~0)
#define SOCKET_ERROR (-1)
/*
- Types
*/
#define |
SOCK_STREAM |
1 |
/* |
stream socket */ |
---|---|---|---|---|
#define |
SOCK_DGRAM |
2 |
/* |
datagram socket */ |
#define |
SOCK_RAW |
3 |
/* |
raw-protocol interface */ |
#define |
SOCK_RDM |
4 |
/* |
reliably-delivered message |
*/ #define |
SOCK_SEQPACKET |
5 |
/* |
sequenced packet stream */ |
/*
- Option flags per-socket.
*/
#define SO_DEBUG recording */ |
0x0001 |
/* |
turn on debugging info |
---|---|---|---|
#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 (u_int)(~SO_LINGER)
/*
- 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 */ |
|
/* * TCP options. */ #define TCP_NODELAY |
0x0001 |
/*
- Address families.
*/
#define |
AF_UNSPEC |
0 |
/* unspecified */ |
---|---|---|---|
#define |
AF_UNIX |
1 |
/* local to host (pipes, portals) |
*/ |
|||
#define |
AF_INET |
2 |
/* internetwork: UDP, TCP, etc. |
*/ |
|||
#define |
AF_IMPLINK |
3 |
/* arpanet imp addresses */ |
#define |
AF_PUP |
4 |
/* pup protocols: e.g. BSP */ |
#define |
AF_CHAOS |
5 |
/* mit CHAOS protocols */ |
#define |
AF_NS |
6 |
/* |
XEROX NS protocols */ |
---|---|---|---|---|
#define |
AF_ISO |
7 |
/* |
ISO protocols */ |
#define |
AF_OSI |
AF_ISO |
/* |
OSI is ISO */ |
#define |
AF_ECMA |
8 |
/* |
european computer |
manufacturers */ |
||||
#define |
AF_DATAKIT |
9 |
/* |
datakit protocols */ |
#define |
AF_CCITT |
10 |
/* CCITT protocols, X.25 etc */ |
|
#define |
AF_SNA |
11 |
/* IBM SNA */ |
|
#define |
AF_DECnet |
12 |
/* DECnet */ |
|
#define |
AF_DLI |
13 |
/* Direct data link interface */ |
|
#define |
AF_LAT |
14 |
/* LAT */ |
|
#define |
AF_HYLINK |
15 |
/* NSC Hyperchannel */ |
|
#define |
AF_APPLETALK |
16 |
/* AppleTalk */ |
|
#define |
AF_NETBIOS |
17 |
/* NetBios-style addresses */ |
|
#define |
AF_MAX |
18 |
/*
-
Structure used by kernel to store most
-
addresses.
*/
struct sockaddr {
u_short sa_family; /* address family */
char sa_data[14]; /* up to 14 bytes of direct address */
};
/*
-
Structure used by kernel to pass protocol
-
information in raw sockets.
*/
struct sockproto {
u_short sp_family; /* address family */
u_short sp_protocol; /* protocol */
};
/*
- Protocol families, same as address families for now.
*/
#define |
PF_UNSPEC |
AF_UNSPEC |
---|---|---|
#define |
PF_UNIX |
AF_UNIX |
#define |
PF_INET |
AF_INET |
#define |
PF_IMPLINK |
AF_IMPLINK |
#define |
PF_PUP |
AF_PUP |
#define |
PF_CHAOS |
AF_CHAOS |
#define |
PF_NS |
AF_NS |
#define |
PF_ISO |
AF_ISO |
#define |
PF_OSI |
AF_OSI |
#define |
PF_ECMA |
AF_ECMA |
#define |
PF_DATAKIT |
AF_DATAKIT |
#define |
PF_CCITT |
AF_CCITT |
#define |
PF_SNA |
AF_SNA |
#define |
PF_DECnet |
AF_DECnet |
#define |
PF_DLI |
AF_DLI |
#define |
PF_LAT |
AF_LAT |
#define |
PF_HYLINK |
AF_HYLINK |
#define |
PF_APPLETALK |
AF_APPLETALK |
#define |
PF_MAX |
AF_MAX |
/*
- Structure used for manipulating linger option.
*/
struct linger {
u_short l_onoff; /* option on/off */
u_short l_linger; /* linger time */
};
/*
- Level number for (get/set)sockopt() to apply to socket itself.
*/
#define SOL_SOCKET 0xffff /* options for socket level */
/*
- Maximum queue length specifiable by listen.
*/
#define |
SOMAXCONN |
5 |
|
---|---|---|---|
#define |
MSG_OOB |
0x1 |
/* process out-of-band data */ |
#define |
MSG_PEEK |
0x2 |
/* peek at incoming message */ |
#define |
MSG_DONTROUTE |
0x4 |
/* send without using routing |
tables */
#define MSG_MAXIOVLEN 16
/*
- Define constant based on rfc883, used by gethostbyxxxx() calls.
*/
#define MAXGETHOSTSTRUCT 1024
/*
- Define flags to be used with the WSAAsyncSelect() call.
*/
#define FD_READ 0x01
#define FD_WRITE 0x02
#define FD_OOB 0x04
#define FD_ACCEPT 0x08
#define FD_CONNECT 0x10
#define FD_CLOSE 0x20
/*
-
All Windows Sockets error constants are biased by WSABASEERR from
-
the "normal"
*/
#define WSABASEERR 10000
/*
- Windows Sockets definitions of regular Microsoft C error constants
*/
#define WSAEINTR (WSABASEERR+4)
#define WSAEBADF (WSABASEERR+9)
#define WSAEACCES (WSABASEERR+13)
#define WSAEFAULT (WSABASEERR+14)
#define WSAEINVAL (WSABASEERR+22)
#define WSAEMFILE (WSABASEERR+24)
/*
- Windows Sockets definitions of regular Berkeley error constants
*/
#define WSAEWOULDBLOCK (WSABASEERR+35)
#define WSAEINPROGRESS (WSABASEERR+36)
#define WSAEALREADY (WSABASEERR+37)
#define WSAENOTSOCK (WSABASEERR+38) #define WSAEDESTADDRREQ (WSABASEERR+39) #define WSAEMSGSIZE (WSABASEERR+40)
#define WSAEPROTOTYPE (WSABASEERR+41)
#define WSAENOPROTOOPT (WSABASEERR+42) #define WSAEPROTONOSUPPORT (WSABASEERR+43) #define WSAESOCKTNOSUPPORT (WSABASEERR+44) #define WSAEOPNOTSUPP (WSABASEERR+45) #define WSAEPFNOSUPPORT (WSABASEERR+46) #define WSAEAFNOSUPPORT (WSABASEERR+47) #define WSAEADDRINUSE (WSABASEERR+48) #define WSAEADDRNOTAVAIL (WSABASEERR+49) #define WSAENETDOWN (WSABASEERR+50)
#define WSAENETUNREACH (WSABASEERR+51)
#define WSAENETRESET (WSABASEERR+52) #define WSAECONNABORTED (WSABASEERR+53) #define WSAECONNRESET (WSABASEERR+54)
#define WSAENOBUFS (WSABASEERR+55)
#define WSAEISCONN (WSABASEERR+56)
#define WSAENOTCONN (WSABASEERR+57)
#define WSAESHUTDOWN (WSABASEERR+58) #define WSAETOOMANYREFS (WSABASEERR+59) #define WSAETIMEDOUT (WSABASEERR+60) #define WSAECONNREFUSED (WSABASEERR+61) #define WSAELOOP (WSABASEERR+62) #define WSAENAMETOOLONG (WSABASEERR+63) #define WSAEHOSTDOWN (WSABASEERR+64) #define WSAEHOSTUNREACH (WSABASEERR+65) #define WSAENOTEMPTY (WSABASEERR+66)
#define WSAEPROCLIM (WSABASEERR+67)
#define WSAEUSERS (WSABASEERR+68)
#define WSAEDQUOT (WSABASEERR+69)
#define WSAESTALE (WSABASEERR+70)
#define WSAEREMOTE (WSABASEERR+71)
/*
- Extended Windows Sockets error constant definitions
*/
#define WSASYSNOTREADY (WSABASEERR+91) #define WSAVERNOTSUPPORTED (WSABASEERR+92) #define WSANOTINITIALISED (WSABASEERR+93)
/*
-
Error return codes from gethostbyname() and gethostbyaddr()
-
(when using the resolver). Note that these errors are
-
retrieved via WSAGetLastError() and must therefore follow
-
the rules for avoiding clashes with error numbers from
-
specific implementations or language run-time systems.
-
For this reason the codes are based at WSABASEERR+1001.
-
Note also that [WSA]NO_ADDRESS is defined only for
-
compatibility purposes.
*/
#define h_errno WSAGetLastError()
/* Authoritative Answer: Host not found */ #define WSAHOST_NOT_FOUND (WSABASEERR+1001) #define HOST_NOT_FOUND WSAHOST_NOT_FOUND
/* Non-Authoritative: Host not found, or SERVERFAIL */ #define WSATRY_AGAIN (WSABASEERR+1002)
#define TRY_AGAIN WSATRY_AGAIN
/* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ #define WSANO_RECOVERY (WSABASEERR+1003)
#define NO_RECOVERY WSANO_RECOVERY
/* Valid name, no data record of requested type */ #define WSANO_DATA (WSABASEERR+1004)
#define NO_DATA WSANO_DATA
/* no address, look for MX record */ #define WSANO_ADDRESS WSANO_DATA
#define NO_ADDRESS WSANO_ADDRESS
/*
- Windows Sockets errors redefined as regular Berkeley error constants
*/
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEINPROGRESS
#define EALREADY WSAEALREADY
#define ENOTSOCK WSAENOTSOCK
#define EDESTADDRREQ WSAEDESTADDRREQ
#define EMSGSIZE WSAEMSGSIZE
#define EPROTOTYPE WSAEPROTOTYPE
#define ENOPROTOOPT WSAENOPROTOOPT #define EPROTONOSUPPORT WSAEPROTONOSUPPORT #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT #define EOPNOTSUPP WSAEOPNOTSUPP
#define EPFNOSUPPORT WSAEPFNOSUPPORT
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#define EADDRINUSE WSAEADDRINUSE
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
#define ENETDOWN WSAENETDOWN
#define ENETUNREACH WSAENETUNREACH
#define ENETRESET WSAENETRESET
#define ECONNABORTED WSAECONNABORTED
#define ECONNRESET WSAECONNRESET
#define ENOBUFS WSAENOBUFS
#define EISCONN WSAEISCONN
#define ENOTCONN WSAENOTCONN
#define ESHUTDOWN WSAESHUTDOWN
#define ETOOMANYREFS WSAETOOMANYREFS
#define ETIMEDOUT WSAETIMEDOUT
#define ECONNREFUSED WSAECONNREFUSED
#define ELOOP WSAELOOP
#define ENAMETOOLONG WSAENAMETOOLONG
#define EHOSTDOWN WSAEHOSTDOWN
#define EHOSTUNREACH WSAEHOSTUNREACH
#define ENOTEMPTY WSAENOTEMPTY
#define EPROCLIM WSAEPROCLIM
#define EUSERS WSAEUSERS
#define EDQUOT WSAEDQUOT
#define ESTALE WSAESTALE
#define EREMOTE WSAEREMOTE
/* Socket function prototypes */ #ifdef cplusplus
extern "C" { #endif
SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR *addr,
int FAR *addrlen);
int PASCAL FAR bind (SOCKET s, const struct sockaddr FAR *addr, int namelen);
int PASCAL FAR closesocket (SOCKET s);
int PASCAL FAR connect (SOCKET s, const struct sockaddr FAR *name, int namelen);
int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR *argp); int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR *name,
int FAR * namelen);
int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR *name,
int FAR * namelen);
int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
char FAR * optval, int FAR *optlen); u_long PASCAL FAR htonl (u_long hostlong);
u_short PASCAL FAR htons (u_short hostshort);
unsigned long PASCAL FAR inet_addr (const char FAR * cp); char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
int PASCAL FAR listen (SOCKET s, int backlog); u_long PASCAL FAR ntohl (u_long netlong); u_short PASCAL FAR ntohs (u_short netshort);
int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
struct sockaddr FAR *from, int FAR * fromlen);
int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR
*writefds,
fd_set FAR *exceptfds, const struct timeval FAR
*timeout);
int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
const struct sockaddr FAR *to, int tolen);
int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
const char FAR * optval, int optlen); int PASCAL FAR shutdown (SOCKET s, int how);
SOCKET PASCAL FAR socket (int af, int type, int protocol);
/* Database function prototypes */
struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr,
int len, int type); struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name); int PASCAL FAR gethostname (char FAR * name, int namelen);
struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR
* proto);
struct servent FAR * PASCAL FAR getservbyname(const char FAR * name,
const char FAR * proto); struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
/* Microsoft Windows Extension function prototypes */
int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData); int PASCAL FAR WSACleanup(void);
void PASCAL FAR WSASetLastError(int iError); int PASCAL FAR WSAGetLastError(void);
BOOL PASCAL FAR WSAIsBlocking(void);
int PASCAL FAR WSAUnhookBlockingHook(void);
FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc); int PASCAL FAR WSACancelBlockingCall(void);
HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
const char FAR * name, const char FAR * proto,
char FAR * buf, int buflen);
HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
const char FAR * proto, char FAR
* buf,
int buflen);
HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
const char FAR * name, char FAR
* buf,
int buflen);
HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
int number, char FAR * buf, int buflen);
HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
const char FAR * name, char FAR
* buf,
int buflen);
HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
const char FAR * addr, int len,
int type, buflen);
const char FAR * buf, int
int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
long lEvent);
#ifdef cplusplus
}
#endif
/* Microsoft Windows Extended data types */ typedef struct sockaddr SOCKADDR;
typedef struct sockaddr *PSOCKADDR;
typedef struct sockaddr FAR *LPSOCKADDR;
typedef struct sockaddr_in SOCKADDR_IN; typedef struct sockaddr_in *PSOCKADDR_IN; typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
typedef struct linger LINGER; typedef struct linger *PLINGER; typedef struct linger FAR *LPLINGER;
typedef struct in_addr IN_ADDR; typedef struct in_addr *PIN_ADDR; typedef struct in_addr FAR *LPIN_ADDR;
typedef struct fd_set FD_SET; typedef struct fd_set *PFD_SET; typedef struct fd_set FAR *LPFD_SET;
typedef struct hostent HOSTENT; typedef struct hostent *PHOSTENT; typedef struct hostent FAR *LPHOSTENT;
typedef struct servent SERVENT; typedef struct servent *PSERVENT; typedef struct servent FAR *LPSERVENT;
typedef struct protoent PROTOENT; typedef struct protoent *PPROTOENT; typedef struct protoent FAR *LPPROTOENT;
typedef struct timeval TIMEVAL; typedef struct timeval *PTIMEVAL; typedef struct timeval FAR *LPTIMEVAL;
/*
-
Windows message parameter composition and decomposition
-
macros.
*
-
WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
-
when constructing the response to a WSAAsyncGetXByY() routine.
*/
#define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
/*
-
WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
-
when constructing the response to WSAAsyncSelect().
*/
#define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
/*
-
WSAGETASYNCBUFLEN is intended for use by the Windows Sockets application
-
to extract the buffer length from the lParam in the response
-
to a WSAGetXByY().
*/
#define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
/*
-
WSAGETASYNCERROR is intended for use by the Windows Sockets
application
-
to extract the error code from the lParam in the response
-
to a WSAGetXByY().
*/
#define WSAGETASYNCERROR(lParam) HIWORD(lParam)
/*
-
WSAGETSELECTEVENT is intended for use by the Windows Sockets application
-
to extract the event code from the lParam in the response
-
to a WSAAsyncSelect().
*/
#define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
/*
-
WSAGETSELECTERROR is intended for use by the Windows Sockets application
-
to extract the error code from the lParam in the response
-
to a WSAAsyncSelect().
*/
#define WSAGETSELECTERROR(lParam) HIWORD(lParam)
#endif /* _WINSOCKAPI_ */
附录 B.2 Windows Sockets 2 头文件
/* Winsock2.h-definitions to be used with the WinSock 2.0 DLL and
- WinSock 2.0 applications.
*
- This header file corresponds to version 2.0 of the WinSock specification.
*
-
This file includes parts which are Copyright (c) 1982- 1986 Regents
-
of the University of California. All rights reserved. The
-
Berkeley Software License Agreement specifies the terms and
-
conditions for redistribution.
*/
#ifndef _WINSOCK2API_ #define _WINSOCK2API_
/*
- Pull in WINDOWS.H if necessary
*/
#ifndef _INC_WINDOWS #include <windows.h> #endif /* _INC_WINDOWS */
/*
- Basic system type definitions, taken from the BSD file sys/types.h.
*/
typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned int u_int; typedef unsigned long u_long;
/*
-
The new type to be used in all
-
instances which refer to sockets.
*/
typedef u_int SOCKET;
/*
-
Select uses arrays of SOCKETs. These macros manipulate such
-
arrays. FD_SETSIZE may be defined by the user before including
-
this file, but the default here should be >= 64.
*
-
CAVEAT IMPLEMENTOR and USER: THESE MACROS AND TYPES MUST BE
-
INCLUDED IN WINSOCK.H EXACTLY AS SHOWN HERE.
*/
#ifndef FD_SETSIZE
#define FD_SETSIZE 64
#endif /* FD_SETSIZE */
typedef struct fd_set {
u_short fd_count; /* how many are SET?
*/
SOCKET fd_array[FD_SETSIZE]; /* an array of
SOCKETs */
} fd_set;
extern int PASCAL FAR WSAFDIsSet(SOCKET, fd_set FAR *); #define FD_CLR(fd, set) do { \
u_int i; \
for ( i = 0; i < ((fd_set FAR *)(set))->fd_count ;
i++) { \
if (((fd_set FAR *)(set))->fd_array[ i] == fd) { \ while ( i < ((fd_set FAR *)(set))->fd_count-1)
{ \
((fd_set FAR *)(set))->fd_array[ i] = \
((fd_set FAR *)(set))->fd_array[ i+1];
\
i++; \
} \
((fd_set FAR *)(set))->fd_count-; \ break; \
} \
} \
} while(0)
#define FD_SET(fd, set) do { \
if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
((fd_set FAR *)(set))->fd_array[((fd_set FAR
*)(set))->fd_count++]=fd;\
} while(0)
#define FD_ZERO(set) (((fd_set FAR *)(set))->fd_count=0)
#define FD_ISSET(fd, set) WSAFDIsSet((SOCKET)fd, (fd_set FAR *)set)
/*
- Structure used in select() call, taken from the BSD file sys/time.h.
*/
struct timeval {
long |
tv_sec; |
/* seconds */ |
---|---|---|
long |
tv_usec; |
/* and microseconds */ |
};
/*
- Operations on timevals.
*
- NB: timercmp does not work for >= or <=.
*/
#define timerisset(tvp) ((tvp)->tv_sec || (tvp)-
>tv_usec)
#define timercmp(tvp, uvp, cmp) \
((tvp)->tv_sec cmp (uvp)->tv_sec || \
(tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
#define timerclear(tvp) (tvp)->tv_sec = (tvp)-
>tv_usec = 0
/*
- Commands for ioctlsocket(), taken from the BSD file fcntl.h.
*
*
-
Ioctl's have the command encoded in the lower word,
-
and the size of any in or out parameters in the upper
-
word. The high 2 bits of the upper word are used
-
to encode the in/out status of the parameter; for now
-
we restrict parameters to at most 128 bytes.
*/
#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 IOC_INOUT (IOC_IN|IOC_OUT)
/* 0x20000000
distinguishes new &
old ioctl's */
#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 FIONREAD _IOR('f', 127, u_long) /* get # bytes to read */
#define FIONBIO _IOW('f', 126, u_long) /* set/clear non- blocking i/o */
#define FIOASYNC _IOW('f', 125, u_long) /* set/clear async i/o */
/* Socket I/O Controls */
#define SIOCSHIWAT watermark */ |
_IOW('s', |
0, |
u_long) |
/* |
set |
high |
---|---|---|---|---|---|---|
#define SIOCGHIWAT |
_IOR('s', |
1, |
u_long) |
/* |
get |
high |
watermark */ |
||||||
#define SIOCSLOWAT |
_IOW('s', |
2, |
u_long) |
/* |
set |
low |
watermark */ |
||||||
#define SIOCGLOWAT |
_IOR('s', |
3, |
u_long) |
/* |
get |
low |
watermark */ |
||||||
#define SIOCATMARK |
_IOR('s', |
7, |
u_long) |
/* |
at oob mark? |
|
*/ |
/*
-
Structures returned by network data base library, taken from the
-
BSD file netdb.h. All addresses are supplied in host order, and
-
returned in network order (suitable for use in system calls).
*/
struct hostent {
char FAR * h_name; /* official name of
host */
char |
FAR * FAR * |
h_aliases; |
/* |
alias list */ |
---|---|---|---|---|
short |
h_addrtype; | /* |
host address type |
*/
short h_length; /* length of address
*/
char FAR * FAR * h_addr_list; /* list of
addresses */
#define h_addr h_addr_list[0] /* address, for backward compat */
};
/*
-
It is assumed here that a network number
-
fits in 32 bits.
*/
struct netent {
char FAR * n_name; /* official name of
net */
*/
};
char FAR * FAR * n_aliases; /* alias list */ short n_addrtype; /* net address type
u_long n_net; /* network # */
struct servent {
char FAR * s_name; /* official service
name */
*/
};
char FAR * FAR * s_aliases; /* alias list */ short s_port; /* port # */
char FAR * s_proto; /* protocol to use
struct protoent {
char FAR * p_name; /* official protocol
name */
};
char FAR * FAR * p_aliases; /* alias list */ short p_proto; /* protocol # */
/*
-
Constants and structures defined by the internet system,
-
Per RFC 790, September 1981, taken from the BSD file netinet/in.h.
*/
/*
- Protocols
*/
#define IP */ |
IPPROTO_IP |
0 |
/* |
dummy for |
---|---|---|---|---|
#define |
IPPROTO_ICMP |
1 |
/* |
control |
message |
protocol */ |
|||
#define |
IPPROTO_IGMP |
2 |
/* |
internet |
group management protocol */
#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */
#define IPPROTO_TCP 6 /* tcp */
#define IPPROTO_PUP 12 /* pup */
#define IPPROTO_UDP 17 /* user datagram protocol */
#define IPPROTO_IDP 22 /* xns idp
*/
#define IPPROTO_ND 77 /* UNOFFICIAL net disk proto */
#define IPPROTO_RAW 255 /* raw IP packet */
#define IPPROTO_MAX 256
/*
- Port/socket numbers: network standard functions
*/
#define IPPORT_ECHO 7
#define IPPORT_DISCARD 9
#define IPPORT_SYSTAT 11
#define IPPORT_DAYTIME 13
#define IPPORT_NETSTAT 15
#define IPPORT_FTP 21
#define IPPORT_TELNET 23
#define IPPORT_SMTP 25
#define IPPORT_TIMESERVER 37
#define IPPORT_NAMESERVER 42
#define IPPORT_WHOIS 43
#define IPPORT_MTP 57
/*
- Port/socket numbers: host specific functions
*/
#define IPPORT_TFTP 69
#define IPPORT_RJE 77
#define IPPORT_FINGER 79
#define IPPORT_TTYLINK 87
#define IPPORT_SUPDUP 95
/*
- UNIX TCP sockets
*/
#define IPPORT_EXECSERVER 512
#define IPPORT_LOGINSERVER 513
#define IPPORT_CMDSERVER 514
#define IPPORT_EFSSERVER 520
/*
- UNIX UDP sockets
*/
#define IPPORT_BIFFUDP 512
#define IPPORT_WHOSERVER 513
#define IPPORT_ROUTESERVER 520
*/
/* 520+1 also used
/*
-
Ports < IPPORT_RESERVED are reserved for
-
privileged processes (e.g. root).
*/
#define IPPORT_RESERVED 1024
/*
- Link numbers
*/
#define IMPLINK_IP 155
#define IMPLINK_LOWEXPER 156
#define IMPLINK_HIGHEXPER 158
/*
- Internet address (old style... should be updated)
*/
struct in_addr {
union {
S_un_b;
} S_un;
struct { u_char s_b1,s_b2,s_b3,s_b4; }
struct { u_short s_w1,s_w2; } S_un_w; u_long S_addr;
#define s_addr S_un.S_addr
& ip code */
/* can be used for most tcp
#define s_host S_un.S_un_b.s_b2
/* host on imp */
#define s_net S_un.S_un_b.s_b1
/* network */
#define s_imp S_un.S_un_w.s_w2
/* imp */
#define s_impno S_un.S_un_b.s_b4
/* imp # */
#define s_lh S_un.S_un_b.s_b3
/* logical host */
};
/*
-
Definitions of bits in internet address integers.
-
On subnets, the decomposition of addresses to host and net parts
-
is done according to subnet mask, not the masks here.
*/
#define IN_CLASSA(i) (((long)(i) & 0x80000000) == 0)
#define IN_CLASSA_NET 0xff000000
#define IN_CLASSA_NSHIFT 24
#define IN_CLASSA_HOST 0x00ffffff
#define IN_CLASSA_MAX 128
#define IN_CLASSB(i) (((long)(i) & 0xc0000000) == 0x80000000)
#define IN_CLASSB_NET 0xffff0000
#define IN_CLASSB_NSHIFT 16
#define IN_CLASSB_HOST 0x0000ffff
#define IN_CLASSB_MAX 65536
#define IN_CLASSC(i) (((long)(i) & 0xc0000000) == 0xc0000000)
#define IN_CLASSC_NET 0xffffff00
#define IN_CLASSC_NSHIFT 8
#define IN_CLASSC_HOST 0x000000ff
#define INADDR_ANY (u_long)0x00000000
#define INADDR_LOOPBACK 0x7f000001
#define INADDR_BROADCAST (u_long)0xffffffff #define INADDR_NONE 0xffffffff
/*
- Socket address, internet style.
*/
struct sockaddr_in {
short sin_family; u_short sin_port;
struct in_addr sin_addr; char sin_zero[8];
};
#define WSADESCRIPTION_LEN 256
#define WSASYS_STATUS_LEN 128
typedef struct WSAData {
WORD wVersion;
WORD wHighVersion;
char szDescription[WSADESCRIPTION_LEN+1];
char szSystemStatus[WSASYS_STATUS_LEN+1];
unsigned short iMaxSockets;
unsigned short iMaxUdpDg;
char FAR * lpVendorInfo;
} WSADATA, FAR * LPWSADATA; typedef WSADATA FAR *LPWSADATA;
#if !defined(MAKEWORD)
#define MAKEWORD(low,high) \
((WORD)((BYTE)(low)) | (((WORD)(BYTE)(high))<<8)))
#endif
/*
- Options for use with [gs]etsockopt at the IP level.
*/
#define IP_OPTIONS 1 /* set/get IP per- packet options */
/*
-
Definitions related to sockets: types, address families, options,
-
taken from the BSD file sys/socket.h.
*/
/*
-
This is used instead of -1, since the
-
SOCKET type is unsigned.
*/
#define INVALID_SOCKET (SOCKET)(~0)
#define SOCKET_ERROR (-1)
/*
- Types
*/
#define SOCK_STREAM 1 /* stream socket */
#define SOCK_DGRAM */ |
2 |
/* |
datagram socket |
|
---|---|---|---|---|
#define SOCK_RAW |
3 |
/* |
raw-protocol |
|
interface */ |
||||
#define SOCK_RDM |
4 |
/* |
reliably- |
|
delivered message |
*/ |
#define SOCK_SEQPACKET 5 /* sequenced packet stream */
/*
- Option flags per-socket.
*/
#define SO_DEBUG info recording */ |
0x0001 |
/* |
turn on debugging |
---|---|---|---|
#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 (int)(~SO_LINGER)
/*
- Additional options.
*/
#define SO_SNDBUF 0x1001 /* send buffer size
*/
#define size */ |
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_ERROR |
0x1007 |
/* |
get error status |
and clear */
#define SO_TYPE 0x1008 /* get socket type
*/
/*
- WinSock 2.0 extension - new options
*/
#define SO_GROUP_ID 0x2001 /* ID of a socket group */
#define SO_GROUP_PRIORITY 0x2002 /* the relative priority within a group */
#define SO_MAX_MSG_SIZE 0x2003 /* maximum message size */
#define SO_PROTOCOL_INFO 0x2004 /* PROTOCOL_INFO
structure */
#define PVD_CONFIG 0x3001 /* configuration info for service provider */
/*
- TCP options.
*/
#define TCP_NODELAY 0x0001
/*
- Address families.
*/
#define AF_UNSPEC |
0 |
/* unspecified */ |
---|---|---|
#define AF_UNIX |
1 |
/* local to host |
(pipes, portals) */ #define AF_INET |
2 |
/* |
internetwork: |
|
---|---|---|---|---|
UDP, TCP, etc. */ |
||||
#define AF_IMPLINK |
3 |
/* |
arpanet imp |
|
addresses */ |
||||
#define AF_PUP |
4 |
/* |
pup protocols: |
|
e.g. BSP */ |
||||
#define AF_CHAOS |
5 |
/* |
mit CHAOS |
|
protocols */ |
||||
#define AF_NS |
6 |
/* |
XEROX NS |
|
protocols */ |
||||
#define AF_IPX |
AF_NS |
/* |
IPX protocols: |
|
IPX, SPX, etc. */ |
||||
#define AF_ISO |
7 |
/* |
ISO protocols */ |
|
#define AF_OSI |
AF_ISO |
/* |
OSI is ISO */ |
|
#define AF_ECMA |
8 |
/* |
european computer |
|
manufacturers */ |
||||
#define AF_DATAKIT |
9 |
/* |
datakit protocols |
|
*/ |
||||
#define AF_CCITT |
10 |
/* |
CCITT protocols, |
|
X.25 etc */ |
||||
#define AF_SNA |
11 |
/* |
IBM SNA */ |
|
#define AF_DECnet |
12 |
/* |
DECnet */ |
|
#define AF_DLI |
13 |
/* |
Direct data link |
|
interface */ |
||||
#define |
AF_LAT |
14 |
/* |
LAT */ |
#define |
AF_HYLINK |
15 |
/* |
NSC Hyperchannel |
*/ |
||||
#define |
AF_APPLETALK |
16 |
/* |
AppleTalk */ |
#define |
AF_NETBIOS |
17 |
/* |
NetBios-style |
addresses */ |
||||
#define |
AF_FIREFOX |
18 |
/* |
Protocols from |
Firefox |
*/ |
|||
#define |
AF_VOICEVIEW |
19 |
/* |
VoiceView */ |
#define /* |
AF_MAX |
20 |
-
Structure used by kernel to store most
-
addresses.
*/
struct sockaddr {
u_short sa_family; /* address family */
char sa_data[14]; /* up to 14 bytes of direct address */
};
/*
-
Structure used by kernel to pass protocol
-
information in raw sockets.
*/
struct sockproto {
u_short sp_family; /* address family */
u_short sp_protocol; /* protocol */
};
/*
- Protocol families, same as address families for now.
*/
#define |
PF_UNSPEC |
AF_UNSPEC |
---|---|---|
#define |
PF_UNIX |
AF_UNIX |
#define |
PF_INET |
AF_INET |
#define |
PF_IMPLINK |
AF_IMPLINK |
#define |
PF_PUP |
AF_PUP |
#define |
PF_CHAOS |
AF_CHAOS |
#define |
PF_NS |
AF_NS |
#define |
PF_IPX |
AF_IPX |
#define |
PF_ISO |
AF_ISO |
#define |
PF_OSI |
AF_OSI |
#define |
PF_ECMA |
AF_ECMA |
#define |
PF_DATAKIT |
AF_DATAKIT |
#define |
PF_CCITT |
AF_CCITT |
#define |
PF_SNA |
AF_SNA |
#define |
PF_DECnet |
AF_DECnet |
#define |
PF_DLI |
AF_DLI |
#define |
PF_LAT |
AF_LAT |
#define PF_HYLINK AF_HYLINK #define PF_APPLETALK AF_APPLETALK #define PF_FIREFOX AF_FIREFOX #define PF_VOICEVIEW AF_VOICEVIEW
#define PF_MAX AF_MAX
/*
- Structure used for manipulating linger option.
*/
struct linger {
u_short l_onoff; /* option on/off */
u_short l_linger; /* linger time */
};
/*
- Level number for (get/set)sockopt() to apply to socket itself.
*/
#define SOL_SOCKET 0xffff /* options for socket level */
/*
- Maximum queue length specifiable by listen.
*/
#define SOMAXCONN 5
#define MSG_OOB 0x1 /* process out-of- band data */
#define MSG_PEEK 0x2 /* peek at incoming message */
#define MSG_DONTROUTE 0x4 /* send without using routing tables */
#define MSG_MAXIOVLEN 16
/*
- Define constant based on rfc883, used by gethostbyxxxx()
calls.
*/
#define MAXGETHOSTSTRUCT 1024
/*
- Define flags to be used with the WSAAsyncSelect() and WSAEventSelect() call.
*/
#define FD_READ 0x01
#define FD_WRITE 0x02
#define FD_OOB 0x04
#define FD_ACCEPT 0x08
#define FD_CONNECT 0x10
#define FD_CLOSE 0x20
/*
- WinSock 2.0 extension - new flags for WSAAsyncSelect() and WSAEventSelect()
*/
#define FD_QOS 0x40 #define FD_GROUP_QOS 0x80
/*
-
All Windows Sockets error constants are biased by WSABASEERR from
-
the "normal"
*/
#define WSABASEERR 10000
/*
- Windows Sockets definitions of regular Microsoft C error constants
*/
#define WSAEINTR (WSABASEERR+4)
#define WSAEBADF (WSABASEERR+9)
#define WSAEACCES (WSABASEERR+13)
#define WSAEFAULT (WSABASEERR+14)
#define WSAEINVAL (WSABASEERR+22)
#define WSAEMFILE (WSABASEERR+24)
/*
- Windows Sockets definitions of regular Berkeley error constants
*/
#define WSAEWOULDBLOCK (WSABASEERR+35)
#define WSAEINPROGRESS (WSABASEERR+36)
#define WSAEALREADY (WSABASEERR+37)
#define WSAENOTSOCK (WSABASEERR+38) #define WSAEDESTADDRREQ (WSABASEERR+39) #define WSAEMSGSIZE (WSABASEERR+40)
#define WSAEPROTOTYPE (WSABASEERR+41)
#define WSAENOPROTOOPT (WSABASEERR+42) #define WSAEPROTONOSUPPORT (WSABASEERR+43) #define WSAESOCKTNOSUPPORT (WSABASEERR+44) #define WSAEOPNOTSUPP (WSABASEERR+45) #define WSAEPFNOSUPPORT (WSABASEERR+46) #define WSAEAFNOSUPPORT (WSABASEERR+47) #define WSAEADDRINUSE (WSABASEERR+48) #define WSAEADDRNOTAVAIL (WSABASEERR+49) #define WSAENETDOWN (WSABASEERR+50)
#define WSAENETUNREACH (WSABASEERR+51)
#define WSAENETRESET (WSABASEERR+52) #define WSAECONNABORTED (WSABASEERR+53) #define WSAECONNRESET (WSABASEERR+54)
#define WSAENOBUFS (WSABASEERR+55)
#define WSAEISCONN (WSABASEERR+56)
#define WSAENOTCONN (WSABASEERR+57)
#define WSAESHUTDOWN (WSABASEERR+58) #define WSAETOOMANYREFS (WSABASEERR+59) #define WSAETIMEDOUT (WSABASEERR+60) #define WSAECONNREFUSED (WSABASEERR+61) #define WSAELOOP (WSABASEERR+62) #define WSAENAMETOOLONG (WSABASEERR+63) #define WSAEHOSTDOWN (WSABASEERR+64) #define WSAEHOSTUNREACH (WSABASEERR+65) #define WSAENOTEMPTY (WSABASEERR+66)
#define WSAEPROCLIM (WSABASEERR+67)
#define WSAEUSERS (WSABASEERR+68)
#define WSAEDQUOT (WSABASEERR+69)
#define WSAESTALE (WSABASEERR+70)
#define WSAEREMOTE (WSABASEERR+71)
/*
- Extended Windows Sockets error constant definitions
*/
#define WSASYSNOTREADY (WSABASEERR+91) #define WSAVERNOTSUPPORTED (WSABASEERR+92) #define WSANOTINITIALISED (WSABASEERR+93)
/*
-
Error return codes from gethostbyname() and gethostbyaddr()
-
(when using the resolver). Note that these errors are
-
retrieved via WSAGetLastError() and must therefore follow
-
the rules for avoiding clashes with error numbers from
-
specific implementations or language run-time systems.
-
For this reason the codes are based at WSABASEERR+1001.
-
Note also that [WSA]NO_ADDRESS is defined only for
-
compatibility purposes.
*/
#define h_errno WSAGetLastError()
/* Authoritative Answer: Host not found */ #define WSAHOST_NOT_FOUND (WSABASEERR+1001) #define HOST_NOT_FOUND WSAHOST_NOT_FOUND
/* Non-Authoritative: Host not found, or SERVERFAIL */ #define WSATRY_AGAIN (WSABASEERR+1002)
#define TRY_AGAIN WSATRY_AGAIN
/* Non-recoverable errors, FORMERR, REFUSED, NOTIMP */ #define WSANO_RECOVERY (WSABASEERR+1003)
#define NO_RECOVERY WSANO_RECOVERY
/* Valid name, no data record of requested type */ #define WSANO_DATA (WSABASEERR+1004)
#define NO_DATA WSANO_DATA
/* no address, look for MX record */ #define WSANO_ADDRESS WSANO_DATA
#define NO_ADDRESS WSANO_ADDRESS
/*
- Windows Sockets errors redefined as regular Berkeley error constants
*/
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEINPROGRESS
#define EALREADY WSAEALREADY
#define ENOTSOCK WSAENOTSOCK
#define EDESTADDRREQ WSAEDESTADDRREQ
#define EMSGSIZE WSAEMSGSIZE
#define EPROTOTYPE WSAEPROTOTYPE
#define ENOPROTOOPT WSAENOPROTOOPT #define EPROTONOSUPPORT WSAEPROTONOSUPPORT #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT #define EOPNOTSUPP WSAEOPNOTSUPP
#define EPFNOSUPPORT WSAEPFNOSUPPORT
#define EAFNOSUPPORT WSAEAFNOSUPPORT
#define EADDRINUSE WSAEADDRINUSE
#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
#define ENETDOWN WSAENETDOWN
#define ENETUNREACH WSAENETUNREACH
#define ENETRESET WSAENETRESET
#define ECONNABORTED WSAECONNABORTED
#define ECONNRESET WSAECONNRESET
#define ENOBUFS WSAENOBUFS
#define EISCONN WSAEISCONN
#define ENOTCONN WSAENOTCONN
#define ESHUTDOWN WSAESHUTDOWN
#define ETOOMANYREFS WSAETOOMANYREFS
#define ETIMEDOUT WSAETIMEDOUT
#define ECONNREFUSED WSAECONNREFUSED
#define ELOOP WSAELOOP
#define ENAMETOOLONG WSAENAMETOOLONG
#define EHOSTDOWN WSAEHOSTDOWN
#define EHOSTUNREACH WSAEHOSTUNREACH
#define ENOTEMPTY WSAENOTEMPTY
#define EPROCLIM WSAEPROCLIM
#define EUSERS WSAEUSERS
#define EDQUOT WSAEDQUOT
#define ESTALE WSAESTALE
#define EREMOTE WSAEREMOTE
/*
- WinSock 2.0 extension - new error codes and type definition
*/
#ifdef WIN32
#define WSAAPI FAR PASCAL
#define WSATASK HANDLE
#define WSAEVENT HANDLE
#define LPWSAEVENT LPHANDLE
#define WSAOVERLAPPED OVERLAPPED
#define LPWSAOVERLAPPED LPOVERLAPPED
#define WSA_IO_PENDING (ERROR_IO_PENDING)
#define WSA_IO_INCOMPLETE (ERROR_IO_INCOMPLETE)
#define WSA_INVALID_HANDLE (ERROR_INVALID_HANDLE)
#define WSA_INVALID_PARAMETER (ERROR_INVALID_PARAMETER)
#define WSA_NOT_ENOUGH_MEMORY (ERROR_NOT_ENOUGH_MEMORY)
#define WSAEDISCON (WSABASEERR + 94) #define WSA_INVALID_EVENT ((WSAEVENT)NULL)
#define WSA_MAXIMUM_WAIT_EVENTS (MAXIMUM_WAIT_OBJECTS)
#define WSA_WAIT_FAILED ((DWORD)-1L) #define WSA_WAIT_EVENT_0 (WAIT_OBJECT_0)
#define WSA_WAIT_IO_COMPLETION (WAIT_IO_COMPLETION) #define WSA_WAIT_TIMEOUT (WAIT_TIMEOUT) #define WSA_INFINITE (INFINITE)
#else // WIN16
#define WSAAPI FAR PASCAL
#define WSATASK HTASK
typedef DWORD WSAEVENT, FAR * LPWSAEVENT;
typedef struct _WSAOVERLAPPED
{
DWORD Internal; DWORD InternalHigh; DWORD Offset;
DWORD OffsetHigh; WSAEVENT hEvent;
} WSAOVERLAPPED, FAR * LPWSAOVERLAPPED;
#define WSA_IO_PENDING (WSAEWOULDBLOCK) #define WSA_IO_INCOMPLETE (WSAEWOULDBLOCK) #define WSA_INVALID_HANDLE (WSAENOTSOCK) #define WSA_INVALID_PARAMETER (WSAEINVAL) #define WSA_NOT_ENOUGH_MEMORY (WSAENOBUFS) #define WSAEDISCON (WSABASEERR
- 94)
#define WSA_INVALID_EVENT ((WSAEVENT)NULL) #define WSA_MAXIMUM_WAIT_EVENTS
(MAXIMUM_WAIT_OBJECTS)
#define WSA_WAIT_FAILED ((DWORD)-1L) #define WSA_WAIT_EVENT_0 ((DWORD)0) #define WSA_WAIT_TIMEOUT ((DWORD)0x102L) #define WSA_INFINITE ((DWORD)-1L)
#endif // WIN32
/*
- WinSock 2.0 extension - WSABUF and QOS struct
*/
typedef struct _WSABUF {
int len; // the length of the buffer char FAR * buf; // the pointer to the buffer
} WSABUF, FAR * LPWSABUF;
typedef enum
{
BestEffortService, PredictiveService, GuaranteedService
} GUARANTEE;
typedef long int32; typedef struct _flowspec
{
int32 TokenRate; // In Bytes/sec int32 TokenBucketSize; // In Bytes int32 PeakBandwidth; // In Bytes/sec
int32 Latency; // In microseconds int32 DelayVariation; // In microseconds GUARANTEE LevelOfGuarantee; // Guaranteed,
Predictive or Best Effort
int32 CostOfCall; // Reserved for future use, must be set to 0 now
int32 NetworkAvailability; // read-only: 1 if accessible, 0 if not
} FLOWSPEC, FAR * LPFLOWSPEC;
typedef struct _QualityOfService
{
WSABUF SendingFlowspec; // the flow spec for data sending
WSABUF ReceivingFlowspec; // the flow spec for data receiving
} QOS, FAR * LPQOS;
/*
- WinSock 2.0 extension - manifest constants for return values of the condition function
*/
#define CF_ACCEPT 0x0000
#define CF_REJECT 0x0001
#define CF_DEFER 0x0002
/*
- WinSock 2.0 extension - manifest constants for shutdown()
*/
#define SD_RECEIVE 0x00
#define SD_SEND 0x01
#define SD_BOTH 0x02
/*
- WinSock 2.0 extension - data type and manifest constants for socket groups
*/
typedef unsigned int GROUP;
#define SG_UNCONSTRAINED_GROUP 0x01 #define SG_CONSTRAINED_GROUP 0x02
/*
- WinSock 2.0 extension - data type for WSAEnumNetworkEvents()
*/
typedef struct _WSANETWORKEVENTS { long lNetworkEvent,
int iErrorCode
} WSANETWORKEVENTS, FAR * LPWSANETWORKEVENTS;
/*
- WinSock 2.0 extension - PROTOCOL_INFO structure and associated manifest constants
*/
typedef struct _PROTOCOL_INFO { DWORD dwServiceFlags1; DWORD dwServiceFlags2; DWORD dwServiceFlags3; DWORD dwServiceFlags4;
int iProviderID; int iVersion;
int iAddressFamily; int iMaxSockAddr; int iMinSockAddr; int iSocketType; int iProtocol;
int iNetworkByteOrder; int iSecurityScheme; BOOL bMultiple;
BOOL bFirst;
DWORD dwMessageSize; LPSTR lpProtocol;
} PROTOCOL_INFO, FAR * LPPROTOCOL_INFO;
#define XP1_CONNECTIONLESS 0x00000001
#define XP1_GUARANTEED_DELIVERY 0x00000002
#define XP1_GUARANTEED_ORDER 0x00000004
#define XP1_MESSAGE_ORIENTED 0x00000008
#define XP1_PSEUDO_STREAM 0x00000010
#define XP1_GRACEFUL_CLOSE 0x00000020
#define XP1_EXPEDITED_DATA 0x00000040
#define XP1_CONNECT_DATA 0x00000080
#define XP1_DISCONNECT_DATA 0x00000100
#define XP1_SUPPORTS_BROADCAST 0x00000200
#define XP1_SUPPORT_MULTIPOINT 0x00000400 #define XP1_MULTIPOINT_CONTROL_PLANE 0x00000800
#define XP1_MULTIPOINT_DATA_PLANE 0x00001000
#define XP1_QOS_SUPPORTED 0x00002000
#define XP1_INTERRUPT 0x00004000
#define XP1_UNI_SEND 0x00008000
#define XP1_UNI_RECV 0x00010000
/*
- WinSock 2.0 extension - manifest constants for WSAJoinLeaf()
*/
#define JL_SENDER_ONLY 0x01 #define JL_RECEIVER_ONLY 0x02 #define JL_BOTH 0x04
/*
- WinSock 2.0 extension - manifest constants for WSASocket()
*/
#define WSA_FLAG_OVERLAPPED 0x01 #define WSA_FLAG_MULTIPOINT_C_ROOT 0x02 #define WSA_FLAG_MULTIPOINT_C_LEAF 0x04 #define WSA_FLAG_MULTIPOINT_D_ROOT 0x08 #define WSA_FLAG_MULTIPOINT_D_LEAF 0x10
/* Socket function prototypes */ #ifdef cplusplus
extern "C" {
#endif
SOCKET PASCAL FAR accept (SOCKET s, struct sockaddr FAR
*addr,
int FAR *addrlen);
int PASCAL FAR bind (SOCKET s, const struct sockaddr FAR
*addr, int namelen);
int PASCAL FAR closesocket (SOCKET s);
int PASCAL FAR connect (SOCKET s, const struct sockaddr FAR
*name, int namelen);
int PASCAL FAR ioctlsocket (SOCKET s, long cmd, u_long FAR
*argp);
int PASCAL FAR getpeername (SOCKET s, struct sockaddr FAR
*name,
int FAR * namelen);
int PASCAL FAR getsockname (SOCKET s, struct sockaddr FAR
*name,
int FAR * namelen);
int PASCAL FAR getsockopt (SOCKET s, int level, int optname,
char FAR * optval, int FAR
*optlen);
u_long PASCAL FAR htonl (u_long hostlong); u_short PASCAL FAR htons (u_short hostshort);
unsigned long PASCAL FAR inet_addr (const char FAR * cp); char FAR * PASCAL FAR inet_ntoa (struct in_addr in);
int PASCAL FAR listen (SOCKET s, int backlog); u_long PASCAL FAR ntohl (u_long netlong); u_short PASCAL FAR ntohs (u_short netshort);
int PASCAL FAR recv (SOCKET s, char FAR * buf, int len, int flags);
int PASCAL FAR recvfrom (SOCKET s, char FAR * buf, int len, int flags,
struct sockaddr FAR *from, int FAR
* fromlen);
int PASCAL FAR select (int nfds, fd_set FAR *readfds, fd_set FAR *writefds,
fd_set FAR *exceptfds, const struct
timeval FAR *timeout);
int PASCAL FAR send (SOCKET s, const char FAR * buf, int len, int flags);
int PASCAL FAR sendto (SOCKET s, const char FAR * buf, int len, int flags,
const struct sockaddr FAR *to, int
tolen);
int PASCAL FAR setsockopt (SOCKET s, int level, int optname,
const char FAR * optval, int
optlen);
int PASCAL FAR shutdown (SOCKET s, int how);
SOCKET PASCAL FAR socket (int af, int type, int protocol);
/* Database function prototypes */
struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR
* addr,
int len, int
type);
struct hostent FAR * PASCAL FAR gethostbyname(const char FAR
* name);
int PASCAL FAR gethostname (char FAR * name, int namelen);
struct servent FAR * PASCAL FAR getservbyport(int port, const char FAR * proto);
struct servent FAR * PASCAL FAR getservbyname(const char FAR
- name,
const char FAR
- proto);
struct protoent FAR * PASCAL FAR getprotobynumber(int proto);
struct protoent FAR * PASCAL FAR getprotobyname(const char FAR * name);
/* Microsoft Windows Extension function prototypes */
int PASCAL FAR WSAStartup(WORD wVersionRequired, LPWSADATA lpWSAData);
int PASCAL FAR WSACleanup(void);
void PASCAL FAR WSASetLastError(int iError); int PASCAL FAR WSAGetLastError(void);
BOOL PASCAL FAR WSAIsBlocking(void);
int PASCAL FAR WSAUnhookBlockingHook(void);
FARPROC PASCAL FAR WSASetBlockingHook(FARPROC lpBlockFunc); int PASCAL FAR WSACancelBlockingCall(void);
HANDLE PASCAL FAR WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
name, proto,
const char FAR * const char FAR * char FAR * buf, int
buflen);
HANDLE PASCAL FAR WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
proto, char FAR * buf,
const char FAR * int buflen);
HANDLE PASCAL FAR WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
name, char FAR * buf,
const char FAR * int buflen);
HANDLE PASCAL FAR WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
FAR * buf,
int number, char int buflen);
HANDLE PASCAL FAR WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
name, char FAR * buf,
const char FAR * int buflen);
HANDLE PASCAL FAR WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
addr, int len, int type, buf, int buflen);
const char FAR * const char FAR *
int PASCAL FAR WSACancelAsyncRequest(HANDLE hAsyncTaskHandle);
int PASCAL FAR WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
long lEvent);
/*
* WinSock 2.0 extension - data type for the condition function in WSAAccept()
*/
typedef int (CALLBACK * LPCONDITIONPROC) (LPWSABUF
lpCallerId,
lpCallerData,
lpCalleeId, lpCalleeData,
dwCallbackData);
LPWSABUF
LPQOS lpSQOS, LPQOS lpGQOS, LPWSABUF
LPWSABUF
GROUP FAR * g, DWORD
/* WinSock 2.0 API new function prototypes */
SOCKET WSAAPI WSAAccept (SOCKET s,
struct sockaddr FAR *addr, int FAR *addrlen,
LPCONDITIONPROC lpfnCondition, DWORD dwCallbackData);
BOOL WSAAPI WSACloseEvent (WSAEVENT hEvent); int WSAAPI WSAConnect (SOCKET s,
const struct sockaddr FAR *name,
int namelen,
LPWSABUF lpCallerData, LPWSABUF lpCalleeData, LPQOS lpSQOS,
LPQOS lpGQOS);
WSAEVENT WSAAPI WSACreateEvent (VOID);
SOCKET WSAAPI WSADuplicateSocket(SOCKET s,
WSATASK hTargetTask);
int WSAAPI WSAEnumNetworkEvents (SOCKET s,
WSAEVENT hEventObject, LPWSANETWORKEVENTS
lpNetworkEvents,
LPINT lpiCount);
int WSAAPI WSAEnumProtocols (LPDWORD lpdwProtocols,
LPVOID lpProtocolBuffer, LPDWORD lpdwBufferLength);
int WSAAPI WSAEventSelect (SOCKET s,
WSAEVENT hEventObject, long lNetworkEvents);
BOOL WSAAPI WSAGetOverlappedResult (SOCKET s,
LPWSAOVERLAPPED
lpOverlapped,
LPDWORD lpcbTransfer, BOOL fWait,
LPDWORD lpdwFlags);
BOOL WSAAPI WSAGetQOSByname (SOCKET s,
LPWSABUF lpQOSName, LPQOS lpQOS);
u_long WSAAPI WSAHtonl (SOCKET s,
u_long hostlong);
u_short WSAAPI WSAHtons (SOCKET s,
u_short hostshort ); int WSAAPI WSAIoctl(SOCKET s,
DWORD dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer,
LPDWORD lpcbBytesReturned, LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE
lpCompletionRoutine);
SOCKET WSAAPI WSAJoinLeaf (SOCKET s,
const struct sockaddr FAR * name, int namelen,
LPWSABUF lpCallerData, LPWSABUF lpCalleeData, LPQOS lpSQOS,
LPQOS lpGQOS,
int iFlags);
u_long WSAAPI WSANtohl (SOCKET s,
u_long netlong );
u_short WSAAPI WSANtohs (SOCKET s,
u_short netshort );
int WSAAPI WSARecv (SOCKET s,
LPWSABUF lpBuffesr, DWORD dwBufferCount,
LPDWORD lpNumberOfBytesRecvd, LPINT lpFlags, LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE
lpCompletionRoutine);
int WSAAPI WSARecvDisconnect (SOCKET s,
LPWSABUF
lpInboundDisconnectData);
int WSAAPI WSARecvFrom (SOCKET s,
LPWSABUF lpBuffers, DWORD dwBufferCount,
LPDWORD lpNumberOfBytesRecvd, LPINT lpFlags,
LPVOID lpFrom, LPINT lpFromlen,
LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE
lpCompletionRoutine);
BOOL WSAAPI WSAResetEvent(WSAEVENT hEvent); int WSAAPI WSASend (SOCKET s,
LPWSABUFlpBuffers, DWORD dwBufferCount,
LPDWORD lpNumberOfBytesSent, int iFlags,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE
lpCompletionRoutine);
int WSAAPI WSASendDisconnect (SOCKET s,
LPWSABUF
lpOutboundDisconnectData );
int WSAAPI WSASendTo (SOCKET s,
LPWSABUFlpBuffers, DWORD dwBufferCount,
LPDWORD lpNumberOfBytesSent, int iFlags,
LPVOID lpTo,
int iTolen,
LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE
lpCompletionRoutine);
BOOL WSAAPI WSASetEvent(WSAEVENT hEvent);
SOCKET WSAAPI WSASocket (int af,
int type,
int protocol,
LPPROTOCOL_INFO lpProtocolInfo, GROUP g,
int iFlags);
DWORD WSAAPI WSAWaitForMultipleEvents(DWORD cEvents,
const WSAEVENT FAR *
lphEvents,
BOOL fWaitAll, DWORD dwTimeout, BOOL fAlertable);
#ifdef cplusplus
}
#endif
/* Microsoft Windows Extended data types */ typedef struct sockaddr SOCKADDR;
typedef struct sockaddr *PSOCKADDR; typedef struct sockaddr FAR *LPSOCKADDR;
typedef struct sockaddr_in SOCKADDR_IN; typedef struct sockaddr_in *PSOCKADDR_IN; typedef struct sockaddr_in FAR *LPSOCKADDR_IN;
typedef struct linger LINGER; typedef struct linger *PLINGER; typedef struct linger FAR *LPLINGER;
typedef struct in_addr IN_ADDR; typedef struct in_addr *PIN_ADDR; typedef struct in_addr FAR *LPIN_ADDR;
typedef struct fd_set FD_SET; typedef struct fd_set *PFD_SET;
typedef struct fd_set FAR *LPFD_SET;
typedef struct hostent HOSTENT; typedef struct hostent *PHOSTENT; typedef struct hostent FAR *LPHOSTENT;
typedef struct servent SERVENT; typedef struct servent *PSERVENT; typedef struct servent FAR *LPSERVENT;
typedef struct protoent PROTOENT; typedef struct protoent *PPROTOENT; typedef struct protoent FAR *LPPROTOENT;
typedef struct timeval TIMEVAL; typedef struct timeval *PTIMEVAL; typedef struct timeval FAR *LPTIMEVAL;
/*
-
Windows message parameter composition and decomposition
-
macros.
*
-
WSAMAKEASYNCREPLY is intended for use by the Windows Sockets implementation
-
when constructing the response to a WSAAsyncGetXByY() routine.
*/
#define WSAMAKEASYNCREPLY(buflen,error) MAKELONG(buflen,error)
/*
-
WSAMAKESELECTREPLY is intended for use by the Windows Sockets implementation
-
when constructing the response to WSAAsyncSelect().
*/
#define WSAMAKESELECTREPLY(event,error) MAKELONG(event,error)
/*
- WSAGETASYNCBUFLEN is intended for use by the Windows
Sockets application
-
to extract the buffer length from the lParam in the response
-
to a WSAAsyncGetXByY().
*/
#define WSAGETASYNCBUFLEN(lParam) LOWORD(lParam)
/*
-
WSAGETASYNCERROR is intended for use by the Windows Sockets application
-
to extract the error code from the lParam in the response
-
to a WSAGetXByY().
*/
#define WSAGETASYNCERROR(lParam) HIWORD(lParam)
/*
-
WSAGETSELECTEVENT is intended for use by the Windows Sockets application
-
to extract the event code from the lParam in the response
-
to a WSAAsyncSelect().
*/
#define WSAGETSELECTEVENT(lParam) LOWORD(lParam)
/*
-
WSAGETSELECTERROR is intended for use by the Windows Sockets application
-
to extract the error code from the lParam in the response
-
to a WSAAsyncSelect().
*/
#define WSAGETSELECTERROR(lParam) HIWORD(lParam) #endif /* _WINSOCK2API_ */
附录 B.3 Winsock.def 文件
;
; File: winsock.def
; System: MS-Windows 3.x
; Summary: Module definition file for Windows Sockets DLL.
;
LIBRARY WINSOCK ; Application's module name DESCRIPTION 'BSD Socket API for Windows'
EXETYPE applications |
WINDOWS |
; |
required for all windows |
---|---|---|---|
STUB application |
'WINSTUB.EXE' |
; ; |
generates error message if is run without Windows |
;CODE can be FIXED in memory because of potential upcalls CODE PRELOAD FIXED
;DATA must be SINGLE and at a FIXED location since this is a DLL
DATA |
PRELOAD |
FIXED |
SINGLE |
---|---|---|---|
HEAPSIZE |
1024 |
||
STACKSIZE |
16384 |
; All functions that will be called by any Windows routine
; must be exported. Any additional exports beyond those defined
; here must have ordinal numbers 1000 or above.
EXPORTS
accept |
@1 | |
---|---|---|
bind |
@2 | |
closesocket |
@3 | |
connect |
@4 |
getpeername getsockname getsockopt htonl htons inet_addr inet_ntoa ioctlsocket listen ntohl ntohs recv recvfrom select send sendto setsockopt shutdown socket |
@15 @21 |
@5 @6 @7 @8 @9 @10 @11 @12 @13 @14 @16 @17 @18 @19 @20 @22 @23 |
---|---|---|
gethostbyaddr gethostbyname getprotobyname getprotobynumber getservbyname getservbyport gethostname |
@56 |
@51 @52 @53 @54 @55 @57 |
WSAAsyncSelect WSAAsyncGetHostByAddr WSAAsyncGetHostByName WSAAsyncGetProtoByNumber WSAAsyncGetProtoByName WSAAsyncGetServByPort WSAAsyncGetServByName WSACancelAsyncRequest WSASetBlockingHook WSAUnhookBlockingHook |
@104 |
@101 @102 @103 @105 @106 @107 @108 @109 @110 |
WSAGetLastError |
@111 |
|
---|---|---|
WSASetLastError |
@112 |
|
WSACancelBlockingCall |
@113 |
|
WSAIsBlocking |
@114 |
|
WSAStartup |
@115 |
|
WSACleanup WSAFDIsSet |
@151 |
@116 |
WEP |
@500 |
RESIDENTNAME |
;eof