message.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <ip.h>
  12. #include <thread.h>
  13. #include "netbios.h"
  14. NbnsMessage *
  15. nbnsmessagenamequeryrequestnew(uint16_t id, int broadcast, NbName name)
  16. {
  17. NbnsMessage *s;
  18. NbnsMessageQuestion *q;
  19. s = nbnsmessagenew();
  20. if (s == nil)
  21. return nil;
  22. s->id = id;
  23. s->opcode = NbnsOpQuery;
  24. s->broadcast = broadcast;
  25. s->recursiondesired = 1;
  26. q = nbnsmessagequestionnew(name, NbnsQuestionTypeNb, NbnsQuestionClassIn);
  27. if (q == nil) {
  28. nbnsmessagefree(&s);
  29. return nil;
  30. }
  31. nbnsmessageaddquestion(s, q);
  32. return s;
  33. }
  34. NbnsMessage *
  35. nbnsmessagenameregistrationrequestnew(uint16_t id, int broadcast,
  36. NbName name,
  37. uint32_t ttl, uint8_t *ipaddr)
  38. {
  39. NbnsMessage *s;
  40. NbnsMessageQuestion *q;
  41. uint8_t rdata[6];
  42. NbnsMessageResource *r;
  43. s = nbnsmessagenew();
  44. if (s == nil)
  45. return nil;
  46. s->id = id;
  47. s->opcode = NbnsOpRegistration;
  48. s->broadcast = broadcast;
  49. s->recursiondesired = 1;
  50. q = nbnsmessagequestionnew(name, NbnsQuestionTypeNb, NbnsQuestionClassIn);
  51. if (q == nil) {
  52. nbnsmessagefree(&s);
  53. return nil;
  54. }
  55. nbnsmessageaddquestion(s, q);
  56. rdata[0] = 0;
  57. rdata[1] = 0;
  58. v6tov4(rdata + 2, ipaddr);
  59. r = nbnsmessageresourcenew(name, NbnsResourceTypeNb, NbnsResourceClassIn, ttl, 6, rdata);
  60. nbnsmessageaddresource(&s->ar, r);
  61. return s;
  62. }