pobri19
October 29th, 2008, 03:43 PM
Basically I'm just trying to make a client program to connect to an IRC server atm but I can't figure out why this won't work. WSAGetLastError continously returns the error 10047 at the call to connect() when I enter "irc.gamesurge.net 6667" as the first and second parameter.
10047:
WSAEAFNOSUPPORT
0x273F
An address incompatible with the requested protocol was used.
Here's the code: #include <iostream>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <cstring>
#include <Mstcpip.h>
using namespace std;
WSADATA wsaData;
int main(int argc, char * argv[]) {
int wsaReturnVal = WSAStartup(MAKEWORD(1, 1), &wsaData);
if (wsaReturnVal) {
printf("Error number: %d", wsaReturnVal);
exit(1);
}
struct addrinfo hints, *res = NULL;
SOCKET sockfd;
memset(&hints, 0, sizeof(addrinfo));
memset(&res, 0, sizeof(addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
getaddrinfo(argv[1], argv[2], &hints, &res);
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (sockfd == SOCKET_ERROR) {
printf("connect error %d", WSAGetLastError());
exit(1);
}
if (connect(sockfd, (struct sockaddr *)res, sizeof(addrinfo)) == SOCKET_ERROR) {
printf("connect error %d", WSAGetLastError());
exit(1);
}
printf("Connected to IRC server...");
closesocket(sockfd);
if (WSACleanup()) {
printf("cleanup %d", WSAGetLastError());
exit(1);
}
}
10047:
WSAEAFNOSUPPORT
0x273F
An address incompatible with the requested protocol was used.
Here's the code: #include <iostream>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <cstring>
#include <Mstcpip.h>
using namespace std;
WSADATA wsaData;
int main(int argc, char * argv[]) {
int wsaReturnVal = WSAStartup(MAKEWORD(1, 1), &wsaData);
if (wsaReturnVal) {
printf("Error number: %d", wsaReturnVal);
exit(1);
}
struct addrinfo hints, *res = NULL;
SOCKET sockfd;
memset(&hints, 0, sizeof(addrinfo));
memset(&res, 0, sizeof(addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
getaddrinfo(argv[1], argv[2], &hints, &res);
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (sockfd == SOCKET_ERROR) {
printf("connect error %d", WSAGetLastError());
exit(1);
}
if (connect(sockfd, (struct sockaddr *)res, sizeof(addrinfo)) == SOCKET_ERROR) {
printf("connect error %d", WSAGetLastError());
exit(1);
}
printf("Connected to IRC server...");
closesocket(sockfd);
if (WSACleanup()) {
printf("cleanup %d", WSAGetLastError());
exit(1);
}
}