Browse code

- ipv6 received= debugging

Andrei Pelinescu-Onciul authored on 08/07/2002 16:27:04
Showing 3 changed files
... ...
@@ -3,6 +3,7 @@
3 3
 #include "../globals.h"
4 4
 #include "../config.h"
5 5
 
6
+#if 0
6 7
 #ifdef PKG_MALLOC
7 8
 #       ifdef VQ_MALLOC
8 9
 #               include "vq_malloc.h"
... ...
@@ -21,7 +22,6 @@
21 21
 #       endif
22 22
 #endif
23 23
 
24
-
25 24
 void memtest()
26 25
 {
27 26
 #define	TEST_SIZE 1024*1024
... ...
@@ -129,5 +129,7 @@ void memtest()
129 129
 	
130 130
 	exit(0);
131 131
 }
132
+#endif
133
+
132 134
 
133 135
 #endif
... ...
@@ -56,7 +56,6 @@ int check_address(struct ip_addr* ip, char *name, int resolver)
56 56
 	struct hostent* he;
57 57
 	int i;
58 58
 
59
-	return 0;
60 59
 	/* maybe we are lucky and name it's an ip */
61 60
 	if (strcmp(name, ip_addr2a(ip))==0)
62 61
 		return 0;
... ...
@@ -10,6 +10,8 @@
10 10
 
11 11
 #include <netdb.h>
12 12
 
13
+#include "ip_addr.h"
14
+
13 15
 
14 16
 /* gethostbyname wrappers
15 17
  * use this, someday htey will use a local cache */
... ...
@@ -36,7 +38,93 @@ static inline struct hostent* resolvehost(const char* name)
36 36
 
37 37
 
38 38
 
39
+
40
+#define HEX2I(c) \
41
+	(	(((c)>='0') && ((c)<='9'))? (c)-'0' :  \
42
+		(((c)>='A') && ((c)<='F'))? ((c)-'A')+10 : \
43
+		(((c)>='a') && ((c)<='f'))? ((c)-'a')+10 : -1 )
44
+
45
+
39 46
 #define rev_resolvehost(ip) gethostbyaddr((ip)->u.addr, (ip)->len, (ip)->af);
40 47
 
41 48
 
49
+
50
+#if 0
51
+/* returns an ip_addr struct.; on error retunrs 0 and sets err (if !=0)
52
+ * the ip_addr struct is static, so subsequent calls will destroy its 
53
+ * content */
54
+static /*inline*/ struct ip_addr* str2ip6(unsigned char* str, unsigned int len,
55
+		int* err)
56
+{
57
+	int i, idx1, rest;
58
+	int no_colons;
59
+	int double_colon;
60
+	int hex;
61
+	static struct ip_addr ip;
62
+	unsigned short* addr_start;
63
+	unsigned short addr_end[8];
64
+	unsigned short* addr;
65
+	unsigned char* limit;
66
+	unsigned char* init;
67
+	
68
+	/* init */
69
+	init=str;
70
+	i=idx1=rest=0;
71
+	double_colon=0;
72
+	no_colons=0;
73
+	ip.af=AF_INET6;
74
+	ip.len=16;
75
+	addr_start=ip.u.addr16;
76
+	addr=addr_start;
77
+	limit=str+len;
78
+	memset(addr_start, 0 , 8*sizeof(unsigned short));
79
+	memset(addr_end, 0 , 8*sizeof(unsigned short));
80
+	
81
+	for (; str<limit; str++){
82
+		if (*str==':'){
83
+			no_colons++;
84
+			if (no_colons>7) goto error_too_many_colons;
85
+			if (double_colon){
86
+				idx1=i;
87
+				i=0;
88
+				if (addr==addr_end) goto error_colons;
89
+				addr=addr_end;
90
+			}else{
91
+				double_colon=1;
92
+				i++;
93
+			}
94
+		}else if ((hex=HEX2I(*str))>=0){
95
+				addr[i]=addr[i]*16+hex;
96
+				double_colon=0;
97
+		}else{
98
+			/* error, unknown char */
99
+			goto error_char;
100
+		}
101
+	}
102
+	
103
+	rest=8-i-idx1;
104
+	memcpy(addr_start+idx1+rest, addr_end, i*sizeof(unsigned short));
105
+	if (err) *err=0;
106
+	return &ip;
107
+
108
+error_too_many_colons:
109
+	DBG("str2ip6: ERROR: too many colons in [%.*s]\n", (int) len, init);
110
+	if (err) *err=1;
111
+	return 0;
112
+
113
+error_colons:
114
+	DBG("str2ip6: ERROR: too many double colons in [%.*s]\n", (int) len, init);
115
+	if (err) *err=1;
116
+	return 0;
117
+
118
+error_char:
119
+	DBG("str2ip6: WARNING: unexpected char %c in  [%.*s]\n", *str, (int) len,
120
+			init);
121
+	if (err) *err=1;
122
+	return 0;
123
+}
124
+#endif
125
+
126
+
127
+
42 128
 #endif