Browse code

- fixed freebsd version : instead on local on stack sockaddr_in structures use pointers and malloc (why? allignemnt problems???)

Andrei Pelinescu-Onciul authored on 06/09/2001 03:58:35
Showing 3 changed files
... ...
@@ -69,9 +69,16 @@ int forward_request(char * orig, char* buf,
69 69
 	char received_buf[MAX_RECEIVED_SIZE];
70 70
 	char* new_buf;
71 71
 	int offset, s_offset, size;
72
-	struct sockaddr_in to;
72
+	struct sockaddr_in* to;
73 73
 
74 74
 	received_len=0;
75
+	new_buf=0;
76
+	to=0;
77
+	to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
78
+	if (to==0){
79
+		DPrint("ERROR: forward_reply: out of memory\n");
80
+		goto error;
81
+	}
75 82
 
76 83
 	via_len=snprintf(line_buf, MAX_VIA_LINE_SIZE, "Via: SIP/2.0/UDP %s:%d\r\n",
77 84
 						names[0], port_no);
... ...
@@ -86,7 +93,7 @@ int forward_request(char * orig, char* buf,
86 86
 	new_buf=(char*)malloc(new_len+1);
87 87
 	if (new_buf==0){
88 88
 		DPrint("ERROR: forward_request: out of memory\n");
89
-		goto error1;
89
+		goto error;
90 90
 	}
91 91
 /* copy msg till first via */
92 92
 	offset=s_offset=0;
... ...
@@ -123,8 +130,8 @@ int forward_request(char * orig, char* buf,
123 123
 	printf("orig. len=%d, new_len=%d, via_len=%d, received_len=%d\n",
124 124
 			len, new_len, via_len, received_len);
125 125
 
126
-	to.sin_family = AF_INET;
127
-	to.sin_port = (re->port)?htons(re->port):htons(SIP_PORT);
126
+	to->sin_family = AF_INET;
127
+	to->sin_port = (re->port)?htons(re->port):htons(SIP_PORT);
128 128
 	/* if error try next ip address if possible */
129 129
 	if (re->ok==0){
130 130
 		if (re->host.h_addr_list[re->current_addr_idx+1])
... ...
@@ -132,21 +139,22 @@ int forward_request(char * orig, char* buf,
132 132
 		re->ok=1;
133 133
 	}
134 134
 	/* ? not 64bit clean?*/
135
-	to.sin_addr.s_addr=*((long*)re->host.h_addr_list[re->current_addr_idx]);
135
+	to->sin_addr.s_addr=*((long*)re->host.h_addr_list[re->current_addr_idx]);
136 136
 
137 137
 	re->tx++;
138 138
 	re->tx_bytes+=new_len;
139
-	if (udp_send(new_buf, new_len, &to, sizeof(to))==-1){
139
+	if (udp_send(new_buf, new_len, to, sizeof(struct sockaddr))==-1){
140 140
 			re->errors++;
141 141
 			re->ok=0;
142 142
 			goto error;
143 143
 	}
144 144
 
145 145
 	free(new_buf);
146
+	free(to);
146 147
 	return 0;
147 148
 error:
148
-	free(new_buf);
149
-error1:
149
+	if (new_buf) free(new_buf);
150
+	if (to) free(to);
150 151
 	return -1;
151 152
 
152 153
 }
... ...
@@ -164,9 +172,15 @@ int forward_reply(char * orig, char* buf,
164 164
 	char* new_buf;
165 165
 	int offset, s_offset, size;
166 166
 	struct hostent* he;
167
-	struct sockaddr_in to;
167
+	struct sockaddr_in* to;
168 168
 
169 169
 	new_buf=0;
170
+	to=0;
171
+	to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
172
+	if (to==0){
173
+		DPrint("ERROR: forward_reply: out of memory\n");
174
+		goto error;
175
+	}
170 176
 
171 177
 	/*check if first via host = us */
172 178
 	if (check_via){
... ...
@@ -209,17 +223,19 @@ int forward_reply(char * orig, char* buf,
209 209
 		DPrint("ERROR:forward_reply:gethostbyname failure\n");
210 210
 		goto error;
211 211
 	}
212
-	to.sin_family = AF_INET;
213
-	to.sin_port = (msg->via2.port)?htons(msg->via2.port):htons(SIP_PORT);
214
-	to.sin_addr.s_addr=*((long*)he->h_addr_list[0]);
212
+	to->sin_family = AF_INET;
213
+	to->sin_port = (msg->via2.port)?htons(msg->via2.port):htons(SIP_PORT);
214
+	to->sin_addr.s_addr=*((long*)he->h_addr_list[0]);
215 215
 	
216 216
 	if (udp_send(new_buf,new_len, &to, sizeof(to))==-1)
217 217
 		goto error;
218 218
 	
219 219
 	free(new_buf);
220
+	free(to);
220 221
 	return 0;
221 222
 
222 223
 error:
223 224
 	if (new_buf) free(new_buf);
225
+	if (to) free(to);
224 226
 	return -1;
225 227
 }
... ...
@@ -4,7 +4,7 @@
4 4
 #  method_re   sip_uri_re      dest_host
5 5
 # (warning: re cannot contain space)
6 6
 
7
-#.*			.*				   centauri.fokus.gmd.de 
7
+.*			.*				   mobile50 
8 8
 .			.				   fox.iptel.org
9 9
 ^R.*        ^sip:.*@dorian.*   ekina.fokus.gmd.de        
10 10
 ^INVITE     .*                 ape:5061             # my laptop
... ...
@@ -19,12 +19,17 @@ int udp_sock;
19 19
 
20 20
 int udp_init(unsigned long ip, unsigned short port)
21 21
 {
22
-	struct sockaddr_in addr;
22
+	struct sockaddr_in* addr;
23 23
 	int optval;
24 24
 
25
-	addr.sin_family=AF_INET;
26
-	addr.sin_port=htons(port);
27
-	addr.sin_addr.s_addr=ip;
25
+	addr=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
26
+	if (addr==0){
27
+		DPrint("ERROR: udp_init: out of memory\n");
28
+		goto error;
29
+	}
30
+	addr->sin_family=AF_INET;
31
+	addr->sin_port=htons(port);
32
+	addr->sin_addr.s_addr=ip;
28 33
 
29 34
 	udp_sock = socket(PF_INET, SOCK_DGRAM, 0);
30 35
 	if (udp_sock==-1){
... ...
@@ -40,15 +45,16 @@ int udp_init(unsigned long ip, unsigned short port)
40 40
 		goto error;
41 41
 	}
42 42
 
43
-	if (bind(udp_sock, (struct sockaddr*) &addr, sizeof(addr))==-1){
43
+	if (bind(udp_sock, (struct sockaddr*) addr, sizeof(struct sockaddr))==-1){
44 44
 		DPrint("ERROR: udp_init: bind: %s\n", strerror());
45 45
 		goto error;
46 46
 	}
47 47
 
48
-
48
+	free(addr);
49 49
 	return 0;
50 50
 
51 51
 error:
52
+	if (addr) free(addr);
52 53
 	return -1;
53 54
 }
54 55