aboutsummaryrefslogtreecommitdiffstats
path: root/gpxe/src/arch/i386/interface/syslinux/comboot_resolv.c
blob: 41c3af7aacb951cc376525c28a53b8fc411ea723 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <errno.h>
#include <comboot.h>
#include <gpxe/in.h>
#include <gpxe/list.h>
#include <gpxe/process.h>
#include <gpxe/resolv.h>

static int comboot_resolv_rc;
static struct in_addr comboot_resolv_addr;

static void comboot_resolv_done ( struct resolv_interface *resolv,
				  struct sockaddr *sa, int rc ) {
	struct sockaddr_in *sin;

	resolv_unplug ( resolv );

	if ( rc != 0 ) {
		comboot_resolv_rc = rc;
		return;
	}

	if ( sa->sa_family != AF_INET ) {
		comboot_resolv_rc = -EAFNOSUPPORT;
		return;
	}

	sin = ( ( struct sockaddr_in * ) sa );
	comboot_resolv_addr = sin->sin_addr;

	comboot_resolv_rc = 0;
}

static struct resolv_interface_operations comboot_resolv_ops = {
	.done = comboot_resolv_done,
};

static struct resolv_interface comboot_resolver = {
	.intf = {
		.dest = &null_resolv.intf,
		.refcnt = NULL,
	},
	.op = &comboot_resolv_ops,
};

int comboot_resolv ( const char *name, struct in_addr *address ) {
	int rc;

	comboot_resolv_rc = -EINPROGRESS;

	if ( ( rc = resolv ( &comboot_resolver, name, NULL ) ) != 0 )
		return rc;

	while ( comboot_resolv_rc == -EINPROGRESS )
		step();

	*address = comboot_resolv_addr;
	return comboot_resolv_rc;
}