dns configuration
This commit is contained in:
parent
79b7ba2832
commit
395bb5c764
26
client.cpp
26
client.cpp
@ -5,6 +5,7 @@
|
||||
#include <stddef.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
@ -288,10 +289,35 @@ int main()
|
||||
p.dhcp4->yiaddr,
|
||||
options.router);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// dns configure
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
int dfd = open("/etc/resolv.conf", O_CREAT | O_WRONLY | O_TRUNC);
|
||||
if (dfd < 0) {
|
||||
perror("open");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
char dbuf[1024];
|
||||
int dbuflen = snprintf(dbuf, (sizeof (dbuf)), "nameserver %s\n",
|
||||
ip4::tostr(options.domain_name_server));
|
||||
if (dbuflen < 0) {
|
||||
perror("snprintf");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ssize_t dret = write(dfd, dbuf, dbuflen);
|
||||
if (dret < 0) {
|
||||
perror("write");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// exit
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
close(dfd);
|
||||
close(s);
|
||||
close(sf);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user