Changeset 632627e for lib/misc.h


Ignore:
Timestamp:
2014-07-24T03:51:07Z (6 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
f93fd2d
Parents:
59e66ff
git-author:
jcopenha <jcopenha@…> (24-07-14 03:51:07)
git-committer:
dequis <dx@…> (24-07-14 03:51:07)
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/misc.h

    r59e66ff r632627e  
    3838};
    3939
     40#ifndef NAMESER_HAS_NS_TYPES
     41
     42#define NS_MAXDNAME 1025
     43#define NS_INT16SZ  2
     44#define NS_INT32SZ  4
     45
     46#define NS_GET16(s, cp) do { \
     47        register const unsigned char *t_cp = (const unsigned char*)(cp); \
     48        (s) = ((guint16)t_cp[0] << 8) \
     49            | ((guint16)t_cp[1]) \
     50            ; \
     51        (cp) += NS_INT16SZ; \
     52} while(0)
     53
     54#define NS_GET32(s, cp) do { \
     55        register const unsigned char *t_cp = (const unsigned char*)(cp); \
     56        (s) = ((guint16)t_cp[0] << 24) \
     57            | ((guint16)t_cp[1] << 16) \
     58            | ((guint16)t_cp[2] << 8) \
     59            | ((guint16)t_cp[3]) \
     60            ; \
     61        (cp) += NS_INT32SZ; \
     62} while(0)
     63
     64#define ns_rr_rdlen(rr) ((rr).rdlength + 0)
     65#define ns_rr_rdata(rr) ((rr).rdata + 0)
     66
     67struct _ns_flagdata { int mask, shift; };
     68
     69typedef struct __ns_rr {
     70        char name[NS_MAXDNAME];
     71        guint16 type;
     72        guint16 rr_class;
     73        guint32 ttl;
     74        guint16 rdlength;
     75        const unsigned char* rdata;
     76} ns_rr;
     77
     78typedef enum __ns_sect {
     79        ns_s_qd = 0,
     80        ns_s_zn = 0,
     81        ns_s_an = 1,
     82        ns_s_pr = 1,
     83        ns_s_ns = 2,
     84        ns_s_ud = 2,
     85        ns_s_ar = 3,
     86        ns_s_max =4
     87} ns_sect;
     88
     89typedef struct __ns_msg
     90{
     91        const unsigned char* _msg;
     92        const unsigned char* _eom;
     93        guint16 _id;
     94        guint16 _flags;
     95        guint16 _counts[ns_s_max];
     96        const unsigned char* _sections[ns_s_max];
     97        ns_sect _sect;
     98        int _rrnum;
     99        const unsigned char* _msg_ptr;
     100} ns_msg;
     101
     102typedef enum __ns_class {
     103        ns_c_invalid = 0,
     104        ns_c_in = 1,
     105        ns_c_2 = 2,
     106        ns_c_chaos = 3,
     107        ns_c_hs = 4,
     108        ns_c_none = 254,
     109        ns_c_any = 255,
     110        ns_c_max = 65536
     111} ns_class;
     112
     113
     114/* TODO : fill out the rest */
     115typedef enum __ns_type {
     116        ns_t_srv = 33
     117} ns_type;
     118
     119#endif /* NAMESER_HAS_NS_INITPARSE */
     120
    40121G_MODULE_EXPORT void strip_linefeed( gchar *text );
    41122G_MODULE_EXPORT char *add_cr( char *text );
Note: See TracChangeset for help on using the changeset viewer.