From 395bb5c76422c8e8423730b2d17498aa330ce85d Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Wed, 19 Aug 2026 23:45:45 -0500 Subject: [PATCH] dns configuration --- client.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/client.cpp b/client.cpp index 18ca6ff..608280a 100644 --- a/client.cpp +++ b/client.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -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);