-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrumprun-setdns.c
42 lines (35 loc) · 1.02 KB
/
rumprun-setdns.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <err.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
char *dns_resolver;
FILE *resolv;
int nw;
dns_resolver = getenv("RUMPRUN_RESOLVER");
if (dns_resolver == NULL) {
warnx("RUMPRUN_RESOLVER not set, not configuring DNS");
return 0;
}
/* May not exist if running w/o any filesystems */
(void)mkdir("/etc", 0755);
resolv = fopen("/etc/resolv.conf", "w");
if (resolv == NULL)
err(1, "fopen(/etc/resolv.conf)");
nw = fprintf(resolv, "nameserver %s\ndomain docker\n", dns_resolver);
if (nw <= 0)
errx(1, "fprintf() returned %d", nw);
fclose(resolv);
/* Test that the DNS server actually works */
struct addrinfo *result;
int rc;
rc = getaddrinfo("docker.com", NULL, NULL, &result);
if (rc != 0)
errx(1, "getaddrinfo(\"docker.com\"): %s", gai_strerror(rc));
freeaddrinfo(result);
return 0;
}