~cpp 트 행 하 한. 2000~3000 트 한 한. // 한 C++ C 한 3 . // 6000~9000 ... // C++ C 0.8 . // 클 해 클 . : IRC bot : irc 해 하 . & AI(할 AI 패) bot OS : Linux Language : C & Linux System Function : . : Zombie Process System Call 한. 1. Client Console 하 IRC Server 한. -> Main Process 2. PING -> 1 Child Process 3. 하 -> 2 Chile Process (3 Master 하 -> Private 패 IP .) main.c -> IRC Server 할 하 한. parse.c -> IRC Server 파한. file.c -> 파 함 Log하 한. 하한. request.c -> IRC Server PING 한 PONG . bot.c -> 한 함. attack_#.c(# == ) -> 함. 크하 하 함 . // 향 트크 . connect.c -> 트크 . // . (2 한 퓨 하...) 할 : main , parse PING , request 파 해. 파 ! . // signal . // fork 한.
~cpp // 하 파. 파 파 . // 해 . // #linux . // 파 privmsg process call mirc 해 함. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <unistd.h> #include <arpa/inet.h> #define MSG_MAX 1024 #define NICK "whoami_" #define HOST "irc.hanirc.org" #define PORT "6667" void error_handling(char *msg); void handler(int sig); typedef struct _info{ char *nick; char *host; char *port; char *user_name; char *user_whois1; char *user3; char *user_whois2; } INFO; INFO info = {NICK, HOST, PORT, "a", "b", "c", "d"}; int main(int argc, char *argv[]) { int sockfd; struct sockaddr_in ina; struct sigaction act; struct hostent *h; pid_t pid; char msg[MSG_MAX]; int msg_len; char check_ping[7]; char pong[11]; int join_flag = 0; sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if(sockfd == -1) error_handling("socket() error: sockfd"); h = gethostbyname(info.host); memset(&ina, 0, sizeof(ina)); ina.sin_family = AF_INET; ina.sin_addr = *(struct in_addr *)h->h_addr_list[0]; ina.sin_port = htons(atoi(info.port)); if(connect(sockfd, (struct sockaddr *)&ina, sizeof(ina)) == -1) error_handling("connect() error: "); act.sa_handler = handler; sigemptyset(&act.sa_mask); act.sa_flags = 0; sigaction(SIGCHLD, &act, 0); pid = fork(); if(pid == -1) error_handling("fork() error: "); else if(pid == 0){ while(1){ msg_len = recv(sockfd, msg, MSG_MAX-1, 0); if(msg_len > 0){ msg[msg_len] = ''; printf(msg); } if(strstr(msg, "NOTICE AUTH :*** Checking Ident") != NULL){ sleep(1); sprintf(msg, "user %s %s %s %sn", info.user_name, info.user_whois1, info.user3, info.user_whois2); send(sockfd, msg, strlen(msg), 0); sprintf(msg, "NICK %sn", info.nick); send(sockfd, msg, strlen(msg), 0); printf("Connect Initialization Succeed!n"); } else{ sscanf(msg, "%6c%s",check_ping, pong); if(strncmp(check_ping, "PING :", 6) == 0){ sprintf(msg, "PONG %sn", pong); send(sockfd, msg, strlen(msg), 0); if(join_flag == 0){ sleep(1); join_flag = 1; send(sockfd, "join #linuxn", 12, 0); } } } msg[0] = ''; } exit(0); } else{ fprintf(stderr, "Child Process Created!: pid = %dn", pid); } while(1){ fgets(msg, MSG_MAX, stdin); send(sockfd, msg, strlen(msg), 0); if(strcmp(msg, "quitn") == 0) break; } kill(0, SIGKILL); // 하 한. return 0; } void error_handling(char *msg) { fprintf(stderr, "%sn", msg); exit(-1); } void handler(int sig) { pid_t pid; int last; pid = waitpid(-1, &last, WNOHANG); fprintf(stderr, "Child Process Closed!: pid = %d, WEXITSTATUS = %Xn", pid, WEXITSTATUS(last)); }