mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-22 16:19:20 +02:00
nonworking read of dns reply
This commit is contained in:
parent
e1c0a595df
commit
43787fae12
21
dns.c
21
dns.c
|
@ -33,6 +33,7 @@
|
|||
static int host2dns(const char *, char *, int);
|
||||
|
||||
struct sockaddr_in peer;
|
||||
char topdomain[256];
|
||||
|
||||
int
|
||||
open_dns()
|
||||
|
@ -87,9 +88,9 @@ dns_set_peer(const char *host)
|
|||
}
|
||||
|
||||
void
|
||||
dns_ping()
|
||||
dns_ping(int dns_fd)
|
||||
{
|
||||
|
||||
dns_query(dns_fd, "kryo.se", 1);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -128,6 +129,22 @@ dns_query(int fd, char *host, int type)
|
|||
sendto(fd, buf, len+1, 0, (struct sockaddr*)&peer, peerlen);
|
||||
}
|
||||
|
||||
int
|
||||
dns_read(int fd, char *buf, int len)
|
||||
{
|
||||
int r;
|
||||
int fromlen;
|
||||
struct sockaddr_in from;
|
||||
|
||||
r = recvfrom(fd, buf, len, 0, (struct sockaddr*)&from, &fromlen);
|
||||
if (r < 0) {
|
||||
perror("recvfrom");
|
||||
}
|
||||
printf("Read %d bytes DNS reply\n", r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
host2dns(const char *host, char *buffer, int size)
|
||||
{
|
||||
|
|
3
dns.h
3
dns.h
|
@ -25,8 +25,9 @@ int open_dns();
|
|||
void close_dns(int);
|
||||
|
||||
void dns_set_peer(const char *);
|
||||
void dns_ping();
|
||||
void dns_ping(int);
|
||||
void dns_query(int, char *, int);
|
||||
int dns_read(int, char *, int);
|
||||
|
||||
|
||||
#endif /* _DNS_H_ */
|
||||
|
|
11
dnstun.c
11
dnstun.c
|
@ -18,6 +18,8 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "tun.h"
|
||||
|
@ -38,7 +40,11 @@ tunnel(int tun_fd, int dns_fd)
|
|||
int i;
|
||||
fd_set fds;
|
||||
struct timeval tv;
|
||||
char buf[1024];
|
||||
int buflen;
|
||||
int read;
|
||||
|
||||
buflen = 1024;
|
||||
while (running) {
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
|
@ -55,13 +61,13 @@ tunnel(int tun_fd, int dns_fd)
|
|||
}
|
||||
|
||||
if(i == 0) {
|
||||
dns_ping();
|
||||
dns_ping(dns_fd);
|
||||
} else {
|
||||
if(FD_ISSET(tun_fd, &fds)) {
|
||||
|
||||
}
|
||||
if(FD_ISSET(dns_fd, &fds)) {
|
||||
|
||||
read = dns_read(dns_fd, buf, buflen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +87,6 @@ main()
|
|||
signal(SIGINT, sigint);
|
||||
|
||||
dns_set_peer("192.168.11.101");
|
||||
dns_query(dns_fd, "kryo.se", 1);
|
||||
|
||||
tunnel(tun_fd, dns_fd);
|
||||
|
||||
|
|
Loading…
Reference in New Issue