mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-27 12:05:15 +00:00
Verify IP, send correct IP and MTU to client
This commit is contained in:
parent
df8c508f77
commit
fa408ad749
20
iodined.c
20
iodined.c
@ -45,6 +45,9 @@ int outid;
|
|||||||
|
|
||||||
struct query q;
|
struct query q;
|
||||||
|
|
||||||
|
int my_mtu;
|
||||||
|
in_addr_t my_ip;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sigint(int sig) {
|
sigint(int sig) {
|
||||||
running = 0;
|
running = 0;
|
||||||
@ -56,6 +59,8 @@ tunnel(int tun_fd, int dns_fd)
|
|||||||
int i;
|
int i;
|
||||||
int read;
|
int read;
|
||||||
int code;
|
int code;
|
||||||
|
int ipadder;
|
||||||
|
struct in_addr nextip;
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
char in[64*1024];
|
char in[64*1024];
|
||||||
@ -106,7 +111,15 @@ tunnel(int tun_fd, int dns_fd)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(in[0] == 'H' || in[0] == 'h') {
|
if(in[0] == 'H' || in[0] == 'h') {
|
||||||
read = snprintf(out, sizeof(out), "%s-%d", "172.30.5.2", 1023);
|
ipadder = htonl(my_ip); // To get the last byte last
|
||||||
|
if ((ipadder & 0xFF) == 0xFF) {
|
||||||
|
// IP ends with 255.
|
||||||
|
ipadder--;
|
||||||
|
} else {
|
||||||
|
ipadder++;
|
||||||
|
}
|
||||||
|
nextip.s_addr = ntohl(ipadder);
|
||||||
|
read = snprintf(out, sizeof(out), "%s-%d", inet_ntoa(nextip), my_mtu);
|
||||||
dnsd_send(dns_fd, &q, out, read);
|
dnsd_send(dns_fd, &q, out, read);
|
||||||
q.id = 0;
|
q.id = 0;
|
||||||
} else if((in[0] >= '0' && in[0] <= '9')
|
} else if((in[0] >= '0' && in[0] <= '9')
|
||||||
@ -254,7 +267,10 @@ main(int argc, char **argv)
|
|||||||
goto cleanup1;
|
goto cleanup1;
|
||||||
if ((dnsd_fd = open_dns(argv[1], 53)) == -1)
|
if ((dnsd_fd = open_dns(argv[1], 53)) == -1)
|
||||||
goto cleanup2;
|
goto cleanup2;
|
||||||
|
|
||||||
|
my_ip = inet_addr(argv[0]);
|
||||||
|
my_mtu = mtu;
|
||||||
|
|
||||||
printf("Listening to dns for domain %s\n", argv[1]);
|
printf("Listening to dns for domain %s\n", argv[1]);
|
||||||
|
|
||||||
if (newroot) {
|
if (newroot) {
|
||||||
|
4
tun.c
4
tun.c
@ -155,7 +155,7 @@ tun_setip(const char *ip)
|
|||||||
{
|
{
|
||||||
char cmdline[512];
|
char cmdline[512];
|
||||||
|
|
||||||
if (inet_addr(ip) != 0) {
|
if (inet_addr(ip) != INADDR_NONE) {
|
||||||
snprintf(cmdline, sizeof(cmdline),
|
snprintf(cmdline, sizeof(cmdline),
|
||||||
"/sbin/ifconfig %s %s netmask 255.255.255.0",
|
"/sbin/ifconfig %s %s netmask 255.255.255.0",
|
||||||
if_name,
|
if_name,
|
||||||
@ -176,6 +176,8 @@ tun_setip(const char *ip)
|
|||||||
printf("Adding route %s/24 to %s\n", ip, ip);
|
printf("Adding route %s/24 to %s\n", ip, ip);
|
||||||
#endif
|
#endif
|
||||||
return system(cmdline);
|
return system(cmdline);
|
||||||
|
} else {
|
||||||
|
printf("Invalid IP: %s!\n", ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user