1 #include <errno.h>
2 #include <comboot.h>
3 #include <gpxe/in.h>
4 #include <gpxe/list.h>
5 #include <gpxe/process.h>
6 #include <gpxe/resolv.h>
7
8 FILE_LICENCE ( GPL2_OR_LATER );
9
10 static int comboot_resolv_rc;
11 static struct in_addr comboot_resolv_addr;
12
comboot_resolv_done(struct resolv_interface * resolv,struct sockaddr * sa,int rc)13 static void comboot_resolv_done ( struct resolv_interface *resolv,
14 struct sockaddr *sa, int rc ) {
15 struct sockaddr_in *sin;
16
17 resolv_unplug ( resolv );
18
19 if ( rc != 0 ) {
20 comboot_resolv_rc = rc;
21 return;
22 }
23
24 if ( sa->sa_family != AF_INET ) {
25 comboot_resolv_rc = -EAFNOSUPPORT;
26 return;
27 }
28
29 sin = ( ( struct sockaddr_in * ) sa );
30 comboot_resolv_addr = sin->sin_addr;
31
32 comboot_resolv_rc = 0;
33 }
34
35 static struct resolv_interface_operations comboot_resolv_ops = {
36 .done = comboot_resolv_done,
37 };
38
39 static struct resolv_interface comboot_resolver = {
40 .intf = {
41 .dest = &null_resolv.intf,
42 .refcnt = NULL,
43 },
44 .op = &comboot_resolv_ops,
45 };
46
comboot_resolv(const char * name,struct in_addr * address)47 int comboot_resolv ( const char *name, struct in_addr *address ) {
48 int rc;
49
50 comboot_resolv_rc = -EINPROGRESS;
51
52 if ( ( rc = resolv ( &comboot_resolver, name, NULL ) ) != 0 )
53 return rc;
54
55 while ( comboot_resolv_rc == -EINPROGRESS )
56 step();
57
58 *address = comboot_resolv_addr;
59 return comboot_resolv_rc;
60 }
61