Browse code

- sockaddr_union len fixes (needed for bind/sun) - new macro sockaddru_len(su) -> returns the len of a sockaddr_union (sizeof(sockaddr) or sizeof(sockaddr_in6)) - removed the len parameter in udp_send (not needed) and updated the modules using it (im, msilo, sl, tm)

Andrei Pelinescu-Onciul authored on 10/09/2002 13:49:23
Showing 8 changed files
... ...
@@ -152,8 +152,7 @@ int do_action(struct action* a, struct sip_msg* msg)
152 152
 				p->tx_bytes+=msg->len;
153 153
 				send_sock=get_send_socket(to);
154 154
 				if (send_sock!=0){
155
-					ret=udp_send(send_sock, msg->orig, msg->len, to,
156
-									sizeof(union sockaddr_union));
155
+					ret=udp_send(send_sock, msg->orig, msg->len, to);
157 156
 				}else{
158 157
 					ret=-1;
159 158
 				}
... ...
@@ -189,8 +189,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
189 189
 	DBG("Sending:\n%s.\n", buf);
190 190
 	DBG("orig. len=%d, new_len=%d\n", msg->len, len );
191 191
 	
192
-	if (udp_send(send_sock, buf, len,  to,
193
-							sizeof(union sockaddr_union))==-1){
192
+	if (udp_send(send_sock, buf, len,  to)==-1){
194 193
 			ser_error=E_SEND;
195 194
 			p->errors++;
196 195
 			p->ok=0;
... ...
@@ -335,8 +334,7 @@ int forward_reply(struct sip_msg* msg)
335 335
 		goto error;
336 336
 	}
337 337
 
338
-	if (udp_send(send_sock, new_buf,new_len,  to,
339
-				sizeof(union sockaddr_union))==-1)
338
+	if (udp_send(send_sock, new_buf,new_len,  to)==-1)
340 339
 	{
341 340
 		STATS_TX_DROPS;
342 341
 		goto error;
... ...
@@ -54,10 +54,23 @@ struct socket_info{
54 54
 	unsigned short port_no;  /* port number */
55 55
 	str port_no_str; /* port number converted to string -- optimization*/
56 56
 	int is_ip; /* 1 if name is an ip address, 0 if not  -- optimization*/
57
+	union sockaddr_union su; 
57 58
 };
58 59
 
59 60
 
60
-
61
+/* len of the sockaddr */
62
+#ifdef __FreeBSD__
63
+#define sockaddru_len(su)	((su).s.sa_len)
64
+#else
65
+#ifdef USE_IPV6
66
+#define sockaddru_len(su)	\
67
+			(((su).s.sa_family==AF_INET6)?sizeof(struct sockaddr_in6):\
68
+					sizeof(struct sockaddr_in))
69
+#else
70
+#define sockaddru_len(su)	sizeof(struct sockaddr_in)
71
+#endif /*USE_IPV6*/
72
+#endif /*__FreeBSD__*/
73
+	
61 74
 /* inits an ip_addr with the addr. info from a hostent structure
62 75
  * ip = struct ip_addr*
63 76
  * he= struct hostent*
... ...
@@ -23,8 +23,7 @@ int send_pr_buffer( struct retr_buf *rb,
23 23
 	void *buf, int len, char *function, int line )
24 24
 {
25 25
 	if (buf && len && rb )
26
-		return udp_send( rb->send_sock, buf,
27
-			len, &rb->to,  sizeof(union sockaddr_union) ) ;
26
+		return udp_send( rb->send_sock, buf, len, &rb->to) ;
28 27
 	else {
29 28
 		LOG(L_CRIT, "ERROR: sending an empty buffer from %s (%d)\n",
30 29
 			function, line );
... ...
@@ -3,6 +3,7 @@ check_via=1      # (cmd. line: -v)
3 3
 dns=on           # (cmd. line: -r)
4 4
 rev_dns=yes      # (cmd. line: -R)
5 5
 fork=no          # (cmd. line: -D)
6
+fork=yes
6 7
 log_stderror=yes # (cmd line: -E)
7 8
 fifo=/tmp/ser_fifo
8 9
 # for more info: sip_router -h
... ...
@@ -7,7 +7,6 @@
7 7
 
8 8
 debug=9          # debug level (cmd line: -dddddddddd)
9 9
 fork=yes          # (cmd. line: -D)
10
-fork=no
11 10
 log_stderror=yes # (cmd line: -E)
12 11
 #log_stderror=no	# (cmd line: -E)
13 12
 
... ...
@@ -113,26 +113,20 @@ int probe_max_receive_buffer( int udp_sock )
113 113
 int udp_init(struct socket_info* sock_info)
114 114
 {
115 115
 	union sockaddr_union* addr;
116
-	int sock_len;
117 116
 	int optval;
118 117
 
119
-
118
+	addr=&sock_info->su;
119
+/*
120 120
 	addr=(union sockaddr_union*)malloc(sizeof(union sockaddr_union));
121 121
 	if (addr==0){
122 122
 		LOG(L_ERR, "ERROR: udp_init: out of memory\n");
123 123
 		goto error;
124 124
 	}
125
-	
125
+*/
126 126
 	if (init_su(addr, &sock_info->address, htons(sock_info->port_no))<0){
127 127
 		LOG(L_ERR, "ERROR: udp_init: could not init sockaddr_union\n");
128 128
 		goto error;
129 129
 	}
130
-	/*
131
-	addr->sin_family=AF_INET;
132
-	addr->sin_port=htons(port);
133
-	addr->sin_addr.s_addr=ip;
134
-	*/
135
-
136 130
 	
137 131
 	sock_info->socket = socket(AF2PF(addr->s.sa_family), SOCK_DGRAM, 0);
138 132
 	if (sock_info->socket==-1){
... ...
@@ -158,17 +152,11 @@ int udp_init(struct socket_info* sock_info)
158 158
 
159 159
 
160 160
 	if ( probe_max_receive_buffer(sock_info->socket)==-1) goto error;
161
-#ifdef __FreeBSD__
162
-	sock_len=addr->s.sa_len;
163
-#else
164
-	sock_len=sizeof(union sockaddr_union);
165
-#endif
166 161
 	
167
-
168
-	if (bind(sock_info->socket,  &addr->s, sock_len)==-1){
162
+	if (bind(sock_info->socket,  &addr->s, sockaddru_len(*addr))==-1){
169 163
 		LOG(L_ERR, "ERROR: udp_init: bind(%x, %p, %d) on %s: %s\n",
170 164
 				sock_info->socket, &addr->s, 
171
-				sock_len,
165
+				sockaddru_len(*addr),
172 166
 				sock_info->address_str.s,
173 167
 				strerror(errno));
174 168
 	#ifdef USE_IPV6
... ...
@@ -179,11 +167,11 @@ int udp_init(struct socket_info* sock_info)
179 179
 		goto error;
180 180
 	}
181 181
 
182
-	free(addr);
182
+/*	free(addr);*/
183 183
 	return 0;
184 184
 
185 185
 error:
186
-	if (addr) free(addr);
186
+/*	if (addr) free(addr);*/
187 187
 	return -1;
188 188
 }
189 189
 
... ...
@@ -207,6 +195,7 @@ int udp_rcv_loop()
207 207
 		LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n");
208 208
 		goto error;
209 209
 	}
210
+	memset(from, 0 , sizeof(union sockaddr_union));
210 211
 
211 212
 	for(;;){
212 213
 #ifdef DYN_BUF
... ...
@@ -217,7 +206,7 @@ int udp_rcv_loop()
217 217
 			goto error;
218 218
 		}
219 219
 #endif
220
-		fromlen=sizeof(union sockaddr_union);
220
+		fromlen=sockaddru_len(bind_address->su);
221 221
 		len=recvfrom(bind_address->socket, buf, BUF_SIZE, 0, &from->s,
222 222
 											&fromlen);
223 223
 		if (len==-1){
... ...
@@ -335,10 +324,11 @@ qa_passed:
335 335
 
336 336
 /* which socket to use? main socket or new one? */
337 337
 int udp_send(struct socket_info *source, char *buf, unsigned len,
338
-				union sockaddr_union*  to, unsigned tolen)
338
+				union sockaddr_union*  to)
339 339
 {
340 340
 
341 341
 	int n;
342
+	int tolen;
342 343
 
343 344
 #ifdef DBG_MSG_QA
344 345
 	/* aborts on error, does nothing otherwise */
... ...
@@ -348,7 +338,7 @@ int udp_send(struct socket_info *source, char *buf, unsigned len,
348 348
 	}
349 349
 #endif
350 350
 
351
-
351
+	tolen=sockaddru_len(*to);
352 352
 again:
353 353
 	n=sendto(source->socket, buf, len, 0, &to->s, tolen);
354 354
 #ifdef XL_DEBUG
... ...
@@ -15,7 +15,7 @@
15 15
 
16 16
 int udp_init(struct socket_info* si);
17 17
 int udp_send(struct socket_info* source,char *buf, unsigned len,
18
-				union sockaddr_union*  to, unsigned tolen);
18
+				union sockaddr_union*  to);
19 19
 int udp_rcv_loop();
20 20
 
21 21