All pastes #963021 Raw Edit

nano

public cpp v1 · immutable
#963021 ·published 2008-03-30 05:02 UTC
rendered paste body
#include <windows.h>#include <winsock.h>#include <stdio.h>#include "resource.h"#include <string.h>#define PORT 6667LRESULT CALLBACK ClientDlgProc(HWND DialogWindow, UINT Message, WPARAM wParam, LPARAM lParam){	switch(Message)	{	case WM_COMMAND:		{		switch(wParam)		{			case IDC_Connect:			{			WSADATA WSAData;			WSAStartup(MAKEWORD(2,0), &WSAData);  //Winsock 2.0			SOCKET connection;//this is a socket named 'connection'			SOCKADDR_IN sin;			connection = socket(AF_INET, SOCK_STREAM, 0); //'connection' is a stream socket			struct hostent *he;			char iptext[100];			{				HWND a = GetDlgItem(DialogWindow,IDC_ADDRESS); 				GetWindowText(a,iptext,sizeof(iptext)); }				if ((he = gethostbyname(iptext)) == NULL) //get the ip of parameter 1 in command prompt				{					perror("gethostbyname"); //if there is a problem in gethostbyname, print the error					exit(EXIT_FAILURE);				}				sin.sin_addr			= *((struct in_addr *)he->h_addr); //address to connect to				sin.sin_family			= AF_INET;						   //potocol AF_INET is everything				sin.sin_port			= htons(PORT);                     //the port the irc server has open for connections				memset(&(sin.sin_zero), '\0', 8);				char *nick		= "NICK nanoobot\r\n"; 				char *channel	= "JOIN #winapi\r\n"; 				char *user      = "USER nanoobot nanoobot nanoobot :nanoobot bot\r\n";				char *entermsg  = "PRIVMSG #test :[-]![-]\r\n";				char *exitmsg	= "PRIVMSG #test :[-]Exit...[-]\r\n";				char buf[512];				connect(connection, (SOCKADDR*)&sin, sizeof(sin));								send(connection,nick,strlen(nick),0);				send(connection,user,strlen(user),0);				do				{					recv(connection,buf,512,0);					if (strncmp("PING", buf, 4) == 0)					{							SetDlgItemText(DialogWindow, IDC_StatusBox, "Connected and sending PONGS.");												buf[1] = 'O';						send(connection, buf, strlen(buf), 0);					}					if (strncmp("End of /MOTD command.", buf, sizeof(buf)))					{						send(connection,channel,strlen(channel),0);							Sleep(1000);					}					break;SetDlgItemText(DialogWindow, IDC_StatusBox, buf);				}while(1);			}		}		default:			break;		}		break;	}	return FALSE;}int APIENTRYWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdline, int nCmdShow){	DialogBox((HINSTANCE) hInstance, MAKEINTRESOURCE(IDD_CLIENT), NULL, (DLGPROC) ClientDlgProc);	return 0;}