dns configuration

This commit is contained in:
Zack Buhman 2026-08-19 23:45:45 -05:00
parent 79b7ba2832
commit 395bb5c764

View File

@ -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);