Last active
May 31, 2016 08:27
-
-
Save Jinmo/7eb5a9f2b488d3bbf4ec to your computer and use it in GitHub Desktop.
소켓 데몬 너무 디버깅하기 싫어서 만든 별것 아닌 것
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/socket.h> | |
#include <sys/types.h> | |
#include <arpa/inet.h> | |
#include <strings.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
int main(int argc, char **argv, char **envp) { | |
char buf[256]; | |
int sockfd = socket(2, 1, 0); | |
struct sockaddr_in addr; | |
int size = sizeof(addr); | |
int pid; | |
bzero(&addr, size); | |
addr.sin_port = htons(atoi(argv[1])); | |
addr.sin_addr.s_addr = INADDR_ANY; | |
addr.sin_family = 2; | |
bind(sockfd, (struct sockaddr *)&addr, size); | |
listen(sockfd, 0); | |
while(1) { | |
int fd = accept(sockfd, (struct sockaddr *)&addr, &size); | |
if((pid = fork()) == 0) { | |
printf("my pid: %d\n", getpid()); | |
dup2(fd, 0); | |
dup2(fd, 1); | |
dup2(fd, 2); | |
execve(argv[2], &argv[2], envp); | |
} else { | |
close(fd); | |
sprintf(buf, "%d", pid); | |
execl("/usr/bin/gdb", "gdb", "-p", buf, NULL); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
방명록남기고갑니다