#ifdef _WIN32
#include <stdio.h>
#include <stdlib.h>
#include <WINSOCK2.H>
#include <windows.h>
#include <time.h>
#else
#include <time.h>
#include <sys/time.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#endif
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
#ifdef _WIN32
#pragma comment(lib, "ws2_32.lib")
#endif
#ifdef _WIN32
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEINPROGRESS
#define ETIMEDOUT WSAETIMEDOUT
#endif
#ifndef _WIN32
typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
#define closesocket close
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#endif
#ifndef _WIN32
int GetLastError(void)
{
return errno;
}
#endif
#ifdef _WIN32
BOOL InitTCPIP(void)
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) //winsock2.2版本
{
printf("Init TCP:WSAStartup failed!\n");
return FALSE;
}
if (wsaData.wVersion != 0x0202) //验证版本协商结果
{
WSACleanup();
printf("Init TCP:wsaData.wVersion failed!\n");
#include <stdio.h>
#include <stdlib.h>
#include <WINSOCK2.H>
#include <windows.h>
#include <time.h>
#else
#include <time.h>
#include <sys/time.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#endif
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
#ifdef _WIN32
#pragma comment(lib, "ws2_32.lib")
#endif
#ifdef _WIN32
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EINPROGRESS WSAEINPROGRESS
#define ETIMEDOUT WSAETIMEDOUT
#endif
#ifndef _WIN32
typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
#define closesocket close
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#endif
#ifndef _WIN32
int GetLastError(void)
{
return errno;
}
#endif
#ifdef _WIN32
BOOL InitTCPIP(void)
{
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) //winsock2.2版本
{
printf("Init TCP:WSAStartup failed!\n");
return FALSE;
}
if (wsaData.wVersion != 0x0202) //验证版本协商结果
{
WSACleanup();
printf("Init TCP:wsaData.wVersion failed!\n");