Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #if 0
  2. #include "resolv.h"
  3. #include "string.h"
  4. #include <gpxe/dns.h>
  5. #include "nic.h"
  6. #include "nmb.h"
  7. /*
  8. * Convert a standard NUL-terminated string to an NBNS query name.
  9. *
  10. * Returns a pointer to the character following the constructed NBNS
  11. * query name.
  12. *
  13. */
  14. static inline char * nbns_make_name ( char *dest, const char *name ) {
  15. char nb_name[16];
  16. char c;
  17. int i;
  18. uint16_t *d;
  19. *(dest++) = 32; /* Length is always 32 */
  20. /* Name encoding is as follows: pad the name with spaces to
  21. * length 15, and add a NUL. Take this 16-byte string, split
  22. * it into nibbles and add 0x41 to each nibble to form a byte
  23. * of the resulting name string.
  24. */
  25. memset ( nb_name, ' ', 15 );
  26. nb_name[15] = '\0';
  27. memcpy ( nb_name, name, strlen ( name ) ); /* Do not copy NUL */
  28. d = ( uint16_t * ) dest;
  29. for ( i = 0 ; i < 16 ; i++ ) {
  30. c = nb_name[i];
  31. *( d++ ) = htons ( ( ( c | ( c << 4 ) ) & 0x0f0f ) + 0x4141 );
  32. }
  33. dest = ( char * ) d;
  34. *(dest++) = 0; /* Terminating 0-length name component */
  35. return dest;
  36. }
  37. /*
  38. * Resolve a name using NMB
  39. *
  40. */
  41. static int nmb_resolv ( struct in_addr *addr, const char *name ) {
  42. struct dns_query query;
  43. struct dns_query_info *query_info;
  44. struct dns_header *reply;
  45. struct dns_rr_info *rr_info;
  46. struct dns_rr_info_nb *rr_info_nb;
  47. struct sockaddr_in nameserver;
  48. DBG ( "NMB resolving %s\n", name );
  49. /* Set up the query data */
  50. nameserver.sin_addr.s_addr = INADDR_BROADCAST;
  51. nameserver.sin_port = NBNS_UDP_PORT;
  52. memset ( &query, 0, sizeof ( query ) );
  53. query.dns.id = htons ( 1 );
  54. query.dns.flags = htons ( DNS_FLAG_QUERY | DNS_FLAG_OPCODE_QUERY |
  55. DNS_FLAG_RD | DNS_FLAG_BROADCAST );
  56. query.dns.qdcount = htons ( 1 );
  57. query_info = ( void * ) nbns_make_name ( query.payload, name );
  58. query_info->qtype = htons ( DNS_TYPE_NB );
  59. query_info->qclass = htons ( DNS_CLASS_IN );
  60. /* Issue query, wait for reply */
  61. reply = dns_query ( &query,
  62. ( ( ( char * ) query_info )
  63. + sizeof ( *query_info )
  64. - ( ( char * ) &query ) ),
  65. &nameserver );
  66. if ( ! reply ) {
  67. DBG ( "NMB got no response via %@ (port %d)\n",
  68. nameserver.sin_addr.s_addr,
  69. nameserver.sin_port );
  70. return 0;
  71. }
  72. /* Search through response for useful answers. */
  73. rr_info = dns_find_rr ( &query, reply );
  74. if ( ! rr_info ) {
  75. DBG ( "NMB got invalid response\n" );
  76. return 0;
  77. }
  78. /* Check type of response */
  79. if ( ntohs ( rr_info->type ) != DNS_TYPE_NB ) {
  80. DBG ( "NMB got answer type %hx (wanted %hx)\n",
  81. ntohs ( rr_info->type ), DNS_TYPE_NB );
  82. return 0;
  83. }
  84. /* Read response */
  85. rr_info_nb = ( struct dns_rr_info_nb * ) rr_info;
  86. *addr = rr_info_nb->nb_address;
  87. DBG ( "NMB found address %@\n", addr->s_addr );
  88. return 1;
  89. }
  90. struct resolver nmb_resolver __resolver = {
  91. .name = "NMB",
  92. .resolv = nmb_resolv,
  93. };
  94. #endif