iPXE
comboot_resolv.c
Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <comboot.h>
00003 #include <ipxe/in.h>
00004 #include <ipxe/list.h>
00005 #include <ipxe/process.h>
00006 #include <ipxe/resolv.h>
00007 
00008 FILE_LICENCE ( GPL2_OR_LATER );
00009 
00010 struct comboot_resolver {
00011         struct interface intf;
00012         int rc;
00013         struct in_addr addr;
00014 };
00015 
00016 static void comboot_resolv_close ( struct comboot_resolver *comboot_resolver,
00017                                    int rc ) {
00018         comboot_resolver->rc = rc;
00019         intf_shutdown ( &comboot_resolver->intf, rc );
00020 }
00021 
00022 static void comboot_resolv_done ( struct comboot_resolver *comboot_resolver,
00023                                   struct sockaddr *sa ) {
00024         struct sockaddr_in *sin;
00025 
00026         if ( sa->sa_family == AF_INET ) {
00027                 sin = ( ( struct sockaddr_in * ) sa );
00028                 comboot_resolver->addr = sin->sin_addr;
00029         }
00030 }
00031 
00032 static struct interface_operation comboot_resolv_op[] = {
00033         INTF_OP ( intf_close, struct comboot_resolver *, comboot_resolv_close ),
00034         INTF_OP ( resolv_done, struct comboot_resolver *, comboot_resolv_done ),
00035 };
00036 
00037 static struct interface_descriptor comboot_resolv_desc =
00038         INTF_DESC ( struct comboot_resolver, intf, comboot_resolv_op );
00039 
00040 static struct comboot_resolver comboot_resolver = {
00041         .intf = INTF_INIT ( comboot_resolv_desc ),
00042 };
00043 
00044 int comboot_resolv ( const char *name, struct in_addr *address ) {
00045         int rc;
00046 
00047         comboot_resolver.rc = -EINPROGRESS;
00048         comboot_resolver.addr.s_addr = 0;
00049 
00050         if ( ( rc = resolv ( &comboot_resolver.intf, name, NULL ) ) != 0 )
00051                 return rc;
00052 
00053         while ( comboot_resolver.rc == -EINPROGRESS )
00054                 step();
00055 
00056         if ( ! comboot_resolver.addr.s_addr )
00057                 return -EAFNOSUPPORT;
00058 
00059         *address = comboot_resolver.addr;
00060         return comboot_resolver.rc;
00061 }