Skip to content

Commit

Permalink
Merge pull request #13 from jjungo/fix_12_segfault
Browse files Browse the repository at this point in the history
Fix #12 Segmentation fault
  • Loading branch information
DhavalKapil committed Dec 18, 2015
2 parents cbe99ba + 72abb9e commit 7a1a5a8
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions icmptunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,34 @@
#include <stdio.h>
#include <stdlib.h>

#define ARG_SERVER_MODE "-s"
#define ARG_CLIENT_MODE "-c"

void usage()
{
printf("Wrong argument\n");
fprintf(stdout, "usage: icmptunnel [-s serverip] | [-c clientip]\n");
}

int main(int argc, char *argv[])
{
char ip_addr[100] = {0,};
if ((strlen(argv[2]) + 1) > sizeof(ip_addr)){
perror("Bad ip argument\n");
exit(EXIT_FAILURE);
if ((argc < 3) || ((strlen(argv[2]) + 1) > sizeof(ip_addr))) {
usage();
exit(EXIT_FAILURE);
}
memcpy(ip_addr, argv[2], strlen(argv[2]) + 1);
run_tunnel(ip_addr, !strcmp(argv[1], "-s"));

if (strncmp(argv[1], ARG_SERVER_MODE, strlen(argv[1])) == 0) {
run_tunnel(ip_addr, 1);
}
else if (strncmp(argv[1], ARG_CLIENT_MODE, strlen(argv[1])) == 0) {
run_tunnel(ip_addr, 0);
}
else {
usage();
exit(EXIT_FAILURE);
}

return EXIT_SUCCESS;
}

0 comments on commit 7a1a5a8

Please sign in to comment.