Browse Source

- added ipv6 address reference resolver support

Andrei Pelinescu-Onciul 22 years ago
parent
commit
a7e13a8997
4 changed files with 40 additions and 12 deletions
  1. 1 1
      Makefile.defs
  2. 1 1
      msg_translator.c
  3. 1 1
      proxy.c
  4. 37 9
      resolve.h

+ 1 - 1
Makefile.defs

@@ -21,7 +21,7 @@
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   11
-EXTRAVERSION = pre16
+EXTRAVERSION = pre17
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 1 - 1
msg_translator.c

@@ -72,7 +72,7 @@
  *    is performed on the address. If no port is present and a srv lookup is 
  *    performed the port is taken from the srv lookup. If the srv lookup failed
  *    or it was not performed, the port is set to the default sip port (5060).
- *  - if reply_to_via is off (default) the local reply is ent to the message
+ *  - if reply_to_via is off (default) the local reply is sent to the message
  *    source ip address. The destination port is set to the source port if 
  *    rport is present or FL_FORCE_RPORT flag is set, to the via port or to
  *    the default sip port (5060) if neither rport or via port are present.

+ 1 - 1
proxy.c

@@ -30,7 +30,7 @@
  /*
   * History:
   * -------
-  *  2003-02-13  all *proxy fucntions are now proto aware (andrei)
+  *  2003-02-13  all *proxy functions are now proto aware (andrei)
   *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
   */
 

+ 37 - 9
resolve.h

@@ -26,6 +26,10 @@
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/* History:
+ * --------
+ *  2003-04-12  support for resolving ipv6 address references added (andrei)
+ */
 
 
 
@@ -156,16 +160,13 @@ static inline struct ip_addr* str2ip(str* st)
 	ip.len=4;
 	
 	return &ip;
-
-
-	     /* FIXME: janakj - is this correct ?, we return always 0 here 
-	      * Also we could use different loglevels here
-	      */
 error_dots:
 	DBG("str2ip: ERROR: too many dots in [%.*s]\n", st->len, st->s);
 	return 0;
  error_char:
+	/*
 	DBG("str2ip: WARNING: unexpected char %c in [%.*s]\n", *s, st->len, st->s);
+	*/
 	return 0;
 }
 
@@ -187,7 +188,15 @@ static inline struct ip_addr* str2ip6(str* st)
 	unsigned char* s;
 	
 	/* init */
-	s=(unsigned char*)st->s;
+	if ((st->len) && (st->s[0]=='[')){
+		/* skip over [ ] */
+		if (st->s[st->len-1]!=']') goto error_char;
+		s=(unsigned char*)(st->s+1);
+		limit=(unsigned char*)(st->s+st->len-1);
+	}else{
+		s=(unsigned char*)st->s;
+		limit=(unsigned char*)(st->s+st->len);
+	}
 	i=idx1=rest=0;
 	double_colon=0;
 	no_colons=0;
@@ -195,7 +204,6 @@ static inline struct ip_addr* str2ip6(str* st)
 	ip.len=16;
 	addr_start=ip.u.addr16;
 	addr=addr_start;
-	limit=(unsigned char*)(st->s+st->len);
 	memset(addr_start, 0 , 8*sizeof(unsigned short));
 	memset(addr_end, 0 , 8*sizeof(unsigned short));
 	for (; s<limit; s++){
@@ -253,8 +261,9 @@ error_colons:
 	return 0;
 
 error_char:
+	/*
 	DBG("str2ip6: WARNING: unexpected char %c in  [%.*s]\n", *s, st->len,
-			st->s);
+			st->s);*/
 	return 0;
 }
 
@@ -267,13 +276,16 @@ struct hostent* sip_resolvehost(str* name, unsigned short* port, int proto);
 /* gethostbyname wrappers
  * use this, someday they will use a local cache */
 
-static inline struct hostent* resolvehost(const char* name)
+static inline struct hostent* resolvehost(char* name)
 {
 	static struct hostent* he=0;
 #ifdef HAVE_GETIPNODEBYNAME 
 	int err;
 	static struct hostent* he2=0;
 #endif
+#ifndef DNS_IP_HACK
+	int len;
+#endif
 #ifdef DNS_IP_HACK
 	struct ip_addr* ip;
 	str s;
@@ -291,11 +303,24 @@ static inline struct hostent* resolvehost(const char* name)
 		return ip_addr2he(&s, ip);
 	}
 	
+#else /* DNS_IP_HACK */
+	len=0;
+	if (*name=='['){
+		len=strlen(name);
+		if (len && (name[len-1]==']')){
+			name[len-1]=0; /* remove '[' */
+			name++; /* skip '[' */
+			goto skip_ipv4;
+		}
+	}
 #endif
 	/* ipv4 */
 	he=gethostbyname(name);
 #ifdef USE_IPV6
 	if(he==0){
+#ifndef DNS_IP_HACK
+skip_ipv4:
+#endif
 		/*try ipv6*/
 	#ifdef HAVE_GETHOSTBYNAME2
 		he=gethostbyname2(name, AF_INET6);
@@ -308,6 +333,9 @@ static inline struct hostent* resolvehost(const char* name)
 	#else
 		#error neither gethostbyname2 or getipnodebyname present
 	#endif
+#ifndef DNS_IP_HACK
+		if (len) name[len-2]=']'; /* restore */
+#endif
 	}
 #endif
 	return he;