Browse code

- added ipv6 address reference resolver support

Andrei Pelinescu-Onciul authored on 12/04/2003 20:55:30
Showing 4 changed files
... ...
@@ -21,7 +21,7 @@
21 21
 VERSION = 0
22 22
 PATCHLEVEL = 8
23 23
 SUBLEVEL =   11
24
-EXTRAVERSION = pre16
24
+EXTRAVERSION = pre17
25 25
 
26 26
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
27 27
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -72,7 +72,7 @@
72 72
  *    is performed on the address. If no port is present and a srv lookup is 
73 73
  *    performed the port is taken from the srv lookup. If the srv lookup failed
74 74
  *    or it was not performed, the port is set to the default sip port (5060).
75
- *  - if reply_to_via is off (default) the local reply is ent to the message
75
+ *  - if reply_to_via is off (default) the local reply is sent to the message
76 76
  *    source ip address. The destination port is set to the source port if 
77 77
  *    rport is present or FL_FORCE_RPORT flag is set, to the via port or to
78 78
  *    the default sip port (5060) if neither rport or via port are present.
... ...
@@ -30,7 +30,7 @@
30 30
  /*
31 31
   * History:
32 32
   * -------
33
-  *  2003-02-13  all *proxy fucntions are now proto aware (andrei)
33
+  *  2003-02-13  all *proxy functions are now proto aware (andrei)
34 34
   *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
35 35
   */
36 36
 
... ...
@@ -26,6 +26,10 @@
26 26
  * along with this program; if not, write to the Free Software 
27 27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28 28
  */
29
+/* History:
30
+ * --------
31
+ *  2003-04-12  support for resolving ipv6 address references added (andrei)
32
+ */
29 33
 
30 34
 
31 35
 
... ...
@@ -156,16 +160,13 @@ static inline struct ip_addr* str2ip(str* st)
156 156
 	ip.len=4;
157 157
 	
158 158
 	return &ip;
159
-
160
-
161
-	     /* FIXME: janakj - is this correct ?, we return always 0 here 
162
-	      * Also we could use different loglevels here
163
-	      */
164 159
 error_dots:
165 160
 	DBG("str2ip: ERROR: too many dots in [%.*s]\n", st->len, st->s);
166 161
 	return 0;
167 162
  error_char:
163
+	/*
168 164
 	DBG("str2ip: WARNING: unexpected char %c in [%.*s]\n", *s, st->len, st->s);
165
+	*/
169 166
 	return 0;
170 167
 }
171 168
 
... ...
@@ -187,7 +188,15 @@ static inline struct ip_addr* str2ip6(str* st)
187 187
 	unsigned char* s;
188 188
 	
189 189
 	/* init */
190
-	s=(unsigned char*)st->s;
190
+	if ((st->len) && (st->s[0]=='[')){
191
+		/* skip over [ ] */
192
+		if (st->s[st->len-1]!=']') goto error_char;
193
+		s=(unsigned char*)(st->s+1);
194
+		limit=(unsigned char*)(st->s+st->len-1);
195
+	}else{
196
+		s=(unsigned char*)st->s;
197
+		limit=(unsigned char*)(st->s+st->len);
198
+	}
191 199
 	i=idx1=rest=0;
192 200
 	double_colon=0;
193 201
 	no_colons=0;
... ...
@@ -195,7 +204,6 @@ static inline struct ip_addr* str2ip6(str* st)
195 195
 	ip.len=16;
196 196
 	addr_start=ip.u.addr16;
197 197
 	addr=addr_start;
198
-	limit=(unsigned char*)(st->s+st->len);
199 198
 	memset(addr_start, 0 , 8*sizeof(unsigned short));
200 199
 	memset(addr_end, 0 , 8*sizeof(unsigned short));
201 200
 	for (; s<limit; s++){
... ...
@@ -253,8 +261,9 @@ error_colons:
253 253
 	return 0;
254 254
 
255 255
 error_char:
256
+	/*
256 257
 	DBG("str2ip6: WARNING: unexpected char %c in  [%.*s]\n", *s, st->len,
257
-			st->s);
258
+			st->s);*/
258 259
 	return 0;
259 260
 }
260 261
 
... ...
@@ -267,13 +276,16 @@ struct hostent* sip_resolvehost(str* name, unsigned short* port, int proto);
267 267
 /* gethostbyname wrappers
268 268
  * use this, someday they will use a local cache */
269 269
 
270
-static inline struct hostent* resolvehost(const char* name)
270
+static inline struct hostent* resolvehost(char* name)
271 271
 {
272 272
 	static struct hostent* he=0;
273 273
 #ifdef HAVE_GETIPNODEBYNAME 
274 274
 	int err;
275 275
 	static struct hostent* he2=0;
276 276
 #endif
277
+#ifndef DNS_IP_HACK
278
+	int len;
279
+#endif
277 280
 #ifdef DNS_IP_HACK
278 281
 	struct ip_addr* ip;
279 282
 	str s;
... ...
@@ -291,11 +303,24 @@ static inline struct hostent* resolvehost(const char* name)
291 291
 		return ip_addr2he(&s, ip);
292 292
 	}
293 293
 	
294
+#else /* DNS_IP_HACK */
295
+	len=0;
296
+	if (*name=='['){
297
+		len=strlen(name);
298
+		if (len && (name[len-1]==']')){
299
+			name[len-1]=0; /* remove '[' */
300
+			name++; /* skip '[' */
301
+			goto skip_ipv4;
302
+		}
303
+	}
294 304
 #endif
295 305
 	/* ipv4 */
296 306
 	he=gethostbyname(name);
297 307
 #ifdef USE_IPV6
298 308
 	if(he==0){
309
+#ifndef DNS_IP_HACK
310
+skip_ipv4:
311
+#endif
299 312
 		/*try ipv6*/
300 313
 	#ifdef HAVE_GETHOSTBYNAME2
301 314
 		he=gethostbyname2(name, AF_INET6);
... ...
@@ -308,6 +333,9 @@ static inline struct hostent* resolvehost(const char* name)
308 308
 	#else
309 309
 		#error neither gethostbyname2 or getipnodebyname present
310 310
 	#endif
311
+#ifndef DNS_IP_HACK
312
+		if (len) name[len-2]=']'; /* restore */
313
+#endif
311 314
 	}
312 315
 #endif
313 316
 	return he;