... | ... |
@@ -116,7 +116,7 @@ int add_rule(struct cfg_line* cl, struct route_elem** head) |
116 | 116 |
/* start copying the host entry.. */ |
117 | 117 |
/* copy h_name */ |
118 | 118 |
len=strlen(he->h_name)+1; |
119 |
- re->host.h_name=(char*)malloc(len); |
|
119 |
+ re->host.h_name=(char*)malloc(sizeof(char) * len); |
|
120 | 120 |
if (re->host.h_name) strncpy(re->host.h_name, he->h_name, len); |
121 | 121 |
else{ |
122 | 122 |
ret=E_OUT_OF_MEM; |
... | ... |
@@ -125,7 +125,7 @@ int add_rule(struct cfg_line* cl, struct route_elem** head) |
125 | 125 |
|
126 | 126 |
/* copy h_aliases */ |
127 | 127 |
for (len=0;he->h_aliases[len];len++); |
128 |
- re->host.h_aliases=(char**)malloc(len+1); |
|
128 |
+ re->host.h_aliases=(char**)malloc(sizeof(char*)*(len+1)); |
|
129 | 129 |
if (re->host.h_aliases==0){ |
130 | 130 |
ret=E_OUT_OF_MEM; |
131 | 131 |
goto error; |
... | ... |
@@ -133,7 +133,7 @@ int add_rule(struct cfg_line* cl, struct route_elem** head) |
133 | 133 |
memset((void*)re->host.h_aliases, 0, sizeof(char*) * (len+1) ); |
134 | 134 |
for (i=0;i<len;i++){ |
135 | 135 |
len2=strlen(he->h_aliases[i])+1; |
136 |
- re->host.h_aliases[i]=(char*)malloc(len2); |
|
136 |
+ re->host.h_aliases[i]=(char*)malloc(sizeof(char)*len2); |
|
137 | 137 |
if (re->host.h_aliases==0){ |
138 | 138 |
ret=E_OUT_OF_MEM; |
139 | 139 |
goto error; |
... | ... |
@@ -142,20 +142,21 @@ int add_rule(struct cfg_line* cl, struct route_elem** head) |
142 | 142 |
} |
143 | 143 |
/* copy h_addr_list */ |
144 | 144 |
for (len=0;he->h_addr_list[len];len++); |
145 |
- re->host.h_addr_list=(char**)malloc(len+1); |
|
145 |
+ re->host.h_addr_list=(char**)malloc(sizeof(char*)*(len+1)); |
|
146 | 146 |
if (re->host.h_addr_list==0){ |
147 | 147 |
ret=E_OUT_OF_MEM; |
148 | 148 |
goto error; |
149 | 149 |
} |
150 | 150 |
memset((void*)re->host.h_addr_list, 0, sizeof(char*) * (len+1) ); |
151 | 151 |
for (i=0;i<len;i++){ |
152 |
- re->host.h_addr_list[i]=(char*)malloc(he->h_length+1); |
|
153 |
- if (re->host.h_addr_list==0){ |
|
152 |
+ re->host.h_addr_list[i]=(char*)malloc(sizeof(char)*he->h_length); |
|
153 |
+ if (re->host.h_addr_list[i]==0){ |
|
154 | 154 |
ret=E_OUT_OF_MEM; |
155 | 155 |
goto error; |
156 | 156 |
} |
157 |
- memcpy(re->host.h_addr_list[i], he->h_addr_list[i], he->h_length+1); |
|
157 |
+ memcpy(re->host.h_addr_list[i], he->h_addr_list[i], he->h_length); |
|
158 | 158 |
} |
159 |
+ |
|
159 | 160 |
/* copy h_addr_type & length */ |
160 | 161 |
re->host.h_addrtype=he->h_addrtype; |
161 | 162 |
re->host.h_length=he->h_length; |
... | ... |
@@ -213,15 +214,16 @@ void print_rl() |
213 | 214 |
DPrint("%2d.to=%s ; route ok=%d\n", i, |
214 | 215 |
t->host.h_name, t->ok); |
215 | 216 |
DPrint(" ips: "); |
216 |
- for (j=0; t->host.h_addr_list[j]; j++) |
|
217 |
- DPrint("%d.%d.%d.%d ", |
|
217 |
+ for (j=0; t->host.h_addr_list[j]; j++){ |
|
218 |
+ DPrint("%d.%d.%d.%d ", |
|
218 | 219 |
(unsigned char) t->host.h_addr_list[j][0], |
219 | 220 |
(unsigned char) t->host.h_addr_list[j][1], |
220 | 221 |
(unsigned char) t->host.h_addr_list[j][2], |
221 | 222 |
(unsigned char) t->host.h_addr_list[j][3] |
222 | 223 |
); |
223 |
- |
|
224 |
- DPrint("\n port:%d\n", (unsigned short)t->port); |
|
224 |
+ } |
|
225 |
+ DPrint("\n"); |
|
226 |
+ DPrint(" port:%d\n", (unsigned short)t->port); |
|
225 | 227 |
DPrint(" Statistics: tx=%d, errors=%d, tx_bytes=%d, idx=%d\n", |
226 | 228 |
t->tx, t->errors, t->tx_bytes, t->current_addr_idx); |
227 | 229 |
} |
... | ... |
@@ -24,6 +24,7 @@ unsigned short our_port; |
24 | 24 |
int udp_init(unsigned long ip, unsigned short port) |
25 | 25 |
{ |
26 | 26 |
struct sockaddr_in addr; |
27 |
+ int optval; |
|
27 | 28 |
|
28 | 29 |
addr.sin_family=AF_INET; |
29 | 30 |
addr.sin_port=htons(port); |
... | ... |
@@ -34,13 +35,20 @@ int udp_init(unsigned long ip, unsigned short port) |
34 | 35 |
DPrint("ERROR: udp_init: socket: %s\n", strerror()); |
35 | 36 |
goto error; |
36 | 37 |
} |
38 |
+ /* set sock opts? */ |
|
39 |
+ optval=1; |
|
40 |
+ if (setsockopt(udp_sock, SOL_SOCKET, SO_REUSEPORT, |
|
41 |
+ &optval, sizeof(optval)) ==-1) |
|
42 |
+ { |
|
43 |
+ DPrint("ERROR: udp_init: setsockopt: %s\n", strerror()); |
|
44 |
+ goto error; |
|
45 |
+ } |
|
37 | 46 |
|
38 | 47 |
if (bind(udp_sock, (struct sockaddr*) &addr, sizeof(addr))==-1){ |
39 |
- DPrint("ERROR: udp_init: socket: %s\n", strerror()); |
|
48 |
+ DPrint("ERROR: udp_init: bind: %s\n", strerror()); |
|
40 | 49 |
goto error; |
41 | 50 |
} |
42 | 51 |
|
43 |
- /* set sock opts? */ |
|
44 | 52 |
|
45 | 53 |
return 0; |
46 | 54 |
|