📄 socket.h
字号:
// socket.h// portable header socket functions// copyright SafeTP Development Group, Inc., 2000 Terms of use are as specified in license.txt#ifndef __SOCKET_H#define __SOCKET_H// ------------- win32 --------------------#if defined(__WIN32__)#ifdef USE_MINWIN_H# include "..\windoze.h" // my abbreviated win32 api headers#else# include <windows.h> // full win32 api#endif#include <winsock.h> // sockets// ------------ unix ------------------#elif defined(__CYGWIN__) || defined(__UNIX__) // some systems (like Linux!) incorrectly #define NULL as ((void*)0), where// the correct definition (for C++) is:#ifndef NULL# define NULL 0#endif#include <sys/types.h> // Solaris 2.5.1 fix: u_short, required by sys/socket.h#include <sys/socket.h> // sockets#include <sys/time.h> // timeval#include <string.h> // bzero, for FD_SET#include <netinet/in.h> // INADDR_*, in_addr, sockaddr_in, htonl etc.#include <netdb.h> // getservbyname#include <arpa/inet.h> // inet_addr#ifdef __OSF1__# include <strings.h> // bzero for FD_SET#endif// these constants are useful, but appear to be specific to// winsock; so, I define them here and use them as if they// were standard#define INVALID_SOCKET ((SOCKET)(~0))#define SOCKET_ERROR (-1)// SunOS apparently doesn't have this#ifndef INADDR_NONE# define INADDR_NONE 0xffffffff#endif// closesocket#define closesocket close#if defined(__CYGWIN__)# include <sys/unistd.h> // close#else // __UNIX__# include <unistd.h> // close#endif// -------------- portable ---------------#endif#include "socketd.h" // by pulling in the SOCKET declarations here, we'll get a compiler // warning if that declaration differs from the "real" one pulled // in from above (e.g. winsock.h)#endif // __SOCKET_H// ----- stuff I had here, before I knew which headers had them, on unix -----#if 0#define INADDR_ANY ((unsigned long)0x00000000)#define INADDR_LOOPBACK (0x7f000001)#define INADDR_NONE 0xffffffff/* * Internet address (old style... should be updated) */struct in_addr { union { 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; } S_un;#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 /* 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 */};/* * Socket address, internet style. */struct sockaddr_in { short sin_family; u_short sin_port; struct in_addr sin_addr; char sin_zero[8];};// htons, htonl, ntohl, ntohs#define NEED_ENDIAN_CONVERSIONSu_long htonl (u_long hostlong);u_short htons (u_short hostshort);u_long ntohl (u_long netlong);u_short ntohs (u_short netshort);#endif // 0 - trash
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -