Browse code

- more warnings fixed, this times solaris/sun cc 5.3

Andrei Pelinescu-Onciul authored on 14/07/2004 20:58:58
Showing 2 changed files
... ...
@@ -39,11 +39,9 @@
39 39
  *  2003-04-03  added su_setport (andrei)
40 40
  *  2003-04-04  update_sock_struct_from_via now differentiates between
41 41
  *               local replies  & "normal" replies (andrei)
42
- *  2003-04-12  update_sock_struct_from via uses also FL_FORCE_RPORT for
42
+ *  2003-04-12  update_sock_struct_form via uses also FL_FORCE_RPORT for
43 43
  *               local replies (andrei)
44 44
  *  2003-08-21  check_self properly handles ipv6 addresses & refs   (andrei)
45
- *  2003-10-21  check_self updated to handle proto (andrei)
46
- *  2003-10-24  converted to the new socket_info lists (andrei)
47 45
  */
48 46
 
49 47
 
... ...
@@ -72,7 +70,6 @@
72 70
 #include "ip_addr.h"
73 71
 #include "resolve.h"
74 72
 #include "name_alias.h"
75
-#include "socket_info.h"
76 73
 
77 74
 #ifdef DEBUG_DMALLOC
78 75
 #include <dmalloc.h>
... ...
@@ -89,14 +86,15 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto)
89 86
 {
90 87
 	int temp_sock;
91 88
 	socklen_t len;
89
+	int r;
92 90
 	union sockaddr_union from; 
93
-	struct socket_info* si;
94 91
 
95 92
 	if (proto!=PROTO_UDP) {
96 93
 		LOG(L_CRIT, "BUG: get_out_socket can only be called for UDP\n");
97 94
 		return 0;
98 95
 	}
99
-	
96
+
97
+	r=-1;
100 98
 	temp_sock=socket(to->s.sa_family, SOCK_DGRAM, 0 );
101 99
 	if (temp_sock==-1) {
102 100
 		LOG(L_ERR, "ERROR: get_out_socket: socket() failed: %s\n",
... ...
@@ -114,39 +112,38 @@ struct socket_info* get_out_socket(union sockaddr_union* to, int proto)
114 112
 				strerror(errno));
115 113
 		goto error;
116 114
 	}
117
-	for (si=udp_listen; si; si=si->next) {
115
+	for (r=0; r<sock_no; r++) {
118 116
 		switch(from.s.sa_family) {
119 117
 			case AF_INET:	
120
-						if (si->address.af!=AF_INET)
118
+						if (sock_info[r].address.af!=AF_INET)
121 119
 								continue;
122
-						if (memcmp(&si->address.u,
120
+						if (memcmp(&sock_info[r].address.u,
123 121
 								&from.sin.sin_addr, 
124
-								si->address.len)==0)
125
-							goto found; /*  success */
122
+								sock_info[r].address.len)==0)
123
+							goto error; /* it is actually success */
126 124
 						break;
127 125
 #if defined(USE_IPV6)
128 126
 			case AF_INET6:	
129
-						if (si->address.af!=AF_INET6)
127
+						if (sock_info[r].address.af!=AF_INET6)
130 128
 								continue;
131
-						if (memcmp(&si->address.u,
129
+						if (memcmp(&sock_info[r].address.u,
132 130
 								&from.sin6.sin6_addr, len)==0)
133
-							goto found;
131
+							goto error;
134 132
 						continue;
135 133
 #endif
136 134
 			default:	LOG(L_ERR, "ERROR: get_out_socket: "
137 135
 									"unknown family: %d\n",
138 136
 									from.s.sa_family);
137
+						r=-1;
139 138
 						goto error;
140 139
 		}
141 140
 	}
142
-error:
143 141
 	LOG(L_ERR, "ERROR: get_out_socket: no socket found\n");
142
+	r=-1;
143
+error:
144 144
 	close(temp_sock);
145
-	return 0;
146
-found:
147
-	close(temp_sock);
148
-	DBG("DEBUG: get_out_socket: socket determined: %p\n", si );
149
-	return si;
145
+	DBG("DEBUG: get_out_socket: socket determined: %d\n", r );
146
+	return r==-1? 0: &sock_info[r];
150 147
 }
151 148
 
152 149
 
... ...
@@ -221,19 +218,17 @@ struct socket_info* get_send_socket(union sockaddr_union* to, int proto)
221 218
 
222 219
 
223 220
 
224
-/* checks if the proto: host:port is one of the address we listen on;
221
+/* checks if the host:port is one of the address we listen on;
225 222
  * if port==0, the  port number is ignored
226
- * if proto==0 (PROTO_NONE) the protocol is ignored
227 223
  * returns 1 if true, 0 if false, -1 on error
228 224
  * WARNING: uses str2ip6 so it will overwrite any previous
229 225
  *  unsaved result of this function (static buffer)
230 226
  */
231
-int check_self(str* host, unsigned short port, unsigned short proto)
227
+int check_self(str* host, unsigned short port)
232 228
 {
229
+	int r;
233 230
 	char* hname;
234 231
 	int h_len;
235
-	struct socket_info* si;
236
-	unsigned short c_proto;
237 232
 #ifdef USE_IPV6
238 233
 	struct ip_addr* ip6;
239 234
 #endif
... ...
@@ -247,80 +242,59 @@ int check_self(str* host, unsigned short port, unsigned short proto)
247 242
 		h_len-=2;
248 243
 	}
249 244
 #endif
250
-	c_proto=proto?proto:PROTO_UDP;
251
-	do{
252
-		/* get the proper sock list */
253
-		switch(c_proto){
254
-			case PROTO_NONE: /* we'll use udp and not all the lists FIXME: */
255
-			case PROTO_UDP:
256
-				si=udp_listen;
257
-				break;
258
-#ifdef USE_TCP
259
-			case PROTO_TCP:
260
-				si=tcp_listen;
261
-				break;
262
-#endif
245
+	for (r=0; r<sock_no; r++){
246
+		DBG("check_self - checking if host==us: %d==%d && "
247
+				" [%.*s] == [%.*s]\n", 
248
+					h_len,
249
+					sock_info[r].name.len,
250
+					h_len, hname,
251
+					sock_info[r].name.len, sock_info[r].name.s
252
+			);
253
+		if (port) {
254
+			DBG("check_self - checking if port %d matches port %d\n", 
255
+					sock_info[r].port_no, port);
263 256
 #ifdef USE_TLS
264
-			case PROTO_TLS:
265
-				si=tls_listen;
266
-				break;
257
+			if  ((sock_info[r].port_no!=port) && (tls_info[r].port_no!=port)) {
258
+#else
259
+			if (sock_info[r].port_no!=port) {
267 260
 #endif
268
-			default:
269
-				/* unknown proto */
270
-				LOG(L_WARN, "WARNING: check_self: "
271
-							"unknown proto %d\n", c_proto);
272
-				return 0; /* false */
273
-		}
274
-		for (; si; si=si->next){
275
-			DBG("check_self - checking if host==us: %d==%d && "
276
-					" [%.*s] == [%.*s]\n", 
277
-						h_len,
278
-						si->name.len,
279
-						h_len, hname,
280
-						si->name.len, si->name.s
281
-				);
282
-			if (port) {
283
-				DBG("check_self - checking if port %d matches port %d\n", 
284
-						si->port_no, port);
285
-				if (si->port_no!=port) {
286
-					continue;
287
-				}
261
+				continue;
288 262
 			}
289
-			if ( (h_len==si->name.len) && 
290
-				(strncasecmp(hname, si->name.s,
291
-						 si->name.len)==0) /*slower*/)
292
-				/* comp. must be case insensitive, host names
293
-				 * can be written in mixed case, it will also match
294
-				 * ipv6 addresses if we are lucky*/
295
-				goto found;
296
-		/* check if host == ip address */
263
+		}
264
+		if ( (h_len==sock_info[r].name.len) && 
265
+			(strncasecmp(hname, sock_info[r].name.s,
266
+				     sock_info[r].name.len)==0) /*slower*/)
267
+			/* comp. must be case insensitive, host names
268
+			 * can be written in mixed case, it will also match
269
+			 * ipv6 addresses if we are lucky*/
270
+			break;
271
+	/* check if host == ip address */
297 272
 #ifdef USE_IPV6
298
-			/* ipv6 case is uglier, host can be [3ffe::1] */
299
-			ip6=str2ip6(host);
300
-			if (ip6){
301
-				if (ip_addr_cmp(ip6, &si->address))
302
-					goto found; /* match */
303
-				else
304
-					continue; /* no match, but this is an ipv6 address
305
-								 so no point in trying ipv4 */
306
-			}
273
+		/* ipv6 case is uglier, host can be [3ffe::1] */
274
+		ip6=str2ip6(host);
275
+		if (ip6){
276
+			if (ip_addr_cmp(ip6, &sock_info[r].address))
277
+				break; /* match */
278
+			else
279
+				continue; /* no match, but this is an ipv6 address
280
+							 so no point in trying ipv4 */
281
+		}
307 282
 #endif
308
-			/* ipv4 */
309
-			if ( 	(!(si->flags&SI_IS_IP)) &&
310
-					(h_len==si->address_str.len) && 
311
-				(memcmp(hname, si->address_str.s, 
312
-									si->address_str.len)==0)
313
-				)
314
-				goto found;
283
+		/* ipv4 */
284
+		if ( 	(!sock_info[r].is_ip) &&
285
+				(h_len==sock_info[r].address_str.len) && 
286
+			(memcmp(hname, sock_info[r].address_str.s, 
287
+								sock_info[r].address_str.len)==0)
288
+			)
289
+			break;
290
+	}
291
+	if (r==sock_no){
292
+		/* try to look into the aliases*/
293
+		if (grep_aliases(hname, h_len, port)==0){
294
+			DBG("check_self: host != me\n");
295
+			return 0;
315 296
 		}
316
-	}while( (proto==0) && (c_proto=next_proto(c_proto)) );
317
-	
318
-	/* try to look into the aliases*/
319
-	if (grep_aliases(hname, h_len, port, proto)==0){
320
-		DBG("check_self: host != me\n");
321
-		return 0;
322 297
 	}
323
-found:
324 298
 	return 1;
325 299
 }
326 300
 
... ...
@@ -513,8 +487,7 @@ int forward_reply(struct sip_msg* msg)
513 487
 	/*check if first via host = us */
514 488
 	if (check_via){
515 489
 		if (check_self(&msg->via1->host,
516
-					msg->via1->port?msg->via1->port:SIP_PORT,
517
-					msg->via1->proto)!=1){
490
+					msg->via1->port?msg->via1->port:SIP_PORT)!=1){
518 491
 			LOG(L_NOTICE, "ERROR: forward_reply: host in first via!=me :"
519 492
 					" %.*s:%d\n", msg->via1->host.len, msg->via1->host.s,
520 493
 									msg->via1->port);
... ...
@@ -536,7 +509,7 @@ int forward_reply(struct sip_msg* msg)
536 509
 		|| (msg->via2==0) || (msg->via2->error!=PARSE_OK))
537 510
 	{
538 511
 		/* no second via => error */
539
-		LOG(L_ERR, "ERROR: forward_msg: no 2nd via found in reply\n");
512
+		LOG(L_ERR, "ERROR: forward_reply: no 2nd via found in reply\n");
540 513
 		goto error;
541 514
 	}
542 515
 
... ...
@@ -397,7 +397,7 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
397 397
 
398 398
 
399 399
 
400
-char* clen_builder(struct sip_msg* msg, unsigned int *clen_len, int diff)
400
+char* clen_builder(struct sip_msg* msg, int *clen_len, int diff)
401 401
 {
402 402
 	char* buf;
403 403
 	int len;