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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. struct comboot_resolver {
  9. struct interface intf;
  10. int rc;
  11. struct in_addr addr;
  12. };
  13. static void comboot_resolv_close ( struct comboot_resolver *comboot_resolver,
  14. int rc ) {
  15. comboot_resolver->rc = rc;
  16. intf_shutdown ( &comboot_resolver->intf, rc );
  17. }
  18. static void comboot_resolv_done ( struct comboot_resolver *comboot_resolver,
  19. struct sockaddr *sa ) {
  20. struct sockaddr_in *sin;
  21. if ( sa->sa_family == AF_INET ) {
  22. sin = ( ( struct sockaddr_in * ) sa );
  23. comboot_resolver->addr = sin->sin_addr;
  24. }
  25. }
  26. static struct interface_operation comboot_resolv_op[] = {
  27. INTF_OP ( intf_close, struct comboot_resolver *, comboot_resolv_close ),
  28. INTF_OP ( resolv_done, struct comboot_resolver *, comboot_resolv_done ),
  29. };
  30. static struct interface_descriptor comboot_resolv_desc =
  31. INTF_DESC ( struct comboot_resolver, intf, comboot_resolv_op );
  32. static struct comboot_resolver comboot_resolver = {
  33. .intf = INTF_INIT ( comboot_resolv_desc ),
  34. };
  35. int comboot_resolv ( const char *name, struct in_addr *address ) {
  36. int rc;
  37. comboot_resolver.rc = -EINPROGRESS;
  38. comboot_resolver.addr.s_addr = 0;
  39. if ( ( rc = resolv ( &comboot_resolver.intf, name, NULL ) ) != 0 )
  40. return rc;
  41. while ( comboot_resolver.rc == -EINPROGRESS )
  42. step();
  43. if ( ! comboot_resolver.addr.s_addr )
  44. return -EAFNOSUPPORT;
  45. *address = comboot_resolver.addr;
  46. return comboot_resolver.rc;
  47. }