resolv.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <netdb.h>
  14. #include <netinet/in.h>
  15. struct resolv_header {
  16. int id;
  17. int qr,opcode,aa,tc,rd,ra,rcode;
  18. int qdcount;
  19. int ancount;
  20. int nscount;
  21. int arcount;
  22. };
  23. struct resolv_question {
  24. char * dotted;
  25. int qtype;
  26. int qclass;
  27. };
  28. struct resolv_answer {
  29. char * dotted;
  30. int atype;
  31. int aclass;
  32. int ttl;
  33. int rdlength;
  34. unsigned char * rdata;
  35. int rdoffset;
  36. };
  37. int encode_header(struct resolv_header * h, unsigned char * dest, int maxlen);
  38. int decode_header(unsigned char * data, struct resolv_header * h);
  39. int encode_dotted(const char * dotted, unsigned char * dest, int maxlen);
  40. int decode_dotted(const unsigned char * message, int offset,
  41. char * dest, int maxlen);
  42. int length_dotted(const unsigned char * message, int offset);
  43. int encode_question(struct resolv_question * q,
  44. unsigned char * dest, int maxlen);
  45. int decode_question(unsigned char * message, int offset,
  46. struct resolv_question * q);
  47. int length_question(unsigned char * message, int offset);
  48. int encode_answer(struct resolv_answer * a,
  49. unsigned char * dest, int maxlen);
  50. int decode_answer(unsigned char * message, int offset,
  51. struct resolv_answer * a);
  52. const char * resolve_name(const char * name, int mailbox);
  53. int encode_packet(struct resolv_header * h,
  54. struct resolv_question ** q,
  55. struct resolv_answer ** an,
  56. struct resolv_answer ** ns,
  57. struct resolv_answer ** ar,
  58. unsigned char * dest, int maxlen);
  59. int decode_packet(unsigned char * data, struct resolv_header * h);
  60. int dns_lookup(const char * name, int type, int nscount, const char ** nsip,
  61. unsigned char ** outpacket, struct resolv_answer * a);
  62. int resolve_address(const char * address,
  63. int nscount, const char ** nsip,
  64. struct in_addr * in);
  65. int resolve_mailbox(const char * address,
  66. int nscount, const char ** nsip,
  67. struct in_addr * in);
  68. extern int open_nameservers(void);
  69. extern void close_nameservers(void);
  70. extern struct hostent * gethostbyname(const char * name);
  71. extern struct hostent * gethostbyaddr(const char * addr, int len, int type);
  72. #endif /*_RESOLV_H_*/