C语言实现带自定义超时时间的telnet端口连通性检测功能

#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");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值