The Netsukuku Project  0.0.9
An Alternative routing method
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
andns_lib.h
Go to the documentation of this file.
1  /**************************************
2  * AUTHOR: Federico Tomassini *
3  * Copyright (C) Federico Tomassini *
4  * Contact effetom@gmail.com *
5  ***********************************************
6  ******* BEGIN 3/2006 ********
7 *************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details. *
18 * *
19 ************************************************************************/
20 
21 #ifndef ANDNS_LIB_H
22 #define ANDNS_LIB_H
23 
24 #include <string.h>
25 #include <stdint.h>
26 #include <sys/types.h>
27 
28 #define ANDNS_MAX_QUESTION_LEN 263 /* TODO */
29 #define ANDNS_MAX_ANSWER_LEN 516
30 #define ANDNS_MAX_ANSWERS_NUM 256
31 #define ANDNS_MAX_PK_LEN ANDNS_MAX_QUESTION_LEN+\
32  ANDNS_MAX_ANSWERS_NUM*ANDNS_MAX_ANSWER_LEN
33 
34 #define ANDNS_MAX_DATA_LEN 512
35 #define ANDNS_MAX_QST_LEN 512
36 #define ANNDS_DNS_MAZ_QST_LEN 255
37 #define ANDNS_MAX_ANSW_IP_LEN 20
38 #define ANDNS_MAX_ANSW_H_LEN 516
39 
40 #define ANDNS_HASH_H 16
41 
42 #define ANDNS_COMPR_LEVEL Z_BEST_COMPRESSION
43 #define ANDNS_COMPR_THRESHOLD 1000
44 
46 {
47  uint8_t m;
48  uint8_t wg;
49  uint8_t prio;
50  uint16_t rdlength;
51  uint16_t service;
52  char *rdata;
54 };
56 #define ANDNS_PKT_DATA_SZ sizeof(andns_pkt_data)
57 #define APD_ALIGN(apd) (apd)->rdata=(char*)xmalloc((apd)->rdlength+1); \
58  memset((apd)->rdata,0,(apd)->rdlength+1)
59 #define APD_MAIN_IP 1<<0
60 #define APD_IP 1<<1
61 #define APD_TCP 1<<2
62 #define APD_UDP 1<<3
63 
64 typedef struct andns_pkt
65 {
66  uint16_t id;
67  uint8_t r;
68  uint8_t qr;
69  uint8_t p;
70  uint8_t z;
71  uint8_t qtype;
72  uint16_t ancount;
73  uint8_t ipv;
74  uint8_t nk;
75  uint8_t rcode;
76  uint16_t service;
77  uint16_t qstlength;
78  char *qstdata;
80 } andns_pkt;
81 #define ANDNS_PKT_SZ sizeof(andns_pkt)
82 #define AP_ALIGN(ap) (ap)->qstdata=(char*)xmalloc((ap)->qstlength)
83 
84 #define ANDNS_HDR_SZ 4
85 #define ANDNS_HDR_Z 4
86 #define ANDNS_MAX_SZ ANDNS_HDR_SZ+ANDNS_MAX_QST_LEN+ANDNS_MAX_QST_LEN+4
87 
88 
89 #define ANDNS_SET_RCODE(s,c) *((s)+3)=(((*((s)+3))&0xf0)|c)
90 #define ANDNS_SET_QR(s) (*((s)+2))|=0x80
91 #define ANDNS_SET_ANCOUNT(s,n) *(s+2)|=((n)>>1);*(s+3)|=((n)<<7);
92 #define ANDNS_SET_Z(s) *(s+3)|=0x20;
93 #define ANDNS_UNSET_Z(s) *(s+3)&=0xdf;
94 
95 /* ANDNS PROTO-TYPE */
96 #define ANDNS_PROTO_TCP 0
97 #define ANDNS_PROTO_UDP 1
98 /* ANDNS QUERY-TYPE */
99 #define AT_A 0 /* h->ip */
100 #define AT_PTR 1 /* ip->h */
101 #define AT_G 2 /* global */
102 /* RCODES: The rcodes are portable between ANDNS and DNS */
103 #define ANDNS_RCODE_NOERR 0 /* No error */
104 #define ANDNS_RCODE_EINTRPRT 1 /* Intepret error */
105 #define ANDNS_RCODE_ESRVFAIL 2 /* Server failure */
106 #define ANDNS_RCODE_ENSDMN 3 /* No such domain */
107 #define ANDNS_RCODE_ENIMPL 4 /* Not implemented */
108 #define ANDNS_RCODE_ERFSD 5 /* Refused */
109 /* REALMS TO SEARCH */
110 #define NTK_REALM 1
111 #define INET_REALM 2
112 /* IP VERSION */
113 #define ANDNS_IPV4 0
114 #define ANDNS_IPV6 1
115 
116 int andns_compress(char *src,int srclen);
117 char* andns_uncompress(char *src,int srclen,int *dstlen) ;
118 int a_hdr_u(char *buf,andns_pkt *ap);
119 int a_qst_u(char *buf,andns_pkt *ap,int limitlen);
120 int a_answ_u(char *buf,andns_pkt *ap,int limitlen);
121 int a_answs_u(char *buf,andns_pkt *ap,int limitlen);
122 int a_u(char *buf,int pktlen,andns_pkt **app);
123 int a_hdr_p(andns_pkt *ap,char *buf);
124 int a_qst_p(andns_pkt *ap,char *buf,int limitlen);
125 int a_answ_p(andns_pkt *ap,andns_pkt_data *apd,char *buf,int limitlen);
126 int a_answs_p(andns_pkt *ap,char *buf, int limitlen);
127 int a_p(andns_pkt *ap, char *buf);
132 void andns_del_answ(andns_pkt *ap);
134 void destroy_andns_pkt(andns_pkt *ap);
135 
136 #endif /* ANDNS_LIB_H */
int a_answ_u(char *buf, andns_pkt *ap, int limitlen)
Definition: andns_lib.c:186
uint16_t ancount
Definition: andns_lib.h:72
void andns_del_answ(andns_pkt *ap)
Definition: andns_lib.c:578
uint8_t m
Definition: andns_lib.h:47
andns_pkt_data * pkt_answ
Definition: andns_lib.h:79
int a_hdr_u(char *buf, andns_pkt *ap)
Definition: andns_lib.c:93
uint16_t id
Definition: andns_lib.h:66
int a_answ_p(andns_pkt *ap, andns_pkt_data *apd, char *buf, int limitlen)
Definition: andns_lib.c:417
andns_pkt_data * andns_add_answ(andns_pkt *ap)
Definition: andns_lib.c:557
void destroy_andns_pkt(andns_pkt *ap)
Definition: andns_lib.c:604
void destroy_andns_pkt_data(andns_pkt_data *apd)
Definition: andns_lib.c:572
struct andns_pkt andns_pkt
char * rdata
Definition: andns_lib.h:52
uint8_t nk
Definition: andns_lib.h:74
struct andns_pkt_data * next
Definition: andns_lib.h:53
int andns_compress(char *src, int srclen)
Definition: andns_lib.c:30
uint16_t qstlength
Definition: andns_lib.h:77
uint8_t rcode
Definition: andns_lib.h:75
int a_answs_u(char *buf, andns_pkt *ap, int limitlen)
Definition: andns_lib.c:261
uint16_t service
Definition: andns_lib.h:51
uint8_t ipv
Definition: andns_lib.h:73
int a_p(andns_pkt *ap, char *buf)
Definition: andns_lib.c:504
andns_pkt_data * create_andns_pkt_data(void)
Definition: andns_lib.c:550
uint8_t r
Definition: andns_lib.h:67
int a_hdr_p(andns_pkt *ap, char *buf)
Definition: andns_lib.c:341
int a_u(char *buf, int pktlen, andns_pkt **app)
Definition: andns_lib.c:294
int a_answs_p(andns_pkt *ap, char *buf, int limitlen)
Definition: andns_lib.c:479
uint16_t service
Definition: andns_lib.h:76
char * andns_uncompress(char *src, int srclen, int *dstlen)
Definition: andns_lib.c:57
int a_qst_p(andns_pkt *ap, char *buf, int limitlen)
Definition: andns_lib.c:370
uint8_t qtype
Definition: andns_lib.h:71
uint8_t p
Definition: andns_lib.h:69
Definition: andns_lib.h:45
uint16_t rdlength
Definition: andns_lib.h:50
uint8_t wg
Definition: andns_lib.h:48
uint8_t z
Definition: andns_lib.h:70
uint8_t qr
Definition: andns_lib.h:68
int a_qst_u(char *buf, andns_pkt *ap, int limitlen)
Definition: andns_lib.c:129
char * qstdata
Definition: andns_lib.h:78
uint8_t prio
Definition: andns_lib.h:49
void destroy_andns_pkt_datas(andns_pkt *ap)
Definition: andns_lib.c:594
andns_pkt * create_andns_pkt(void)
Definition: andns_lib.c:542
Definition: andns_lib.h:64