/* Barebones IRC Skeleton */ #include /* printf() */ #include /* socket(), connect(), send(), recv() */ #include /* sockaddr_in, inet_addr() */ #include /* atoi() */ #include /* memset() */ #include /* 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 [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); }