📄 netdrv.c
字号:
/*
*
* 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 Foundation.
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "ache.h"
#include "netdrv.h"
int WSAGetLastError(void)
{
return errno;
}
int WSACleanup(void)
{
return 0;
}
int InitSockets(void)
{
/* Ask for socket functionality */
return 0;
}
unsigned char * CheckIp(char *ipn)
{
static unsigned char ip[5];
char ips[20];
char *lpbuf;
int freei,potn=0;
int len=strlen(ipn);
if(len>15||len<7)
return 0;
memcpy((void*)ips,(void*)ipn,len);
ips[len]=0;
lpbuf=ips;
for(freei=0;freei<len;freei++)
{
if(ipn[freei]=='.')
{
ipn[freei]=0;
ip[potn]=(unsigned char)(strtod(lpbuf,0));
lpbuf=ips+freei+1;
potn++;
if(potn>=3)
break;
}
}
if(potn!=3)
return 0;
ip[3]=(unsigned char)(strtod(lpbuf,0));
sprintf(ipn,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]);
return (unsigned char *)ip;
}
int CheckSocketRead(SOCKET fd, unsigned long usecond)
{
int ret ;
fd_set rec_fdset;
struct timeval rec_timeout ;
rec_timeout.tv_sec = usecond/1000;
rec_timeout.tv_usec = usecond%1000;
ret = 0;
if (fd <= 0)
return 0;
FD_ZERO(&rec_fdset);
FD_CLR(fd, &rec_fdset);
FD_SET(fd, &rec_fdset);
if((select(fd+1, &rec_fdset, 0, 0, &rec_timeout))< 0)
{
return 0 ;
}
ret=FD_ISSET(fd , &rec_fdset);
return ret ;
}
int CheckSocketWrite(SOCKET fd, unsigned long usecond)
{
int ret ;
fd_set snd_fdset;
struct timeval rec_timeout ;
rec_timeout.tv_sec = usecond/1000;
rec_timeout.tv_usec = usecond%1000;
ret = 0;
if (fd <= 0)
return 0;
FD_ZERO(&snd_fdset);
FD_CLR(fd, &snd_fdset);
FD_SET(fd, &snd_fdset);
if((select(fd+1, 0, &snd_fdset, 0, &rec_timeout))< 0)
{
return 0 ;
}
ret=FD_ISSET(fd , &snd_fdset);
return ret ;
}
int input_timeout (int filedes, unsigned int useconds)
{
fd_set set;
struct timeval timeout;
/* Initialize the file descriptor set. */
FD_ZERO (&set);
FD_SET (filedes, &set);
/* Initialize the timeout data structure. */
timeout.tv_sec = useconds/1000;
timeout.tv_usec = useconds%1000;
/* select returns 0 if timeout, 1 if input available, -1 if error. */
return TEMP_FAILURE_RETRY (select (FD_SETSIZE,
&set, NULL, NULL,
&timeout));
}
#include <stdarg.h>
void SPYERROR( char *pszMsg, ... )
{
static unsigned long count=0;
static char pszErr[ 1024 ];
char *msgstart=NULL;
sprintf(pszErr," Error[%06ld]:",++count);
msgstart=pszErr+strlen(pszErr);
va_list args;
va_start( args, pszMsg );
vsprintf( msgstart, pszMsg, args ); pszErr[ 1023 ] = '\0';
va_end( args );
strcat(pszErr,"\n");
printf(pszErr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -