mirror of
https://github.com/yarrick/iodine.git
synced 2024-12-28 02:27:48 +00:00
handles errors from tun and dns(d)
This commit is contained in:
parent
b9a14dcae2
commit
02763e9a84
10
dns.c
10
dns.c
@ -70,7 +70,7 @@ open_dns(const char *host, const char *domain)
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(fd < 0) {
|
||||
warn("socket");
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
flag = 1;
|
||||
@ -81,7 +81,7 @@ open_dns(const char *host, const char *domain)
|
||||
|
||||
if(bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
warn("bind");
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Opened UDP socket\n");
|
||||
@ -91,7 +91,7 @@ open_dns(const char *host, const char *domain)
|
||||
h = gethostbyname(host);
|
||||
if (!h) {
|
||||
printf("Could not resolve name %s, exiting\n", host);
|
||||
exit(9);
|
||||
return -1;
|
||||
}
|
||||
bzero(&peer, sizeof(peer));
|
||||
peer.sin_family = AF_INET;
|
||||
@ -124,7 +124,7 @@ open_dnsd(const char *domain)
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(fd < 0) {
|
||||
warn("socket");
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
flag = 1;
|
||||
@ -135,7 +135,7 @@ open_dnsd(const char *domain)
|
||||
|
||||
if(bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
warn("bind");
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Opened UDP socket\n");
|
||||
|
8
iodine.c
8
iodine.c
@ -185,8 +185,10 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
tun_fd = open_tun();
|
||||
dns_fd = open_dns(argv[0], argv[1]);
|
||||
if ((tun_fd = open_tun()) == -1)
|
||||
goto cleanup1;
|
||||
if ((dns_fd = open_dns(argv[0], argv[1])) == -1)
|
||||
goto cleanup2;
|
||||
|
||||
signal(SIGINT, sigint);
|
||||
|
||||
@ -215,7 +217,9 @@ main(int argc, char **argv)
|
||||
|
||||
printf("Closing tunnel\n");
|
||||
|
||||
cleanup2:
|
||||
close_dns(dns_fd);
|
||||
cleanup1:
|
||||
close_tun(tun_fd);
|
||||
|
||||
return 0;
|
||||
|
@ -187,8 +187,11 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
tun_fd = open_tun();
|
||||
dnsd_fd = open_dnsd(argv[0]);
|
||||
if ((tun_fd = open_tun()) == -1)
|
||||
goto cleanup1;
|
||||
if ((dnsd_fd = open_dnsd(argv[0])) == -1)
|
||||
goto cleanup2;
|
||||
|
||||
|
||||
if (newroot) {
|
||||
if (chroot(newroot) != 0 || chdir("/") != 0)
|
||||
@ -214,7 +217,9 @@ main(int argc, char **argv)
|
||||
|
||||
tunnel(tun_fd, dnsd_fd);
|
||||
|
||||
cleanup2:
|
||||
close_dnsd(dnsd_fd);
|
||||
cleanup1:
|
||||
close_tun(tun_fd);
|
||||
|
||||
return 0;
|
||||
|
12
tun.c
12
tun.c
@ -49,7 +49,7 @@ open_tun()
|
||||
|
||||
if ((tun_fd = open(tun_device, O_RDWR)) < 0) {
|
||||
warn("open_tun: %s: %s", tun_device, strerror(errno));
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bzero(&ifreq, sizeof(ifreq));
|
||||
@ -66,14 +66,13 @@ open_tun()
|
||||
|
||||
if (errno != EBUSY) {
|
||||
warn("open_tun: ioctl[TUNSETIFF]: %s", strerror(errno));
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
warn("open_tun: Couldn't set interface name.\n");
|
||||
exit(1);
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#else /* BSD */
|
||||
@ -88,7 +87,7 @@ open_tun()
|
||||
if (tun_device != NULL) {
|
||||
if ((tun_fd = open(tun_device, O_RDWR)) < 0) {
|
||||
warn("open_tun: %s: %s", tun_device, strerror(errno));
|
||||
exit(1);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < TUN_MAX_TRY; i++) {
|
||||
@ -104,10 +103,9 @@ open_tun()
|
||||
}
|
||||
|
||||
warn("open_tun: Failed to open tunneling device.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif /* LINUX */
|
||||
|
Loading…
x
Reference in New Issue
Block a user