// @Author=sys // @Comments=RIP Anthony "sys" King ~ debioll #include #include #include #include #include #include #define DSTADDR "irc.gamesurge.net" #define DSTPORT 6667 #define BUFF_SIZE 512 int main(int argc, char * argv[]) { struct hostent * canonical; canonical = gethostbyname(DSTADDR); if (!canonical) { printf("Unknown host: %s\r\n", DSTADDR); return 1; } int fd; fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { printf("Error creating socket.\r\n"); return 1; } struct sockaddr_in client; memset(&client, 0, sizeof client); client.sin_family = AF_INET; client.sin_port = htons(DSTPORT); memcpy(&client.sin_addr, canonical->h_addr, canonical->h_length); int eid; eid = connect(fd, (struct sockaddr *) &client, sizeof client); if (eid < 0) { printf("Error connecting socket.\r\n"); return 1; } char buff[BUFF_SIZE]; memset(buff, 0, sizeof buff); sprintf(buff, "NICK %s\r\n", "H2O"); send(fd, buff, strlen(buff), 0); memset(buff, 0, sizeof buff); sprintf(buff, "USER %s \"\" \"\" :%s\r\n", "svs", "c"); send(fd, buff, strlen(buff), 0); memset(buff, 0, sizeof buff); char pong[BUFF_SIZE]; while (recv(fd, buff, sizeof buff, 0) > 0) { if (sscanf(buff, "PING :%s", pong) > 0) { sprintf(buff, "PONG :%s\r\n", pong); send(fd, buff, strlen(buff), 0); } printf("-> %s\r\n", buff); memset(buff, 0, sizeof buff); } close(fd); return 0; }