该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
/*
Protocol of connection
Connect : CONN
Connected Success : SUCC
Reboot : REBT 暂时不可用
Upload : UPLD
Download : DNLD
Destroy : DTOY 暂时不可用
Help : HELP 暂时不可用
OK : START TO TRANSFER FILE
DoneTrans : Finish Transferring
*/
#include
#include
#include
#define CONNECT 0
#define LISTEN 1
#define ACCEPT 2
#define 加载WSA() LoadWSA()
#define 初始化套接字(地址的指针,设置,链接阵列,监听中的套接字) LoadSOCKET(地址的指针,设置,链接阵列,监听中的套接字)
#define 发送(套接字,缓冲区,数据长度) WSASend(套接字,缓冲区,数据长度)
#define 接受(套接字,数据长度) WSARecv(套接字,数据长度)
#define CONNECT 0
#define LISTEN 1
#define ACCEPT 2
#define INVALID_SETTING -50 //参数错误
#define MAXIMUM 65535
#define MINIMUM 1
#define READ 0
#define WRITE 1
#pragma comment(lib,"ws2_32.lib")
SOCKET sock;
HANDLE hReadWrite1[2];
HANDLE hReadWrite2[2];
STARTUPINFO SI;
SECURITY_ATTRIBUTES sa;
struct sockaddr_in saddr;
struct hostent *host;
long Bytes;
FILE fp;
int LoadWSA()//加载Winsock库
{
WSADATA wd;
if(WSAStartup(0x0202,&wd)!=0)//加载失败时返回WSA错误码
{
return(WSAGetLastError());
}
return 0;//否则返回0
}
SOCKET LoadSOCKET(struct sockaddr_in *saddr,int SET,int array,SOCKET ListenSocket)
{
SOCKET sock;
int size=sizeof(struct sockaddr);
if(SET<2)//如果传入设置为ACCEPT
{
sock=socket(AF_INET,SOCK_STREAM,0);
}
if(saddr=NULL)//传入空白的saddr
{
return -50;
}
switch(SET)
{
case 0://如果为CONNECT
{
if(connect(sock,(struct sockaddr*)&saddr,sizeof(struct sockaddr))<0)
{
return NULL;
}
}
case 1://如果为LISTEN