Prechádzať zdrojové kódy

- ipv6 received= debugging

Andrei Pelinescu-Onciul 23 rokov pred
rodič
commit
c6c85c8e91
3 zmenil súbory, kde vykonal 91 pridanie a 2 odobranie
  1. 3 1
      mem/memtest.c
  2. 0 1
      msg_translator.c
  3. 88 0
      resolve.h

+ 3 - 1
mem/memtest.c

@@ -3,6 +3,7 @@
 #include "../globals.h"
 #include "../config.h"
 
+#if 0
 #ifdef PKG_MALLOC
 #       ifdef VQ_MALLOC
 #               include "vq_malloc.h"
@@ -21,7 +22,6 @@
 #       endif
 #endif
 
-
 void memtest()
 {
 #define	TEST_SIZE 1024*1024
@@ -129,5 +129,7 @@ void memtest()
 	
 	exit(0);
 }
+#endif
+
 
 #endif

+ 0 - 1
msg_translator.c

@@ -56,7 +56,6 @@ int check_address(struct ip_addr* ip, char *name, int resolver)
 	struct hostent* he;
 	int i;
 
-	return 0;
 	/* maybe we are lucky and name it's an ip */
 	if (strcmp(name, ip_addr2a(ip))==0)
 		return 0;

+ 88 - 0
resolve.h

@@ -10,6 +10,8 @@
 
 #include <netdb.h>
 
+#include "ip_addr.h"
+
 
 /* gethostbyname wrappers
  * use this, someday htey will use a local cache */
@@ -36,7 +38,93 @@ static inline struct hostent* resolvehost(const char* name)
 
 
 
+
+#define HEX2I(c) \
+	(	(((c)>='0') && ((c)<='9'))? (c)-'0' :  \
+		(((c)>='A') && ((c)<='F'))? ((c)-'A')+10 : \
+		(((c)>='a') && ((c)<='f'))? ((c)-'a')+10 : -1 )
+
+
 #define rev_resolvehost(ip) gethostbyaddr((ip)->u.addr, (ip)->len, (ip)->af);
 
 
+
+#if 0
+/* returns an ip_addr struct.; on error retunrs 0 and sets err (if !=0)
+ * the ip_addr struct is static, so subsequent calls will destroy its 
+ * content */
+static /*inline*/ struct ip_addr* str2ip6(unsigned char* str, unsigned int len,
+		int* err)
+{
+	int i, idx1, rest;
+	int no_colons;
+	int double_colon;
+	int hex;
+	static struct ip_addr ip;
+	unsigned short* addr_start;
+	unsigned short addr_end[8];
+	unsigned short* addr;
+	unsigned char* limit;
+	unsigned char* init;
+	
+	/* init */
+	init=str;
+	i=idx1=rest=0;
+	double_colon=0;
+	no_colons=0;
+	ip.af=AF_INET6;
+	ip.len=16;
+	addr_start=ip.u.addr16;
+	addr=addr_start;
+	limit=str+len;
+	memset(addr_start, 0 , 8*sizeof(unsigned short));
+	memset(addr_end, 0 , 8*sizeof(unsigned short));
+	
+	for (; str<limit; str++){
+		if (*str==':'){
+			no_colons++;
+			if (no_colons>7) goto error_too_many_colons;
+			if (double_colon){
+				idx1=i;
+				i=0;
+				if (addr==addr_end) goto error_colons;
+				addr=addr_end;
+			}else{
+				double_colon=1;
+				i++;
+			}
+		}else if ((hex=HEX2I(*str))>=0){
+				addr[i]=addr[i]*16+hex;
+				double_colon=0;
+		}else{
+			/* error, unknown char */
+			goto error_char;
+		}
+	}
+	
+	rest=8-i-idx1;
+	memcpy(addr_start+idx1+rest, addr_end, i*sizeof(unsigned short));
+	if (err) *err=0;
+	return &ip;
+
+error_too_many_colons:
+	DBG("str2ip6: ERROR: too many colons in [%.*s]\n", (int) len, init);
+	if (err) *err=1;
+	return 0;
+
+error_colons:
+	DBG("str2ip6: ERROR: too many double colons in [%.*s]\n", (int) len, init);
+	if (err) *err=1;
+	return 0;
+
+error_char:
+	DBG("str2ip6: WARNING: unexpected char %c in  [%.*s]\n", *str, (int) len,
+			init);
+	if (err) *err=1;
+	return 0;
+}
+#endif
+
+
+
 #endif