mirror of
https://github.com/yarrick/iodine.git
synced 2024-12-23 05:43:32 +02:00
Now init peer and domain in open_dns(), use argv values
This commit is contained in:
parent
5eb02a4bdc
commit
ecb97656ab
3 changed files with 26 additions and 20 deletions
31
dns.c
31
dns.c
|
@ -83,11 +83,12 @@ readname(char *packet, char *dst, char *src)
|
|||
memcpy((dst), (src), (len)); (src)+=(len);
|
||||
|
||||
int
|
||||
open_dns()
|
||||
open_dns(const char *host, const char *domain)
|
||||
{
|
||||
int fd;
|
||||
int flag;
|
||||
struct sockaddr_in addr;
|
||||
struct hostent *h;
|
||||
|
||||
bzero(&addr, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
|
@ -113,6 +114,20 @@ open_dns()
|
|||
|
||||
printf("Opened UDP socket\n");
|
||||
|
||||
// Init dns target struct
|
||||
h = gethostbyname(host);
|
||||
if (!h) {
|
||||
perror("gethostbyname");
|
||||
}
|
||||
bzero(&peer, sizeof(peer));
|
||||
peer.sin_family = AF_INET;
|
||||
peer.sin_port = htons(53);
|
||||
peer.sin_addr = *((struct in_addr *) h->h_addr);
|
||||
|
||||
// Save top domain used
|
||||
strncpy(topdomain, domain, sizeof(topdomain) - 2);
|
||||
topdomain[sizeof(topdomain) - 1] = 0;
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
@ -122,22 +137,10 @@ close_dns(int fd)
|
|||
close(fd);
|
||||
}
|
||||
|
||||
void
|
||||
dns_set_peer(const char *host)
|
||||
{
|
||||
struct hostent *h;
|
||||
|
||||
h = gethostbyname(host);
|
||||
bzero(&peer, sizeof(peer));
|
||||
peer.sin_family = AF_INET;
|
||||
peer.sin_port = htons(53);
|
||||
peer.sin_addr = *((struct in_addr *) h->h_addr);
|
||||
}
|
||||
|
||||
void
|
||||
dns_ping(int dns_fd)
|
||||
{
|
||||
dns_query(dns_fd, "kryo.se", 1);
|
||||
dns_query(dns_fd, "4.kryo.se", 1);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
3
dns.h
3
dns.h
|
@ -19,10 +19,9 @@
|
|||
|
||||
extern struct sockaddr_in peer;
|
||||
|
||||
int open_dns();
|
||||
int open_dns(const char *, const char *);
|
||||
void close_dns(int);
|
||||
|
||||
void dns_set_peer(const char *);
|
||||
void dns_ping(int);
|
||||
void dns_query(int, char *, int);
|
||||
int dns_read(int, char *, int);
|
||||
|
|
12
dnstun.c
12
dnstun.c
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
@ -76,18 +77,21 @@ tunnel(int tun_fd, int dns_fd)
|
|||
}
|
||||
|
||||
int
|
||||
main()
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int tun_fd;
|
||||
int dns_fd;
|
||||
|
||||
if (argc != 3) {
|
||||
printf("Usage: %s nameserver topdomain\n", argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
tun_fd = open_tun();
|
||||
dns_fd = open_dns();
|
||||
dns_fd = open_dns(argv[1], argv[2]);
|
||||
|
||||
signal(SIGINT, sigint);
|
||||
|
||||
dns_set_peer("192.168.11.101");
|
||||
|
||||
tunnel(tun_fd, dns_fd);
|
||||
|
||||
printf("Closing tunnel\n");
|
||||
|
|
Loading…
Reference in a new issue