Skip to content

Instantly share code, notes, and snippets.

@Jinmo
Last active May 31, 2016 08:27
Show Gist options
  • Save Jinmo/7eb5a9f2b488d3bbf4ec to your computer and use it in GitHub Desktop.
Save Jinmo/7eb5a9f2b488d3bbf4ec to your computer and use it in GitHub Desktop.
소켓 데몬 너무 디버깅하기 싫어서 만든 별것 아닌 것
#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);
}
}
}
@jen6
Copy link

jen6 commented Sep 28, 2015

이게 뭔가여

@Jinmo
Copy link
Author

Jinmo commented Sep 28, 2015

./socat [port] [argv..]

@bunseokbot
Copy link

진짜 귀찮아 보이는구나

@iidx
Copy link

iidx commented Sep 28, 2015

방명록남기고갑니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment