resolv.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. extern int open_nameservers(void);
  68. extern void close_nameservers(void);
  69. extern struct hostent * gethostbyname(const char * name);
  70. extern struct hostent * gethostbyaddr(const char * addr, int len, int type);
  71. extern int res_init(void);
  72. extern int res_query(const char *dname, int class, int type,
  73. unsigned char *answer, int anslen);
  74. #endif /*_RESOLV_H_*/