Browse code

- port fix (original port was overwritten with 5060 for non-srv lookups)

Andrei Pelinescu-Onciul authored on 06/10/2006 11:02:58
Showing 1 changed files
... ...
@@ -29,6 +29,7 @@
29 29
 /* History:
30 30
  * --------
31 31
  *  2006-07-13  created by andrei
32
+ *  2006-10-06  port fix (andrei)
32 33
  */
33 34
 
34 35
 #ifdef USE_DNS_CACHE
... ...
@@ -2188,69 +2189,73 @@ int dns_sip_resolve(struct dns_srv_handle* h,  str* name,
2188 2188
 	if ((h->srv==0) && (h->a==0)){
2189 2189
 		h->port=(proto==PROTO_TLS)?SIPS_PORT:SIP_PORT; /* just in case we
2190 2190
 														don't find another */
2191
-		if ((port) && (*port==0)){
2192
-			/* try SRV if initial call & no port specified
2193
-			 * (draft-ietf-sip-srv-06) */
2194
-			*port=h->port;
2195
-			if ((name->len+SRV_MAX_PREFIX_LEN+1)>MAX_DNS_NAME){
2196
-				LOG(L_WARN, "WARNING: dns_sip_resolvehost: domain name too"
2197
-							" long (%d), unable to perform SRV lookup\n",
2198
-							name->len);
2199
-			}else{
2200
-				/* check if it's an ip address */
2201
-				if ( ((tmp_ip=str2ip(name))!=0)
2191
+		if (port){
2192
+			if (*port==0){
2193
+				/* try SRV if initial call & no port specified
2194
+				 * (draft-ietf-sip-srv-06) */
2195
+				if ((name->len+SRV_MAX_PREFIX_LEN+1)>MAX_DNS_NAME){
2196
+					LOG(L_WARN, "WARNING: dns_sip_resolvehost: domain name too"
2197
+								" long (%d), unable to perform SRV lookup\n",
2198
+								name->len);
2199
+				}else{
2200
+					/* check if it's an ip address */
2201
+					if ( ((tmp_ip=str2ip(name))!=0)
2202 2202
 #ifdef	USE_IPV6
2203
-					  || ((tmp_ip=str2ip6(name))!=0)
2203
+						  || ((tmp_ip=str2ip6(name))!=0)
2204 2204
 #endif
2205
-					){
2206
-					/* we are lucky, this is an ip address */
2205
+						){
2206
+						/* we are lucky, this is an ip address */
2207 2207
 #ifdef	USE_IPV6
2208
-					if (((flags&DNS_IPV4_ONLY) && (tmp_ip->af==AF_INET6)) ||
2209
-						((flags&DNS_IPV6_ONLY) && (tmp_ip->af==AF_INET))){
2210
-						return -E_DNS_AF_MISMATCH;
2211
-					}
2208
+						if (((flags&DNS_IPV4_ONLY) && (tmp_ip->af==AF_INET6))||
2209
+							((flags&DNS_IPV6_ONLY) && (tmp_ip->af==AF_INET))){
2210
+							return -E_DNS_AF_MISMATCH;
2211
+						}
2212 2212
 #endif
2213
-					*ip=*tmp_ip;
2214
-					return 0;
2215
-				}
2216
-				
2217
-				switch(proto){
2218
-					case PROTO_NONE: /* no proto specified, use udp */
2219
-						goto skip_srv;
2220
-					case PROTO_UDP:
2221
-						memcpy(tmp, SRV_UDP_PREFIX, SRV_UDP_PREFIX_LEN);
2222
-						memcpy(tmp+SRV_UDP_PREFIX_LEN, name->s, name->len);
2223
-						tmp[SRV_UDP_PREFIX_LEN + name->len] = '\0';
2224
-						len=SRV_UDP_PREFIX_LEN + name->len;
2225
-						break;
2226
-					case PROTO_TCP:
2227
-						memcpy(tmp, SRV_TCP_PREFIX, SRV_TCP_PREFIX_LEN);
2228
-						memcpy(tmp+SRV_TCP_PREFIX_LEN, name->s, name->len);
2229
-						tmp[SRV_TCP_PREFIX_LEN + name->len] = '\0';
2230
-						len=SRV_TCP_PREFIX_LEN + name->len;
2231
-						break;
2232
-					case PROTO_TLS:
2233
-						memcpy(tmp, SRV_TLS_PREFIX, SRV_TLS_PREFIX_LEN);
2234
-						memcpy(tmp+SRV_TLS_PREFIX_LEN, name->s, name->len);
2235
-						tmp[SRV_TLS_PREFIX_LEN + name->len] = '\0';
2236
-						len=SRV_TLS_PREFIX_LEN + name->len;
2237
-						break;
2238
-					default:
2239
-						LOG(L_CRIT, "BUG: sip_resolvehost: unknown proto %d\n",
2240
-									proto);
2241
-						return -E_DNS_CRITICAL;
2242
-				}
2243
-				srv_name.s=tmp;
2244
-				srv_name.len=len;
2245
-				
2246
-				if ((ret=dns_srv_resolve_ip(h, &srv_name, ip, port, flags))>=0)
2247
-				{
2248
-					DBG("dns_sip_resolve(%.*s, %d, %d), srv0, ret=%d\n", 
2249
-						name->len, name->s, h->srv_no, h->ip_no, ret);
2250
-					return ret;
2213
+						*ip=*tmp_ip;
2214
+						return 0;
2215
+					}
2216
+					
2217
+					switch(proto){
2218
+						case PROTO_NONE: /* no proto specified, use udp */
2219
+							goto skip_srv;
2220
+						case PROTO_UDP:
2221
+							memcpy(tmp, SRV_UDP_PREFIX, SRV_UDP_PREFIX_LEN);
2222
+							memcpy(tmp+SRV_UDP_PREFIX_LEN, name->s, name->len);
2223
+							tmp[SRV_UDP_PREFIX_LEN + name->len] = '\0';
2224
+							len=SRV_UDP_PREFIX_LEN + name->len;
2225
+							break;
2226
+						case PROTO_TCP:
2227
+							memcpy(tmp, SRV_TCP_PREFIX, SRV_TCP_PREFIX_LEN);
2228
+							memcpy(tmp+SRV_TCP_PREFIX_LEN, name->s, name->len);
2229
+							tmp[SRV_TCP_PREFIX_LEN + name->len] = '\0';
2230
+							len=SRV_TCP_PREFIX_LEN + name->len;
2231
+							break;
2232
+						case PROTO_TLS:
2233
+							memcpy(tmp, SRV_TLS_PREFIX, SRV_TLS_PREFIX_LEN);
2234
+							memcpy(tmp+SRV_TLS_PREFIX_LEN, name->s, name->len);
2235
+							tmp[SRV_TLS_PREFIX_LEN + name->len] = '\0';
2236
+							len=SRV_TLS_PREFIX_LEN + name->len;
2237
+							break;
2238
+						default:
2239
+							LOG(L_CRIT, "BUG: sip_resolvehost: "
2240
+									"unknown proto %d\n", proto);
2241
+							return -E_DNS_CRITICAL;
2242
+					}
2243
+					srv_name.s=tmp;
2244
+					srv_name.len=len;
2245
+					
2246
+					if ((ret=dns_srv_resolve_ip(h, &srv_name, ip,
2247
+															port, flags))>=0)
2248
+					{
2249
+						DBG("dns_sip_resolve(%.*s, %d, %d), srv0, ret=%d\n", 
2250
+							name->len, name->s, h->srv_no, h->ip_no, ret);
2251
+						return ret;
2252
+					}
2251 2253
 				}
2254
+			}else{ /* if (*port==0) */
2255
+				h->port=*port; /* store initial port */
2252 2256
 			}
2253
-		}
2257
+		} /* if (port) */
2254 2258
 	}else if (h->srv){
2255 2259
 			srv_name.s=h->srv->name;
2256 2260
 			srv_name.len=h->srv->name_len;