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 22
 #       endif
22 23
 #endif
23 24
 
24
-
25 25
 void memtest()
26 26
 {
27 27
 #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 38
 
37 39
 
38 40
 
41
+
42
+#define HEX2I(c) \
43
+	(	(((c)>='0') && ((c)<='9'))? (c)-'0' :  \
44
+		(((c)>='A') && ((c)<='F'))? ((c)-'A')+10 : \
45
+		(((c)>='a') && ((c)<='f'))? ((c)-'a')+10 : -1 )
46
+
47
+
39 48
 #define rev_resolvehost(ip) gethostbyaddr((ip)->u.addr, (ip)->len, (ip)->af);
40 49
 
41 50
 
51
+
52
+#if 0
53
+/* returns an ip_addr struct.; on error retunrs 0 and sets err (if !=0)
54
+ * the ip_addr struct is static, so subsequent calls will destroy its 
55
+ * content */
56
+static /*inline*/ struct ip_addr* str2ip6(unsigned char* str, unsigned int len,
57
+		int* err)
58
+{
59
+	int i, idx1, rest;
60
+	int no_colons;
61
+	int double_colon;
62
+	int hex;
63
+	static struct ip_addr ip;
64
+	unsigned short* addr_start;
65
+	unsigned short addr_end[8];
66
+	unsigned short* addr;
67
+	unsigned char* limit;
68
+	unsigned char* init;
69
+	
70
+	/* init */
71
+	init=str;
72
+	i=idx1=rest=0;
73
+	double_colon=0;
74
+	no_colons=0;
75
+	ip.af=AF_INET6;
76
+	ip.len=16;
77
+	addr_start=ip.u.addr16;
78
+	addr=addr_start;
79
+	limit=str+len;
80
+	memset(addr_start, 0 , 8*sizeof(unsigned short));
81
+	memset(addr_end, 0 , 8*sizeof(unsigned short));
82
+	
83
+	for (; str<limit; str++){
84
+		if (*str==':'){
85
+			no_colons++;
86
+			if (no_colons>7) goto error_too_many_colons;
87
+			if (double_colon){
88
+				idx1=i;
89
+				i=0;
90
+				if (addr==addr_end) goto error_colons;
91
+				addr=addr_end;
92
+			}else{
93
+				double_colon=1;
94
+				i++;
95
+			}
96
+		}else if ((hex=HEX2I(*str))>=0){
97
+				addr[i]=addr[i]*16+hex;
98
+				double_colon=0;
99
+		}else{
100
+			/* error, unknown char */
101
+			goto error_char;
102
+		}
103
+	}
104
+	
105
+	rest=8-i-idx1;
106
+	memcpy(addr_start+idx1+rest, addr_end, i*sizeof(unsigned short));
107
+	if (err) *err=0;
108
+	return &ip;
109
+
110
+error_too_many_colons:
111
+	DBG("str2ip6: ERROR: too many colons in [%.*s]\n", (int) len, init);
112
+	if (err) *err=1;
113
+	return 0;
114
+
115
+error_colons:
116
+	DBG("str2ip6: ERROR: too many double colons in [%.*s]\n", (int) len, init);
117
+	if (err) *err=1;
118
+	return 0;
119
+
120
+error_char:
121
+	DBG("str2ip6: WARNING: unexpected char %c in  [%.*s]\n", *str, (int) len,
122
+			init);
123
+	if (err) *err=1;
124
+	return 0;
125
+}
126
+#endif
127
+
128
+
129
+
42 130
 #endif