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.1KB

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