8 #include <sys/socket.h>
12 #define VERSION "0.3.3"
13 #define NTK_RESOLV_MAIL_BUGS "https://github.com/Netsukuku/netsukuku/issues"
15 #define NTKRESOLV_PORT 53
16 #define NTKRESOLV_PORT_STR "53"
18 #define LOCALHOST "localhost"
20 #define NTK_RESOLV_TIMEOUT 15
22 #define MAX_HOSTNAME_LEN 512
23 #define NTKRESOLV_MAX_OBJ_LEN 512
28 #define min(x,y) (x)<(y)?(x):(y)
32 #define REALM_NTK_STR "ntk"
33 #define REALM_INT_STR "inet"
36 #define QTYPE_PTR AT_PTR
39 #define QTYPE_A_STR "snsd"
40 #define QTYPE_PTR_STR "ptr"
41 #define QTYPE_G_STR "global"
42 #define QTYPE_MX_STR "mx"
44 #define SNSD_PROTO_TCP 0
45 #define SNSD_PROTO_UDP 1
46 #define SNSD_PROTO_TCP_STR "tcp"
47 #define SNSD_PROTO_UDP_STR "udp"
49 #define SNSD_PROTO_DEFAULT SNSD_PROTO_TCP
50 #define SNSD_SERVICE_DEFAULT 0
57 #define TIME_SCALE 1000000.0
58 #define HELP_STR "help"
65 #define QTFROMPREF(s) \
68 for (__n=0;__n<QT_LEN;__n++) \
69 if (!strncasecmp(s,QTYPE_STR_LIST[__n],strlen(s))) \
72 #define REALMFROMPREF(s) \
75 if (!strncasecmp(REALM_NTK_STR,s,strlen(s))) \
77 else if (!strncasecmp(REALM_INT_STR,s,strlen(s))) \
80 #define PROTOFROMPREF(s) \
83 if (!strncasecmp(SNSD_PROTO_UDP_STR,s,strlen(s))) \
84 __res=SNSD_PROTO_UDP; \
85 else if (!strncasecmp(SNSD_PROTO_TCP_STR,s,strlen(s))) \
86 __res=SNSD_PROTO_TCP; \
101 #define NTKRESOLV_OPTS_SZ sizeof(ntkresolv_opts)
103 #define QR_STR(ap) ((ap)->qr==0)?"QUERY":"ANSWER"
104 #define QTYPE_STR(ap) \
107 switch((ap)->qtype) { \
141 #define RCODE_STR(ap) \
144 switch((ap)->rcode) { \
145 case ANDNS_RCODE_NOERR: \
148 case ANDNS_RCODE_EINTRPRT: \
151 case ANDNS_RCODE_ESRVFAIL: \
154 case ANDNS_RCODE_ENSDMN: \
157 case ANDNS_RCODE_ENIMPL: \
160 case ANDNS_RCODE_ERFSD: \
168 #define IPV_STR(ap) \
171 switch((ap)->ipv) { \
183 #define MAX_INT_STR 10
184 #define SERVICE_STR(ap) \
187 char __t[MAX_INT_STR]; \
188 switch((ap)->qtype) { \
196 snprintf(__t,MAX_INT_STR,"%d", \
205 #define PROTO_STR(ap) \
208 switch((ap)->qtype) { \
219 __h=ap->p==SNSD_PROTO_TCP? \
220 SNSD_PROTO_TCP_STR: \
221 SNSD_PROTO_UDP_STR; \
230 #define GET_OPT_REALM (globopts.realm==REALM_NTK)?"NTK":"INET"
233 #define GOP (globopts)
234 #define AMISILENT (GOP.silent)
238 #define bye if (!AMISILENT) say("\tBye!\n");
240 #define COMPUTE_TIME diff_time(time_start,time_stop)
241 #define time_report if (!AMISILENT){gettimeofday(&time_stop,NULL); \
242 say("Query time: %f seconds.\n" \
245 #define G_ALIGN(len) GQT->qstlength=len;GQT->qstdata=(char*) \
247 if (!GQT->qstdata){say("Fatal malloc!\n"); \
249 #define G_SETQST_A(s) G_ALIGN(strlen(s)+1);strcpy(GQT->qstdata,s); \
250 GQT->qstlength=strlen(s);
252 #define NTK_RESOLV_HASH_STR(s,d) \
255 for (__i=0;__i<ANDNS_HASH_H;__i++) \
256 sprintf(d+2*__i,"%02x",((unsigned char*)(s))[__i]); \
257 d[2*ANDNS_HASH_H]=0;})
259 #define NTK_RESOLV_STR_HASH(s,d) \
262 for (__i=0;__i<ANDNS_HASH_H;__i++) { \
263 sscanf(s+2*__i,"%02x",&__t); \
264 d[__i]=(unsigned char)(__t);}})
266 #define NTK_RESOLV_IP_SYMBOL "~"
267 #define NTK_RESOLV_HNAME_SYMBOL "-"
268 #define NTK_RESOLV_SYMBOL(apd) (apd)->m&APD_IP?NTK_RESOLV_IP_SYMBOL: \
269 NTK_RESOLV_HNAME_SYMBOL
279 double diff_time(
struct timeval a,
struct timeval b);
304 int main(
int argc,
char **argv);
#define QTYPE_G_STR
Definition: ntkresolv.h:41
struct ntkresolv_opts ntkresolv_opts
char * QTYPE_STR_LIST[]
Definition: ntkresolv.h:62
void answer_data_to_str(andns_pkt_data *apd, char *dst)
Definition: ntkresolv.c:394
void proto_usage(char *arg)
Definition: ntkresolv.c:79
#define MAX_HOSTNAME_LEN
Definition: ntkresolv.h:22
void qt_usage(char *arg)
Definition: ntkresolv.c:49
void opts_set_question(char *arg)
Definition: ntkresolv.c:255
void service_and_proto_usage(char *arg)
Definition: ntkresolv.c:95
Definition: ntkresolv.h:91
void opts_set_service_and_proto(char *arg)
Definition: ntkresolv.c:211
andns_pkt * q
Definition: ntkresolv.h:98
#define QTYPE_MX_STR
Definition: ntkresolv.h:42
void print_results(void)
Definition: ntkresolv.c:472
void opts_set_hash(void)
Definition: ntkresolv.c:242
void ntkresolv_safe_exit(int i)
Definition: ntkresolv.c:527
void usage(void)
Definition: netsukuku.c:155
void opts_set_silent(void)
Definition: ntkresolv.c:149
void opts_set_proto(char *arg)
Definition: ntkresolv.c:226
int QT_LEN
Definition: ntkresolv.h:63
#define NTKRESOLV_MAX_OBJ_LEN
Definition: ntkresolv.h:23
#define QTYPE_A_STR
Definition: ntkresolv.h:39
int main(int argc, char **argv)
Definition: netsukuku.c:699
int8_t silent
Definition: ntkresolv.h:94
void print_question()
Definition: ntkresolv.c:360
#define QTYPE_PTR_STR
Definition: ntkresolv.h:40
uint16_t id
Definition: ntkresolv.h:96
void opts_init(void)
Definition: ntkresolv.c:136
void print_headers()
Definition: ntkresolv.c:347
void print_parsable_answers(void)
Definition: ntkresolv.c:442
char nsserver[512]
Definition: ntkresolv.h:92
uint8_t hash
Definition: ntkresolv.h:97
void opts_set_compute_hash(void)
Definition: ntkresolv.c:246
void opts_set_ns(char *arg)
Definition: ntkresolv.c:169
void opts_set_port(char *arg)
Definition: ntkresolv.c:154
void print_answers()
Definition: ntkresolv.c:407
void opts_set_recursion(void)
Definition: ntkresolv.c:238
Definition: andns_lib.h:45
void version(void)
Definition: ntkresolv.c:16
void ntkresolv_exit(int i)
Definition: ntkresolv.c:523
double diff_time(struct timeval a, struct timeval b)
Definition: ntkresolv.c:122
void realm_usage(char *arg)
Definition: ntkresolv.c:66
int16_t port
Definition: ntkresolv.h:93
void ip_bin_to_str(void *data, char *dst)
Definition: ntkresolv.c:366
char obj[512]
Definition: ntkresolv.h:95
void opts_set_qt(char *arg)
Definition: ntkresolv.c:182
void opts_set_realm(char *arg)
Definition: ntkresolv.c:199
void opts_finish(char *arg)
Definition: ntkresolv.c:320
void opts_set_parsable_output(void)
Definition: ntkresolv.c:250
void do_command(void)
Definition: ntkresolv.c:484
Definition: andns_lib.h:64