resolv.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* resolv.h: DNS Resolver
  2. *
  3. * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>,
  4. * The Silver Hammer Group, Ltd.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. */
  11. #ifndef _RESOLV_H_
  12. #define _RESOLV_H_
  13. #include <features.h>
  14. #include <sys/param.h>
  15. #if (!defined(BSD)) || (BSD < 199306)
  16. # include <sys/bitypes.h>
  17. #else
  18. # include <sys/types.h>
  19. #endif
  20. #include <stdio.h>
  21. #include <netinet/in.h>
  22. struct resolv_header {
  23. int id;
  24. int qr,opcode,aa,tc,rd,ra,rcode;
  25. int qdcount;
  26. int ancount;
  27. int nscount;
  28. int arcount;
  29. };
  30. struct resolv_question {
  31. char * dotted;
  32. int qtype;
  33. int qclass;
  34. };
  35. struct resolv_answer {
  36. char * dotted;
  37. int atype;
  38. int aclass;
  39. int ttl;
  40. int rdlength;
  41. unsigned char * rdata;
  42. int rdoffset;
  43. };
  44. int encode_header(struct resolv_header * h, unsigned char * dest, int maxlen);
  45. int decode_header(unsigned char * data, struct resolv_header * h);
  46. int encode_dotted(const char * dotted, unsigned char * dest, int maxlen);
  47. int decode_dotted(const unsigned char * message, int offset,
  48. char * dest, int maxlen);
  49. int length_dotted(const unsigned char * message, int offset);
  50. int encode_question(struct resolv_question * q,
  51. unsigned char * dest, int maxlen);
  52. int decode_question(unsigned char * message, int offset,
  53. struct resolv_question * q);
  54. int length_question(unsigned char * message, int offset);
  55. int encode_answer(struct resolv_answer * a,
  56. unsigned char * dest, int maxlen);
  57. int decode_answer(unsigned char * message, int offset,
  58. struct resolv_answer * a);
  59. const char * resolve_name(const char * name, int mailbox);
  60. int encode_packet(struct resolv_header * h,
  61. struct resolv_question ** q,
  62. struct resolv_answer ** an,
  63. struct resolv_answer ** ns,
  64. struct resolv_answer ** ar,
  65. unsigned char * dest, int maxlen);
  66. int decode_packet(unsigned char * data, struct resolv_header * h);
  67. int dns_lookup(const char * name, int type, int nscount, const char ** nsip,
  68. unsigned char ** outpacket, struct resolv_answer * a);
  69. int resolve_address(const char * address,
  70. int nscount, const char ** nsip,
  71. struct in_addr * in);
  72. int resolve_mailbox(const char * address,
  73. int nscount, const char ** nsip,
  74. struct in_addr * in);
  75. extern int open_nameservers(void);
  76. extern void close_nameservers(void);
  77. extern struct hostent * gethostbyname(const char * name);
  78. extern struct hostent * gethostbyaddr(const char * addr, int len, int type);
  79. extern int res_init(void);
  80. extern int res_query(const char *dname, int class, int type,
  81. unsigned char *answer, int anslen);
  82. #endif /*_RESOLV_H_*/