📄 attsock.h
字号:
#define AF_MAX 22
/*
* Structure used by kernel to store most
* addresses.
*/
typedef struct sockaddr {
unsigned short sa_family; /* address family */
char sa_data[14]; /* up to 14 bytes of direct address */
}SOCKADDR;
/*
* 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
/*用于函数(ioctlsocket)的控制命令*/
#define FIONBIO 1
#define FIONREAD 2
#define SIOCATMASK 3
/*
* 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)
/***************************************\
SOCKET中间的错误信息设置
-1 : global error num
-100 —— -200 : Socket Error Num
\***************************************/
#ifndef EWOULDBLOCK
#define EWOULDBLOCK 100 /*阻塞错误 */
#define ENOTCONN 101 /*未连接错误 */
#define ESOCKTNOSUPPORT 102 /*本地址族中不支持该类型套接口*/
#define EAFNOSUPPORT 103 /*家族不支持 */
#define EISCONN 104 /*已连接错误 */
#define EOPNOTSUPP 105 /*选项不支持 */
#define EALARM 106 /*警报 */
#define EABORT 107 /*放弃 */
#define EINTR 108 /*用户调用放弃 */
#define ECONNREFUSED 109 /*连接被拒绝 */
#define EMSGSIZE 110 /*消息长度错误 */
#define EADDRINUSE 111 /*地址被占用 */
#define EMIN 112 /*最小值溢出 */
#define EMAX 113 /*最大值溢出 */
#define ESOCKTABLEFULL 114 /*SOCKET表满 */
#define ENOMEMORY 115 /*内存不够 */
#define ENOTSOCK 116 /*SOCKET句柄无效 */
#define EINVALIDPARA 117 /*参数无效 */
#define EADDRFORMAT 118 /*地址格式不对 */
#define EPROTNOSUPPORT 119 /*协议不支持 */
#define ELOWSYSRESOURCE 120 /*系统资源不够 */
#define ETIMEOUT 121 /*超时错误 */
#define ERESET 122 /*连接被复位 */
#define EINPROGRESS 123 /*一个阻塞的调用正在被执行 */
#define ECONNABORTED 124 /*连接被放弃 */
#define ENETDOWN 125 /*网络不通 */
#define ENOTINITIALISED 126 /*未初始化(SockStartup没有被调用) */
#define EINVAL 127 /**/
#define EUNKNOWERROR 199 /*未知错误 */
#define EMAXSOCKERRORNUM 200 /*最大错误数值*/
#endif
/*Error code about name query:*/
#define NO_ERROR 0
#define FORMAT_ERROR 1
#define SERVER_FAIL 2
#define NAME_ERROR 3
#define NOT_IMPL 4
#define REFUSED 5
#define RUNING_ERROR 6
#define NOBUF_ERROR 7
#define TIMEOUT_ERROR 8
#define USERCANCLE_ERROR 9
#define INADDR_ANY (unsigned long)0x00000000
#define INADDR_LOOPBACK 0x7f000001
#define INADDR_BROADCAST (unsigned long)0xffffffff
#define INADDR_NONE 0xffffffff
/*SOCKET选项级别以及协议数值的设置(getsockopt和setsockopt)*/
#define SOL_SOCKET 0xffff /*Socket 级的选项。 */
/*用于函数shutdown()的断联控制方式*/
#define SD_RECEIVE 1 /*不允许后继的recv操作 */
#define SD_SEND 2 /* 不允许后继的send操作 */
#define SD_BOTH 3 /* 断开连接并禁止读、写操作 */
/**************************************************************************\
*
* DATA STRUCTURE & DATA TYPE DEFINITION
*
\**************************************************************************/
/*定义结构保证与WINSOCK兼容*/
struct linger
{
unsigned short l_onoff; // option on/off
unsigned short l_linger; // linger time
};
typedef struct linger LINGER;
/**************************************************************************\
*
* FUNCTION PROTOTYPE DECLARATION
*
\**************************************************************************/
/* socket function prototypes */
int WSAStartup(unsigned short wVersionRequired, LPWSADATA lpWSAData);
int WSACleanup(void);
void WSASetLastError (long iError);
long WSAGetLastError (void);
SOCKET plx_socket(int af, int type, int protocol);
int plx_shutdown(SOCKET s, int how);
int plx_closesocket(SOCKET s);
SOCKET plx_accept(SOCKET s, struct sockaddr *addr, int *addrlen);
int plx_bind(SOCKET s, const struct sockaddr *addr, int addrlen);
int plx_connect(SOCKET s, const struct sockaddr *addr, int addrlen);
int plx_listen(SOCKET s, int backlog);
int plx_send(SOCKET s, const char *pbuf, int len, int flags);
int plx_sendto(SOCKET s, const char* pbuf, int len, int flags,
const struct sockaddr *to, int tolen);
int plx_recv(SOCKET s, char *pbuf, int len, int flags);
int plx_recvfrom(SOCKET s, char *pbuf, int len, int flags,
struct sockaddr *from, int *fromlen);
int plx_ioctlsocket(SOCKET s, long cmd, unsigned long *argp);
int plx_getsockname(SOCKET s, struct sockaddr *addr, int *addrlen);
int plx_gethostname(char *name, int namelen);
int plx_getpeername(SOCKET s, struct sockaddr* name, int *namelen);
int plx_getsockopt(SOCKET s, int level, int optname, char *optval, int *optlen);
int plx_setsockopt(SOCKET s, int level, int optname, char* optval, int optlen);
unsigned short plx_ntohs(unsigned short port);
unsigned short plx_htons(unsigned short hostshort);
unsigned long plx_ntohl(unsigned long netlong);
unsigned long plx_htonl(unsigned long hostlong);
char *inet_ntoa(struct in_addr in);
unsigned long inet_addr(const char* cp);
int WSAAsyncSelect(SOCKET s, void *hWnd, unsigned int uMsg, long lEvent);
long WSAAsyncGetHostByName(void *hWnd, unsigned int uMsg,
char *name, char* buf, long buflen);
long WSAAsyncGetHostByAddr(void *hWnd, unsigned int uMsg,
char* addr, long len, long type,
char* buf, long buflen);
int WSACancelAsyncRequest(unsigned int hAsynHandle);
int LIB_GetError(void);
int LIB_SetError(int error);
int LIB_GetSysClock(void);
#define socket plx_socket
#define shutdown plx_shutdown
#define closesocket plx_closesocket
#define accept plx_accept
#define bind plx_bind
#define connect plx_connect
#define listen plx_listen
#define send plx_send
#define sendto plx_sendto
#define recv plx_recv
#define recvfrom plx_recvfrom
#define ioctlsocket plx_ioctlsocket
#define getsockname plx_getsockname
#define gethostname plx_gethostname
#define getpeername plx_getpeername
#define getsockopt plx_getsockopt
#define setsockopt plx_setsockopt
/* 11-22 modified for 06A */
#ifndef ntohs
#define ntohs plx_ntohs
#endif
#ifndef htons
#define htons plx_htons
#endif
#ifndef ntohl
#define ntohl plx_ntohl
#endif
#ifndef htonl
#define htonl plx_htonl
#endif
/* 11-22 modified for 06A end */
#endif /* WINSOCK_H_*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -