Skip to content

Instantly share code, notes, and snippets.

@neuro-sys
Created November 6, 2012 13:48
Show Gist options
  • Select an option

  • Save neuro-sys/4024835 to your computer and use it in GitHub Desktop.

Select an option

Save neuro-sys/4024835 to your computer and use it in GitHub Desktop.
winsock
#include <stdio.h>
#include <Ws2tcpip.h>
#pragma comment (lib, "Ws2_32.lib")
int main()
{
WSADATA wsaData;
struct addrinfo hint;
struct addrinfo *res;
int sockfd;
WSAStartup(MAKEWORD(2,1), &wsaData);
memset(&hint, sizeof(hint), 0);
hint.ai_family = AF_UNSPEC;
hint.ai_protocol = SOCK_STREAM;
GetAddrInfo("irc.freenode.net", "6667", &hint, &res);
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
connect(sockfd, res->ai_addr, res->ai_addrlen);
WSACleanup();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment