Browse code

- as a resulkt of yesterdays updates now via->host.s contains [] for ipv6 addresses => updated check_via_address and via start of params computations accordingly

Andrei Pelinescu-Onciul authored on 10/07/2003 15:04:43
Showing 1 changed files
... ...
@@ -48,6 +48,10 @@
48 48
  *              => ip:port;transport=proto (andrei)
49 49
  * 2003-04-12  added FL_FORCE_RPORT support (andrei)
50 50
  * 2003-04-13  updated warning builder -- fixed (andrei)
51
+ * 2003-07-10  check_via_address knows now how to compare with ipv6 address
52
+ *              references (e.g [::1]) (andrei)
53
+ *             build_req_fomr_sip_req no longer adds 1 for ipv6 via parameter
54
+ *              position calculations ([] are part of host.s now) (andrei)
51 55
  *
52 56
  */
53 57
 /* Via special params:
... ...
@@ -148,15 +152,25 @@ static int check_via_address(struct ip_addr* ip, str *name,
148 148
 	struct hostent* he;
149 149
 	int i;
150 150
 	char* s;
151
+	int len;
151 152
 
152 153
 	/* maybe we are lucky and name it's an ip */
153 154
 	s=ip_addr2a(ip);
154 155
 	if (s){
155
-		DBG("check_address(%s, %.*s, %d)\n", 
156
+		DBG("check_via_address(%s, %.*s, %d)\n", 
156 157
 			s, name->len, name->s, resolver);
158
+		len=strlen(s);
157 159
 
158 160
 	#ifdef USE_IPV6
159
-		if ((ip->af==AF_INET6) && (strncasecmp(name->s, s, name->len)==0))
161
+		/* check if name->s is an ipv6 address or an ipv6 address ref. */
162
+		if ((ip->af==AF_INET6) &&
163
+				(	((len==name->len)&&(strncasecmp(name->s, s, name->len)==0))
164
+					||
165
+					((len==(name->len-2))&&(name->s[0]=='[')&&
166
+						(name->s[name->len-1]==']')&&
167
+						(strncasecmp(name->s+1, s, len)==0))
168
+				)
169
+		   )
160 170
 			return 0;
161 171
 		else
162 172
 	#endif
... ...
@@ -164,13 +178,13 @@ static int check_via_address(struct ip_addr* ip, str *name,
164 164
 			if (strncmp(name->s, s, name->len)==0) 
165 165
 				return 0;
166 166
 	}else{
167
-		LOG(L_CRIT, "check_address: BUG: could not convert ip address\n");
167
+		LOG(L_CRIT, "check_via_address: BUG: could not convert ip address\n");
168 168
 		return -1;
169 169
 	}
170 170
 
171 171
 	if (port==0) port=SIP_PORT;
172 172
 	if (resolver&DO_DNS){
173
-		DBG("check_address: doing dns lookup\n");
173
+		DBG("check_via_address: doing dns lookup\n");
174 174
 		/* try all names ips */
175 175
 		he=sip_resolvehost(name, &port, 0); /* FIXME proto? */
176 176
 		if (he && ip->af==he->h_addrtype){
... ...
@@ -181,7 +195,7 @@ static int check_via_address(struct ip_addr* ip, str *name,
181 181
 		}
182 182
 	}
183 183
 	if (resolver&DO_REV_DNS){
184
-		DBG("check_address: doing rev. dns lookup\n");
184
+		DBG("check_via_address: doing rev. dns lookup\n");
185 185
 		/* try reverse dns */
186 186
 		he=rev_resolvehost(ip);
187 187
 		if (he && (strncmp(he->h_name, name->s, name->len)==0))
... ...
@@ -1255,9 +1269,12 @@ skip_clen:
1255 1255
 				/*size+=strlen(msg->via1->hdr.s+size+1)+1;*/
1256 1256
 				size += msg->via1->port_str.len + 1; /* +1 for ':'*/
1257 1257
 			}
1258
+#if 0
1259
+			/* no longer necessary, now hots.s contains [] */
1258 1260
 		#ifdef USE_IPV6
1259 1261
 			if(send_sock->address.af==AF_INET6) size+=1; /* +1 for ']'*/
1260 1262
 		#endif
1263
+#endif
1261 1264
 	}
1262 1265
 	/* if received needs to be added, add anchor after host and add it, or 
1263 1266
 	 * overwrite the previous one if already present */