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

📄 netdrv.h

📁 Linux 下的socket客户端服务端代码
💻 H
字号:
/*
 * GPRS Control Centor -- a control centor of GPRS terminal based on GTK+
 * Copyright (C) 2003 Xiangbin Lee <honeycombs@sina.com> <honeycombs@263.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software.
 */

#ifndef _NET_DRIVER_H_
#define _NET_DRIVER_H_

/*-----------------------------------------------------*/

/*
* Windows Sockets errors redefined as regular Berkeley error constants.
* These are commented out in Windows NT to avoid conflicts with errno.h.
* Use the WSA constants instead.
*/

#define SOCKET   int
#define INVALID_SOCKET -1
#define LPVOID  void *
#define HANDLE  int
#define closesocket close

#define WSAEWOULDBLOCK      EWOULDBLOCK 
#define WSAEINPROGRESS      EINPROGRESS
#define WSAEALREADY         EALREADY
#define WSAENOTSOCK         ENOTSOCK 
#define WSAEDESTADDRREQ     EDESTADDRREQ
#define WSAEMSGSIZE         EMSGSIZE 
#define WSAEPROTOTYPE       EPROTOTYPE 
#define WSAENOPROTOOPT      ENOPROTOOPT 
#define WSAEPROTONOSUPPORT  EPROTONOSUPPORT         
#define WSAESOCKTNOSUPPORT  ESOCKTNOSUPPORT
#define WSAEOPNOTSUPP       EOPNOTSUPP 
#define WSAEPFNOSUPPORT     EPFNOSUPPORT 
#define WSAEAFNOSUPPORT     EAFNOSUPPORT
#define WSAEADDRINUSE       EADDRINUSE 
#define WSAEADDRNOTAVAIL    EADDRNOTAVAIL 
#define WSAENETDOWN         ENETDOWN 
#define WSAENETUNREACH      ENETUNREACH 
#define WSAENETRESET        ENETRESET  
#define WSAECONNABORTED     ECONNABORTED 
#define WSAECONNRESET       ECONNRESET 
#define WSAENOBUFS          ENOBUFS 
#define WSAEISCONN          EISCONN

#define WSAENOTCONN         ENOTCONN
#define WSAESHUTDOWN        ESHUTDOWN
#define WSAETOOMANYREFS     ETOOMANYREFS            
#define WSAETIMEDOUT        ETIMEDOUT
#define WSAECONNREFUSED     ECONNREFUSED
#define WSAELOOP            ELOOP
#define WSAENAMETOOLONG     ENAMETOOLONG 
#define WSAEHOSTDOWN        EHOSTDOWN 
#define WSAEHOSTUNREACH     EHOSTUNREACH
#define WSAENOTEMPTY        ENOTEMPTY
#define WSAEPROCLIM         EPROCLIM 
#define WSAEUSERS           EUSERS 
#define WSAEDQUOT           EDQUOT
#define WSAESTALE           ESTALE 
#define WSAEREMOTE          EREMOTE

/*
* Winsock compatability layer for Unix
*/

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>

#include <netdb.h>
#include <errno.h>

int WSAGetLastError(void);

int WSACleanup(void);

int InitSockets(void);


/********************************************************************
 *
 * Define Error processor for WINDOWS SOCKET
 * Input
 * Output: char ErrorMsg[512] (Error Message Container)
 ********************************************************************/

#define WSA_ERROR(x)  {printf("\n Socket Error %d: %s\n",WSAGetLastError(),x);}

/********************************************************************
 * Debug functions
 ********************************************************************/
#define _PrintInterruptMsg(x,y)    {printf("\n %s %d",x,y );}

int CheckSocketRead(SOCKET fd);
int CheckSocketWrite(SOCKET fd);
int CheckIp(char *ipn);

/* ---------------------------------------------------- */

# define TEMP_FAILURE_RETRY(expression) \
  (__extension__                                  \
    ({ long int __result;                              \
       do __result = (long int) (expression);                      \
       while (__result == -1L && errno == EINTR);                  \
       __result; }))

#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
      
int input_timeout (int filedes, unsigned int seconds);
/*-----------------------------------------------------*/
#endif 

⌨️ 快捷键说明

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