[comboot] Add COMBOOT and COM32 support
[people/mcb30/gpxe.git] / src / arch / i386 / interface / syslinux / comboot_resolv.c
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 static int comboot_resolv_rc;
9 static struct in_addr comboot_resolv_addr;
10
11 static void comboot_resolv_done ( struct resolv_interface *resolv,
12                                   struct sockaddr *sa, int rc ) {
13         struct sockaddr_in *sin;
14
15         resolv_unplug ( resolv );
16
17         if ( rc != 0 ) {
18                 comboot_resolv_rc = rc;
19                 return;
20         }
21
22         if ( sa->sa_family != AF_INET ) {
23                 comboot_resolv_rc = -EAFNOSUPPORT;
24                 return;
25         }
26
27         sin = ( ( struct sockaddr_in * ) sa );
28         comboot_resolv_addr = sin->sin_addr;
29
30         comboot_resolv_rc = 0;
31 }
32
33 static struct resolv_interface_operations comboot_resolv_ops = {
34         .done = comboot_resolv_done,
35 };
36
37 static struct resolv_interface comboot_resolver = {
38         .intf = {
39                 .dest = &null_resolv.intf,
40                 .refcnt = NULL,
41         },
42         .op = &comboot_resolv_ops,
43 };
44
45 int comboot_resolv ( const char *name, struct in_addr *address ) {
46         int rc;
47
48         comboot_resolv_rc = -EINPROGRESS;
49
50         if ( ( rc = resolv ( &comboot_resolver, name, NULL ) ) != 0 )
51                 return rc;
52
53         while ( comboot_resolv_rc == -EINPROGRESS )
54                 step();
55
56         *address = comboot_resolv_addr;
57         return comboot_resolv_rc;
58 }