📄 connection.c,v
字号:
head 1.1;access;symbols;locks; strict;comment @ * @;1.1date 2002.11.02.17.24.32; author nelak; state Exp;branches;next ;desc@@1.1log@*** empty log message ***@text@#include <stdio.h>#include <winsock2.h>#include "Connection.h"#include <md5.h> /**********************/ /*Connecting to server*//**********************/int Connect(const char *User,const unsigned char *Password,const char *Server,const int *Port){char *md5;int nRet;LPHOSTENT lpHostEntry;SOCKET MProtocol;int CmdNum=0;char Command[512];char *MyCommand;WSAData wsaData;if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) { printf("WSAStartup failed.\n"); } else printf("Initializing Connection\n");MProtocol = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);if (MProtocol == INVALID_SOCKET) { printf("Error at socket()"); WSACleanup(); return 1; }printf("%s\n",Server);lpHostEntry = gethostbyname(Server); // Specifying server by its nameif (lpHostEntry == NULL) { printf("Error at gethostbyname()"); WSACleanup(); return 1; }SOCKADDR_IN MsnServer;MsnServer.sin_family = AF_INET;MsnServer.sin_addr.s_addr = inet_addr("64.4.13.246");// ^ Address of the server being inserted into the address fieldMsnServer.sin_port = htons(1863);printf("%d\n",MsnServer.sin_addr);nRet = connect(MProtocol,(LPSOCKADDR)&MsnServer,sizeof(struct sockaddr));if (nRet == SOCKET_ERROR) { printf("Error at connect()"); WSACleanup(); return 1; } else printf("Connection open\n");/*md5sum(md5,Password);printf("%s",md5);*/sprintf(Command,"VER %d MSNP7 MSNP6 MSNP5 MSNP4 CVR0\r\n",CmdNum++);printf("%d\n",strlen(Command));nRet = send(MProtocol, // Pretend this is connected Command, // Our string buffer strlen(Command), // Length of the data in the buffer 0); // Most often is 0, but see end of tutorial for optionsprintf("%s\n",Command);if (nRet == SOCKET_ERROR) { printf("Error on send()\n"); return 0;}if ((nRet = recv(MProtocol,Command,sizeof(Command),0)) ==-1) { printf("Connection Error\n"); }printf("%s\n",Command);sprintf(Command,"INF %d\r\n",CmdNum++);printf("%s\n",Command);printf("%d\n",strlen(Command));if ((nRet = send(MProtocol, // Pretend this is connected Command, // Our string buffer strlen(Command), // Length of the data in the buffer 0)) ==-1) { printf("Connection Error\n"); } // Most often is 0, but see end of tutorial for optionsif ((nRet = recv(MProtocol,Command,sizeof(Command),0)) ==-1) { printf("Connection Error\n"); }printf("%s\n",Command);sprintf(Command,"USR %d MD5 I %s\r\n",CmdNum++,User);printf("%s\n",Command);printf("%d\n",strlen(Command));if ((nRet = send(MProtocol, // Pretend this is connected Command, // Our string buffer strlen(Command), // Length of the data in the buffer 0)) ==-1) { printf("Connection Error\n"); } // Most often is 0, but see end of tutorial for optionsif ((nRet = recv(MProtocol,Command,sizeof(Command),0)) ==-1) { printf("Connection Error\n"); }printf("%s\n",Command);md5=&Command[12];*(md5+16)='\0';sprintf(md5,"%s",md5);printf("%s\n",md5);MD5String(md5);sprintf(Command,"USR %d MD5 S %s \r\n",CmdNum++,md5);printf("%s\n",Command);printf("%d\n",strlen(Command));if ((nRet = send(MProtocol, // Pretend this is connected Command, // Our string buffer strlen(Command), // Length of the data in the buffer 0)) ==-1) { printf("Connection Error\n"); } // Most often is 0, but see end of tutorial for optionsif ((nRet = recv(MProtocol,Command,sizeof(Command),0)) ==-1) { printf("Connection Error\n"); }printf("%s\n",Command);closesocket(MProtocol); // // Shutdown Winsock //WSACleanup();return 0;}/*End Connect*/@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -