Added set peer

This commit is contained in:
Erik Ekman 2006-06-05 14:13:32 +00:00
parent 5ff6d2228c
commit 66bc89019a
3 changed files with 20 additions and 1 deletions

15
dns.c
View File

@ -21,6 +21,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <arpa/nameser.h> #include <arpa/nameser.h>
#include <netdb.h>
#include <time.h> #include <time.h>
#include <err.h> #include <err.h>
#include <stdio.h> #include <stdio.h>
@ -31,6 +32,8 @@
#include "dns.h" #include "dns.h"
struct sockaddr_in peer;
int int
open_dns() open_dns()
{ {
@ -68,3 +71,15 @@ close_dns(int fd)
{ {
close(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);
}

4
dns.h
View File

@ -19,7 +19,11 @@
#ifndef _DNS_H_ #ifndef _DNS_H_
#define _DNS_H_ #define _DNS_H_
extern struct sockaddr_in peer;
int open_dns(); int open_dns();
void close_dns(int); void close_dns(int);
void dns_set_peer(const char *);
#endif /* _DNS_H_ */ #endif /* _DNS_H_ */

View File

@ -29,7 +29,7 @@ main()
open_tun(); open_tun();
dnssock = open_dns(); dnssock = open_dns();
dns_set_peer("192.168.11.101");
close_dns(dnssock); close_dns(dnssock);
close_tun(); close_tun();