1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
int main()
{
WSADATA wsaData;
int iResult;
DWORD dwError;
SOCKET sock;
struct hostent *remoteHost;
struct sockaddr_in server;
char host_name[] = "irc.chat.twitch.tv";
struct in_addr addr;
char **pAlias;
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
printf("WSAStartup failed: %d\n", iResult);
return 1;
}
printf("Calling gethostbyname with %s\n", host_name);
remoteHost = gethostbyname(host_name);
if (!remoteHost)
{
printf("Failled to get %s(s) host by name... Error: %d\n", host_name, WSAGetLastError());
getch();
exit(1);
}
printf("Successfully retrieved host by name...\n");
int i = 0;
while (remoteHost->h_addr_list[i] != 0)
{
addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++];
printf("\tIP Address #%d: %s\n", i, inet_ntoa(addr));
}
char *ipaddr = inet_ntoa(addr);
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET)
{
printf("Socket == Invalid_Socket...\n");
getch();
exit(1);
}
printf("Gathered All IP Adresses... Using %s\n", ipaddr);
ZeroMemory(&server, sizeof(&server));
server.sin_addr.s_addr = inet_addr(ipaddr);
server.sin_family = AF_INET;
server.sin_port = htons(6667);
if (connect(sock, (struct sockaddr *)&server, sizeof(server)) == 0)
{
printf("Connected to %s OR %s...\n", host_name, ipaddr);
Sleep(2000);
printf("Trying: PASS securityreasons\nNICK ircbot");
send(sock, "PASS securityreasons\n", strlen("PASS securityreasons") + 1, 0);
send(sock, "NICK ircbot\n", strlen("ircbot") + 1, 0);
int mret; char *rbuf;
while (true)
{
ZeroMemory(&rbuf, sizeof(rbuf));
mret = recv(sock, rbuf, sizeof(rbuf), 0);
if (!mret)
{
printf("Connection broke...\n");
getch();
exit(1);
}
else
{
if(rbuf)
printf("%s\n", rbuf);
}
Sleep(700);
}
}
else
{
printf("Failed to connect!\n");
}
getch();
return 0;
}
| |