All pastes #501788 Raw Edit

Mine

public c v1 · immutable
·published 2007-05-22 06:32 UTC
rendered paste body
/* Barebones IRC Skeleton */#include <stdio.h> 	/* printf() */#include <sys/socket.h> /* socket(), connect(), send(), recv() */#include <arpa/inet.h>  /* sockaddr_in, inet_addr() */#include <stdlib.h>	/* atoi() */#include <string.h>	/* memset() */#include <unistd.h>	/* close() */void DieWithError(char *errorMsg); /* prints error msg and exits */int main( int argc, char *argv[] ){	int sock;				/* the socket */	int inCommand;				/* internal commands *not sent to server* */	struct sockaddr_in ircServerAddr;	/* irc server address */	unsigned short ircServerPort;		/* irc server port */	char *serverIp;				/* x.x.x.x */	char *sendMsg;				/* string to send to irc server */	unsigned int sendMsgLen;		/* len of send message */		if ((argc < 2) || (argc > 3))	{		fprintf(stderr, "Usage: %s <IRC Server IP> [port]\n", argv[0]);		exit(1);	}		serverIp = argv[1]; 			/* first arg; required server ip */		if (argc == 3)		ircServerPort = atoi(argv[2]);	/* use provided port */	else		ircServerPort = 6667;		/* or use standard irc port */		/* create socket */	if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)		DieWithError("couldn't make socket");			/* fill ircServerAddr struct */	memset(&ircServerAddr, 0, sizeof(ircServerAddr)); 	/* zero the struct */	ircServerAddr.sin_family	= AF_INET;		/* internet address family */	ircServerAddr.sin_addr.s_addr	= inet_addr(serverIp);  /* server ip */	ircServerAddr.sin_port		= htons(ircServerPort); /* http://retran.com/beej/htonsman.html */		/* connect to the IRC server */	if (connect(sock, (struct sockaddr *) &ircServerAddr, sizeof(ircServerAddr)) < 0)		DieWithError("couldn't connect to serv");						   	sendMsg = "USER Ceegie Ceegie Ceegie :Ceegie\r\nNICK Ceegie\r\nJOIN #LLJKLLJK\r\n";	sendMsgLen = strlen(sendMsg);				/* size up the send message */		/* send the string to the server */	if (send(sock, sendMsg, sendMsgLen, 0) != sendMsgLen)		DieWithError("unexpected number of bytes sent");			/*and close w/out sending QUIT :hurrrrr*/	close(sock);}void DieWithError(char *errorMsg){    fprintf(stderr, "%s\n", errorMsg);    exit(1);}