#include #include #include #include #include #include #include #include #include #define host "irc.smashthestack.org" #define port 6667 int main(int argc, char **argv) { int bytes; int sock; char buf[512]; struct hostent *he; struct sockaddr_in the_addr; he = gethostbyname(host); if((sock = socket(PF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } the_addr.sin_family = AF_INET; the_addr.sin_port = htons(port); the_addr.sin_addr = *((struct in_addr *)he->h_addr); memset(&(the_addr.sin_zero), '\0', 8); if(connect(sock, (struct sockaddr *)&the_addr, sizeof(struct sockaddr)) == -1) { perror("connect"); exit(1); } char blah[] = "NICK test\nUSER test test test :test\n"; send(sock, blah, strlen(blah), 0); while(1) { recv(sock, buf, 512, 0); if(strncmp("PING", buf, 4) == 0) { printf("received ping.. sending pong\n"); buf[1] = 'O'; send(sock, buf, strlen(buf), 0); } } return 0; }