Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / i386 / interface / syslinux / comboot_resolv.c
1 #include <errno.h>
2 #include <comboot.h>
3 #include <ipxe/in.h>
4 #include <ipxe/list.h>
5 #include <ipxe/process.h>
6 #include <ipxe/resolv.h>
7
8 FILE_LICENCE ( GPL2_OR_LATER );
9
10 struct comboot_resolver {
11         struct interface intf;
12         int rc;
13         struct in_addr addr;
14 };
15
16 static void comboot_resolv_close ( struct comboot_resolver *comboot_resolver,
17                                    int rc ) {
18         comboot_resolver->rc = rc;
19         intf_shutdown ( &comboot_resolver->intf, rc );
20 }
21
22 static void comboot_resolv_done ( struct comboot_resolver *comboot_resolver,
23                                   struct sockaddr *sa ) {
24         struct sockaddr_in *sin;
25
26         if ( sa->sa_family == AF_INET ) {
27                 sin = ( ( struct sockaddr_in * ) sa );
28                 comboot_resolver->addr = sin->sin_addr;
29         }
30 }
31
32 static struct interface_operation comboot_resolv_op[] = {
33         INTF_OP ( intf_close, struct comboot_resolver *, comboot_resolv_close ),
34         INTF_OP ( resolv_done, struct comboot_resolver *, comboot_resolv_done ),
35 };
36
37 static struct interface_descriptor comboot_resolv_desc =
38         INTF_DESC ( struct comboot_resolver, intf, comboot_resolv_op );
39
40 static struct comboot_resolver comboot_resolver = {
41         .intf = INTF_INIT ( comboot_resolv_desc ),
42 };
43
44 int comboot_resolv ( const char *name, struct in_addr *address ) {
45         int rc;
46
47         comboot_resolver.rc = -EINPROGRESS;
48         comboot_resolver.addr.s_addr = 0;
49
50         if ( ( rc = resolv ( &comboot_resolver.intf, name, NULL ) ) != 0 )
51                 return rc;
52
53         while ( comboot_resolver.rc == -EINPROGRESS )
54                 step();
55
56         if ( ! comboot_resolver.addr.s_addr )
57                 return -EAFNOSUPPORT;
58
59         *address = comboot_resolver.addr;
60         return comboot_resolver.rc;
61 }