Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef WIN32_LEAN_AND_MEAN
- #define WIN32_LEAN_AND_MEAN
- #endif
- #include "stdafx.h"
- #include <windows.h>
- #include <iostream>
- #include <string>
- #include <winsock2.h>
- #include <ws2tcpip.h>
- #include <stdio.h>
- #pragma comment(lib, "Ws2_32.lib")
- using namespace std;
- int main(int argc, char *argv[])
- {
- int a = 0;
- while (a == 0) {
- WSADATA wsaData;
- int iResult;
- iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
- if (iResult != 0) {
- printf("WSAStartup failed: %d\n", iResult);
- }
- struct addrinfo *result = NULL,
- *ptr = NULL,
- hints;
- ZeroMemory(&hints, sizeof(hints));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
- #define DEFAULT_PORT "6667"
- iResult = getaddrinfo(argv[1], DEFAULT_PORT, &hints, &result);
- if (iResult != 0) {
- printf("getaddrinfo failed: %d\n", iResult);
- WSACleanup();
- return 1;
- }
- SOCKET ConnectSocket = INVALID_SOCKET;
- ptr = result;
- ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype,
- ptr->ai_protocol);
- if (ConnectSocket == INVALID_SOCKET) {
- printf("Error at socket(): %ld\n", WSAGetLastError());
- freeaddrinfo(result);
- WSACleanup();
- return 1;
- }
- iResult = connect(ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
- if (iResult == SOCKET_ERROR) {
- closesocket(ConnectSocket);
- ConnectSocket = INVALID_SOCKET;
- }
- cout << "working";
- cin >> a;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement