diff options
author | jcopenha <jcopenha@typedef.org> | 2014-07-24 00:51:07 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2014-07-24 00:51:07 -0300 |
commit | 632627e1ead19fc7dc07effe441b2d543a675229 (patch) | |
tree | 84d8aac19b33ad72e1711a2a88ad6a7958c060ef /lib/misc.h | |
parent | 59e66ff766cbef04883c1d7477d66c7e9b515833 (diff) |
srv_lookup: Portability fixes, handle compressed responses
srv_lookup works on cygwin and openbsd now.
Provide ns_initparse, friends, and types where they aren't provided by
platform.
Use dn_expandname instead of custom parser so compressed DNS responses
are handled correctly.
Diffstat (limited to 'lib/misc.h')
-rw-r--r-- | lib/misc.h | 81 |
1 files changed, 81 insertions, 0 deletions
@@ -37,6 +37,87 @@ struct ns_srv_reply char name[]; }; +#ifndef NAMESER_HAS_NS_TYPES + +#define NS_MAXDNAME 1025 +#define NS_INT16SZ 2 +#define NS_INT32SZ 4 + +#define NS_GET16(s, cp) do { \ + register const unsigned char *t_cp = (const unsigned char*)(cp); \ + (s) = ((guint16)t_cp[0] << 8) \ + | ((guint16)t_cp[1]) \ + ; \ + (cp) += NS_INT16SZ; \ +} while(0) + +#define NS_GET32(s, cp) do { \ + register const unsigned char *t_cp = (const unsigned char*)(cp); \ + (s) = ((guint16)t_cp[0] << 24) \ + | ((guint16)t_cp[1] << 16) \ + | ((guint16)t_cp[2] << 8) \ + | ((guint16)t_cp[3]) \ + ; \ + (cp) += NS_INT32SZ; \ +} while(0) + +#define ns_rr_rdlen(rr) ((rr).rdlength + 0) +#define ns_rr_rdata(rr) ((rr).rdata + 0) + +struct _ns_flagdata { int mask, shift; }; + +typedef struct __ns_rr { + char name[NS_MAXDNAME]; + guint16 type; + guint16 rr_class; + guint32 ttl; + guint16 rdlength; + const unsigned char* rdata; +} ns_rr; + +typedef enum __ns_sect { + ns_s_qd = 0, + ns_s_zn = 0, + ns_s_an = 1, + ns_s_pr = 1, + ns_s_ns = 2, + ns_s_ud = 2, + ns_s_ar = 3, + ns_s_max =4 +} ns_sect; + +typedef struct __ns_msg +{ + const unsigned char* _msg; + const unsigned char* _eom; + guint16 _id; + guint16 _flags; + guint16 _counts[ns_s_max]; + const unsigned char* _sections[ns_s_max]; + ns_sect _sect; + int _rrnum; + const unsigned char* _msg_ptr; +} ns_msg; + +typedef enum __ns_class { + ns_c_invalid = 0, + ns_c_in = 1, + ns_c_2 = 2, + ns_c_chaos = 3, + ns_c_hs = 4, + ns_c_none = 254, + ns_c_any = 255, + ns_c_max = 65536 +} ns_class; + + +/* TODO : fill out the rest */ +typedef enum __ns_type { + ns_t_srv = 33 +} ns_type; + +#endif /* NAMESER_HAS_NS_INITPARSE */ + G_MODULE_EXPORT void strip_linefeed( gchar *text ); G_MODULE_EXPORT char *add_cr( char *text ); G_MODULE_EXPORT char *strip_newlines(char *source); |