You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

comboot_resolv.c 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. FILE_LICENCE ( GPL2_OR_LATER );
  8. static int comboot_resolv_rc;
  9. static struct in_addr comboot_resolv_addr;
  10. static void comboot_resolv_done ( struct resolv_interface *resolv,
  11. struct sockaddr *sa, int rc ) {
  12. struct sockaddr_in *sin;
  13. resolv_unplug ( resolv );
  14. if ( rc != 0 ) {
  15. comboot_resolv_rc = rc;
  16. return;
  17. }
  18. if ( sa->sa_family != AF_INET ) {
  19. comboot_resolv_rc = -EAFNOSUPPORT;
  20. return;
  21. }
  22. sin = ( ( struct sockaddr_in * ) sa );
  23. comboot_resolv_addr = sin->sin_addr;
  24. comboot_resolv_rc = 0;
  25. }
  26. static struct resolv_interface_operations comboot_resolv_ops = {
  27. .done = comboot_resolv_done,
  28. };
  29. static struct resolv_interface comboot_resolver = {
  30. .intf = {
  31. .dest = &null_resolv.intf,
  32. .refcnt = NULL,
  33. },
  34. .op = &comboot_resolv_ops,
  35. };
  36. int comboot_resolv ( const char *name, struct in_addr *address ) {
  37. int rc;
  38. comboot_resolv_rc = -EINPROGRESS;
  39. if ( ( rc = resolv ( &comboot_resolver, name, NULL ) ) != 0 )
  40. return rc;
  41. while ( comboot_resolv_rc == -EINPROGRESS )
  42. step();
  43. *address = comboot_resolv_addr;
  44. return comboot_resolv_rc;
  45. }