... | ... |
@@ -30,10 +30,17 @@ |
30 | 30 |
#endif |
31 | 31 |
|
32 | 32 |
|
33 |
+struct id_list{ |
|
34 |
+ char* s; |
|
35 |
+ struct id_list* next; |
|
36 |
+}; |
|
37 |
+ |
|
33 | 38 |
extern int yylex(); |
34 | 39 |
void yyerror(char* s); |
35 | 40 |
char* tmp; |
36 | 41 |
void* f_tmp; |
42 |
+struct id_list* lst_tmp; |
|
43 |
+ |
|
37 | 44 |
|
38 | 45 |
%} |
39 | 46 |
|
... | ... |
@@ -45,6 +52,7 @@ void* f_tmp; |
45 | 52 |
struct action* action; |
46 | 53 |
struct net* ipnet; |
47 | 54 |
struct ip_addr* ipaddr; |
55 |
+ struct id_list* idlst; |
|
48 | 56 |
} |
49 | 57 |
|
50 | 58 |
/* terminals */ |
... | ... |
@@ -142,6 +150,8 @@ void* f_tmp; |
142 | 150 |
%type <ipaddr> ipv4, ipv6, ip |
143 | 151 |
%type <ipnet> ipnet |
144 | 152 |
%type <strval> host |
153 |
+%type <strval> listen_id |
|
154 |
+%type <idlst> id_lst |
|
145 | 155 |
/*%type <route_el> rules; |
146 | 156 |
%type <route_el> rule; |
147 | 157 |
*/ |
... | ... |
@@ -166,6 +176,67 @@ statement: assign_stm |
166 | 176 |
| CR /* null statement*/ |
167 | 177 |
; |
168 | 178 |
|
179 |
+listen_id: ip { tmp=ip_addr2a($1); |
|
180 |
+ if(tmp==0){ |
|
181 |
+ LOG(L_CRIT, "ERROR: cfg. parser: bad ip " |
|
182 |
+ "addresss.\n"); |
|
183 |
+ $$=0; |
|
184 |
+ }else{ |
|
185 |
+ $$=malloc(strlen(tmp)+1); |
|
186 |
+ if ($$==0){ |
|
187 |
+ LOG(L_CRIT, "ERROR: cfg. parser: out of " |
|
188 |
+ "memory.\n"); |
|
189 |
+ }else{ |
|
190 |
+ strncpy($$, tmp, strlen(tmp)+1); |
|
191 |
+ } |
|
192 |
+ } |
|
193 |
+ } |
|
194 |
+ | ID { $$=malloc(strlen($1)+1); |
|
195 |
+ if ($$==0){ |
|
196 |
+ LOG(L_CRIT, "ERROR: cfg. parser: out of " |
|
197 |
+ "memory.\n"); |
|
198 |
+ }else{ |
|
199 |
+ strncpy($$, $1, strlen($1)+1); |
|
200 |
+ } |
|
201 |
+ } |
|
202 |
+ | STRING { $$=malloc(strlen($1)+1); |
|
203 |
+ if ($$==0){ |
|
204 |
+ LOG(L_CRIT, "ERROR: cfg. parser: out of " |
|
205 |
+ "memory.\n"); |
|
206 |
+ }else{ |
|
207 |
+ strncpy($$, $1, strlen($1)+1); |
|
208 |
+ } |
|
209 |
+ } |
|
210 |
+ | host { $$=malloc(strlen($1)+1); |
|
211 |
+ if ($$==0){ |
|
212 |
+ LOG(L_CRIT, "ERROR: cfg. parser: out of " |
|
213 |
+ "memory.\n"); |
|
214 |
+ }else{ |
|
215 |
+ strncpy($$, $1, strlen($1)+1); |
|
216 |
+ } |
|
217 |
+ } |
|
218 |
+ ; |
|
219 |
+ |
|
220 |
+id_lst: listen_id { $$=malloc(sizeof(struct id_list)); |
|
221 |
+ if ($$==0){ |
|
222 |
+ LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n"); |
|
223 |
+ }else{ |
|
224 |
+ $$->s=$1; |
|
225 |
+ $$->next=0; |
|
226 |
+ } |
|
227 |
+ } |
|
228 |
+ | listen_id id_lst { |
|
229 |
+ $$=malloc(sizeof(struct id_list)); |
|
230 |
+ if ($$==0){ |
|
231 |
+ LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n"); |
|
232 |
+ }else{ |
|
233 |
+ $$->s=$1; |
|
234 |
+ $$->next=$2; |
|
235 |
+ } |
|
236 |
+ } |
|
237 |
+ ; |
|
238 |
+ |
|
239 |
+ |
|
169 | 240 |
assign_stm: DEBUG EQUAL NUMBER { debug=$3; } |
170 | 241 |
| DEBUG EQUAL error { yyerror("number expected"); } |
171 | 242 |
| FORK EQUAL NUMBER { dont_fork= ! $3; } |
... | ... |
@@ -204,87 +275,21 @@ assign_stm: DEBUG EQUAL NUMBER { debug=$3; } |
204 | 275 |
| SERVER_SIGNATURE EQUAL error { yyerror("boolean value expected"); } |
205 | 276 |
| REPLY_TO_VIA EQUAL NUMBER { reply_to_via=$3; } |
206 | 277 |
| REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); } |
207 |
- | LISTEN EQUAL ip { |
|
208 |
- if (sock_no< MAX_LISTEN){ |
|
209 |
- tmp=ip_addr2a($3); |
|
210 |
- /* tmp=inet_ntoa(*(struct in_addr*)&$3);*/ |
|
211 |
- if (tmp==0){ |
|
212 |
- LOG(L_CRIT, "ERROR: cfg. parser: " |
|
213 |
- " bad ip address: %s\n", |
|
214 |
- strerror(errno)); |
|
215 |
- }else{ |
|
216 |
- sock_info[sock_no].name.s= |
|
217 |
- (char*)malloc(strlen(tmp)+1); |
|
218 |
- if (sock_info[sock_no].name.s==0){ |
|
219 |
- LOG(L_CRIT, "ERROR: cfg. parser: " |
|
220 |
- "out of memory.\n"); |
|
221 |
- }else{ |
|
222 |
- strncpy(sock_info[sock_no].name.s, |
|
223 |
- tmp, strlen(tmp)+1); |
|
224 |
- sock_info[sock_no].name.len= |
|
225 |
- strlen(tmp); |
|
226 |
- sock_info[sock_no].port_no= |
|
227 |
- port_no; |
|
228 |
- sock_no++; |
|
229 |
- } |
|
230 |
- } |
|
231 |
- }else{ |
|
232 |
- LOG(L_CRIT, "ERROR: cfg. parser:" |
|
233 |
- " too many listen addresses" |
|
234 |
- "(max. %d).\n", MAX_LISTEN); |
|
235 |
- } |
|
236 |
- } |
|
237 |
- | LISTEN EQUAL ID { |
|
238 |
- if (sock_no < MAX_LISTEN){ |
|
239 |
- sock_info[sock_no].name.s= |
|
240 |
- (char*)malloc(strlen($3)+1); |
|
241 |
- if (sock_info[sock_no].name.s==0){ |
|
242 |
- LOG(L_CRIT, "ERROR: cfg. parser:" |
|
243 |
- " out of memory.\n"); |
|
244 |
- }else{ |
|
245 |
- strncpy(sock_info[sock_no].name.s, $3, |
|
246 |
- strlen($3)+1); |
|
247 |
- sock_info[sock_no].name.len=strlen($3); |
|
248 |
- sock_info[sock_no].port_no= port_no; |
|
249 |
- sock_no++; |
|
250 |
- } |
|
251 |
- }else{ |
|
252 |
- LOG(L_CRIT, "ERROR: cfg. parser: " |
|
253 |
- "too many listen addresses" |
|
254 |
- "(max. %d).\n", MAX_LISTEN); |
|
255 |
- } |
|
256 |
- } |
|
257 |
- | LISTEN EQUAL STRING { |
|
258 |
- if (sock_no < MAX_LISTEN){ |
|
259 |
- sock_info[sock_no].name.s= |
|
260 |
- (char*)malloc(strlen($3)+1); |
|
261 |
- if (sock_info[sock_no].name.s==0){ |
|
262 |
- LOG(L_CRIT, "ERROR: cfg. parser:" |
|
263 |
- " out of memory.\n"); |
|
264 |
- }else{ |
|
265 |
- strncpy(sock_info[sock_no].name.s, $3, |
|
266 |
- strlen($3)+1); |
|
267 |
- sock_info[sock_no].name.len=strlen($3); |
|
268 |
- sock_info[sock_no].port_no=port_no; |
|
269 |
- sock_no++; |
|
270 |
- } |
|
271 |
- }else{ |
|
272 |
- LOG(L_CRIT, "ERROR: cfg. parser: " |
|
273 |
- "too many listen addresses" |
|
274 |
- "(max. %d).\n", MAX_LISTEN); |
|
275 |
- } |
|
276 |
- } |
|
277 |
- | LISTEN EQUAL host { |
|
278 |
+ | LISTEN EQUAL id_lst { |
|
279 |
+ for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){ |
|
278 | 280 |
if (sock_no < MAX_LISTEN){ |
279 | 281 |
sock_info[sock_no].name.s= |
280 |
- (char*)malloc(strlen($3)+1); |
|
282 |
+ (char*)malloc(strlen(lst_tmp->s)+1); |
|
281 | 283 |
if (sock_info[sock_no].name.s==0){ |
282 | 284 |
LOG(L_CRIT, "ERROR: cfg. parser:" |
283 | 285 |
" out of memory.\n"); |
286 |
+ break; |
|
284 | 287 |
}else{ |
285 |
- strncpy(sock_info[sock_no].name.s, $3, |
|
286 |
- strlen($3)+1); |
|
287 |
- sock_info[sock_no].name.len=strlen($3); |
|
288 |
+ strncpy(sock_info[sock_no].name.s, |
|
289 |
+ lst_tmp->s, |
|
290 |
+ strlen(lst_tmp->s)+1); |
|
291 |
+ sock_info[sock_no].name.len= |
|
292 |
+ strlen(lst_tmp->s); |
|
288 | 293 |
sock_info[sock_no].port_no=port_no; |
289 | 294 |
sock_no++; |
290 | 295 |
} |
... | ... |
@@ -292,14 +297,16 @@ assign_stm: DEBUG EQUAL NUMBER { debug=$3; } |
292 | 297 |
LOG(L_CRIT, "ERROR: cfg. parser: " |
293 | 298 |
"too many listen addresses" |
294 | 299 |
"(max. %d).\n", MAX_LISTEN); |
300 |
+ break; |
|
295 | 301 |
} |
296 |
- } |
|
297 |
- |
|
302 |
+ } |
|
303 |
+ } |
|
298 | 304 |
| LISTEN EQUAL error { yyerror("ip address or hostname" |
299 | 305 |
"expected"); } |
300 |
- | ALIAS EQUAL STRING { add_alias($3, strlen($3)); } |
|
301 |
- | ALIAS EQUAL ID { add_alias($3, strlen($3)); } |
|
302 |
- | ALIAS EQUAL host { add_alias($3, strlen($3)); } |
|
306 |
+ | ALIAS EQUAL id_lst { |
|
307 |
+ for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) |
|
308 |
+ add_alias(lst_tmp->s, strlen(lst_tmp->s)); |
|
309 |
+ } |
|
303 | 310 |
| ALIAS EQUAL error { yyerror(" hostname expected"); } |
304 | 311 |
| error EQUAL { yyerror("unknown config variable"); } |
305 | 312 |
; |
... | ... |
@@ -117,6 +117,30 @@ inline static int matchnet(struct ip_addr* ip, struct net* net) |
117 | 117 |
|
118 | 118 |
|
119 | 119 |
|
120 |
+/* inits an ip_addr pointer from a sockaddr structure*/ |
|
121 |
+static inline void sockaddr2ip_addr(struct ip_addr* ip, struct sockaddr* sa) |
|
122 |
+{ |
|
123 |
+ switch(sa->sa_family){ |
|
124 |
+ case AF_INET: |
|
125 |
+ ip->af=AF_INET; |
|
126 |
+ ip->len=4; |
|
127 |
+ memcpy(ip->u.addr, &((struct sockaddr_in*)sa)->sin_addr, 4); |
|
128 |
+ break; |
|
129 |
+#ifdef USE_IPV6 |
|
130 |
+ case AF_INET6: |
|
131 |
+ ip->af=AF_INET6; |
|
132 |
+ ip->len=16; |
|
133 |
+ memcpy(ip->u.addr, &((struct sockaddr_in6*)sa)->sin6_addr, 16); |
|
134 |
+ break; |
|
135 |
+#endif |
|
136 |
+ default: |
|
137 |
+ LOG(L_CRIT, "sockaddr2ip_addr: BUG: unknown address family %d\n", |
|
138 |
+ sa->sa_family); |
|
139 |
+ } |
|
140 |
+} |
|
141 |
+ |
|
142 |
+ |
|
143 |
+ |
|
120 | 144 |
/* inits an ip_addr pointer from a sockaddr_union ip address */ |
121 | 145 |
static inline void su2ip_addr(struct ip_addr* ip, union sockaddr_union* su) |
122 | 146 |
{ |
... | ... |
@@ -20,6 +20,12 @@ |
20 | 20 |
#include <sys/wait.h> |
21 | 21 |
#include <signal.h> |
22 | 22 |
|
23 |
+#include <sys/ioctl.h> |
|
24 |
+#include <net/if.h> |
|
25 |
+#ifdef __sun__ |
|
26 |
+#include <sys/sockio.h> |
|
27 |
+#endif |
|
28 |
+ |
|
23 | 29 |
#include "config.h" |
24 | 30 |
#include "dprint.h" |
25 | 31 |
#include "route.h" |
... | ... |
@@ -681,14 +687,129 @@ static void sig_usr(int signo) |
681 | 687 |
|
682 | 688 |
|
683 | 689 |
|
684 |
-void test(); |
|
690 |
+/* add all family type addresses of interface if_name to the socket_info array |
|
691 |
+ * if if_name==0, adds all addresses on all interfaces |
|
692 |
+ * WARNING: it only works with ipv6 addresses on FreeBSD |
|
693 |
+ * return: -1 on error, 0 on success |
|
694 |
+ */ |
|
695 |
+int add_interfaces(char* if_name, int family, unsigned short port) |
|
696 |
+{ |
|
697 |
+ struct ifconf ifc; |
|
698 |
+ struct ifreq* ifr; |
|
699 |
+ struct ifreq ifrcopy; |
|
700 |
+ char* last; |
|
701 |
+ int size; |
|
702 |
+ int lastlen; |
|
703 |
+ int s; |
|
704 |
+ char* tmp; |
|
705 |
+ struct ip_addr addr; |
|
706 |
+ int ret; |
|
707 |
+ |
|
708 |
+ /* ipv4 or ipv6 only*/ |
|
709 |
+ s=socket(family, SOCK_DGRAM, 0); |
|
710 |
+ ret=-1; |
|
711 |
+ lastlen=0; |
|
712 |
+ ifc.ifc_req=0; |
|
713 |
+ for (size=10; ; size*=2){ |
|
714 |
+ ifc.ifc_len=size*sizeof(struct ifreq); |
|
715 |
+ ifc.ifc_req=(struct ifreq*) malloc(size*sizeof(struct ifreq)); |
|
716 |
+ if (ifc.ifc_req==0){ |
|
717 |
+ fprintf(stderr, "memory allocation failure\n"); |
|
718 |
+ goto error; |
|
719 |
+ } |
|
720 |
+ if (ioctl(s, SIOCGIFCONF, &ifc)==-1){ |
|
721 |
+ if(errno==EBADF) return 0; /* invalid descriptor => no such ifs*/ |
|
722 |
+ fprintf(stderr, "ioctl failed: %s\n", strerror(errno)); |
|
723 |
+ goto error; |
|
724 |
+ } |
|
725 |
+ if ((lastlen) && (ifc.ifc_len==lastlen)) break; /*success, |
|
726 |
+ len not changed*/ |
|
727 |
+ lastlen=ifc.ifc_len; |
|
728 |
+ /* try a bigger array*/ |
|
729 |
+ free(ifc.ifc_req); |
|
730 |
+ } |
|
731 |
+ |
|
732 |
+ last=(char*)ifc.ifc_req+ifc.ifc_len; |
|
733 |
+ for(ifr=ifc.ifc_req; (char*)ifr<last; |
|
734 |
+ ifr=(struct ifreq*)((char*)ifr+sizeof(ifr->ifr_name)+ |
|
735 |
+ #ifdef __FreeBSD__ |
|
736 |
+ MAX(ifr->ifr_addr.sa_len, sizeof(struct sockaddr)) |
|
737 |
+ #else |
|
738 |
+ ( (ifr->ifr_addr.sa_family==AF_INET)? |
|
739 |
+ sizeof(struct sockaddr_in): |
|
740 |
+ ((ifr->ifr_addr.sa_family==AF_INET6)? |
|
741 |
+ sizeof(struct sockaddr_in6):sizeof(struct sockaddr)) ) |
|
742 |
+ #endif |
|
743 |
+ ) |
|
744 |
+ ) |
|
745 |
+ { |
|
746 |
+ if (ifr->ifr_addr.sa_family!=family){ |
|
747 |
+ /*printf("strange family %d skipping...\n", |
|
748 |
+ ifr->ifr_addr.sa_family);*/ |
|
749 |
+ continue; |
|
750 |
+ } |
|
751 |
+ |
|
752 |
+ if (if_name==0){ /* ignore down ifs only if listening on all of them*/ |
|
753 |
+ memcpy(&ifrcopy, ifr, sizeof(ifrcopy)); |
|
754 |
+ /*get flags*/ |
|
755 |
+ if (ioctl(s, SIOCGIFFLAGS, &ifrcopy)!=-1){ /* ignore errors */ |
|
756 |
+ /* if if not up, skip it*/ |
|
757 |
+ if (!(ifrcopy.ifr_flags & IFF_UP)) continue; |
|
758 |
+ } |
|
759 |
+ } |
|
760 |
+ |
|
761 |
+ |
|
762 |
+ |
|
763 |
+ if ((if_name==0)|| |
|
764 |
+ (strncmp(if_name, ifr->ifr_name, sizeof(ifr->ifr_name))==0)){ |
|
765 |
+ |
|
766 |
+ /*add address*/ |
|
767 |
+ if (sock_no<MAX_LISTEN){ |
|
768 |
+ sockaddr2ip_addr(&addr, &ifr->ifr_addr); |
|
769 |
+ if ((tmp=ip_addr2a(&addr))==0) goto error; |
|
770 |
+ /* fill the strings*/ |
|
771 |
+ sock_info[sock_no].name.s=(char*)malloc(strlen(tmp)+1); |
|
772 |
+ if(sock_info[sock_no].name.s==0){ |
|
773 |
+ fprintf(stderr, "Out of memory.\n"); |
|
774 |
+ goto error; |
|
775 |
+ } |
|
776 |
+ /* fill in the new name and port */ |
|
777 |
+ sock_info[sock_no].name.len=strlen(tmp); |
|
778 |
+ strncpy(sock_info[sock_no].name.s, tmp, |
|
779 |
+ sock_info[sock_no].name.len+1); |
|
780 |
+ sock_info[sock_no].port_no=port; |
|
781 |
+ sock_no++; |
|
782 |
+ ret=0; |
|
783 |
+ }else{ |
|
784 |
+ fprintf(stderr, "Too many addresses (max %d)\n", MAX_LISTEN); |
|
785 |
+ goto error; |
|
786 |
+ } |
|
787 |
+ } |
|
788 |
+ /* |
|
789 |
+ printf("%s:\n", ifr->ifr_name); |
|
790 |
+ printf(" "); |
|
791 |
+ print_sockaddr(&(ifr->ifr_addr)); |
|
792 |
+ printf(" "); |
|
793 |
+ ls_ifflags(ifr->ifr_name, family, options); |
|
794 |
+ printf("\n");*/ |
|
795 |
+ } |
|
796 |
+ free(ifc.ifc_req); /*clean up*/ |
|
797 |
+ close(s); |
|
798 |
+ return ret; |
|
799 |
+error: |
|
800 |
+ if (ifc.ifc_req) free(ifc.ifc_req); |
|
801 |
+ close(s); |
|
802 |
+ return -1; |
|
803 |
+} |
|
804 |
+ |
|
805 |
+ |
|
685 | 806 |
|
686 | 807 |
int main(int argc, char** argv) |
687 | 808 |
{ |
688 | 809 |
|
689 | 810 |
FILE* cfg_stream; |
690 | 811 |
struct hostent* he; |
691 |
- int c,r; |
|
812 |
+ int c,r,t; |
|
692 | 813 |
char *tmp; |
693 | 814 |
char** h; |
694 | 815 |
struct host_alias* a; |
... | ... |
@@ -963,24 +1084,42 @@ int main(int argc, char** argv) |
963 | 1084 |
memset(pids, 0, sizeof(int)*(children_no+1)); |
964 | 1085 |
|
965 | 1086 |
if (sock_no==0) { |
966 |
- /* get our address, only the first one */ |
|
967 |
- if (uname (&myname) <0){ |
|
968 |
- fprintf(stderr, "cannot determine hostname, try -l address\n"); |
|
969 |
- goto error; |
|
970 |
- } |
|
971 |
- sock_info[sock_no].name.s=(char*)malloc(strlen(myname.nodename)+1); |
|
972 |
- if (sock_info[sock_no].name.s==0){ |
|
973 |
- fprintf(stderr, "Out of memory.\n"); |
|
974 |
- goto error; |
|
1087 |
+ /* try to get all listening ipv4 interfaces */ |
|
1088 |
+ if (add_interfaces(0, AF_INET, 0)==-1){ |
|
1089 |
+ /* if error fall back to get hostname*/ |
|
1090 |
+ /* get our address, only the first one */ |
|
1091 |
+ if (uname (&myname) <0){ |
|
1092 |
+ fprintf(stderr, "cannot determine hostname, try -l address\n"); |
|
1093 |
+ goto error; |
|
1094 |
+ } |
|
1095 |
+ sock_info[sock_no].name.s=(char*)malloc(strlen(myname.nodename)+1); |
|
1096 |
+ if (sock_info[sock_no].name.s==0){ |
|
1097 |
+ fprintf(stderr, "Out of memory.\n"); |
|
1098 |
+ goto error; |
|
1099 |
+ } |
|
1100 |
+ sock_info[sock_no].name.len=strlen(myname.nodename); |
|
1101 |
+ strncpy(sock_info[sock_no].name.s, myname.nodename, |
|
1102 |
+ sock_info[sock_no].name.len+1); |
|
1103 |
+ sock_no++; |
|
975 | 1104 |
} |
976 |
- sock_info[sock_no].name.len=strlen(myname.nodename); |
|
977 |
- strncpy(sock_info[sock_no].name.s, myname.nodename, |
|
978 |
- sock_info[sock_no].name.len+1); |
|
979 |
- sock_no++; |
|
980 | 1105 |
} |
981 | 1106 |
|
1107 |
+ /* try to change all the interface names into addresses |
|
1108 |
+ * --ugly hack */ |
|
1109 |
+ for (r=0; r<sock_no;){ |
|
1110 |
+ if (add_interfaces(sock_info[r].name.s, AF_INET, |
|
1111 |
+ sock_info[r].port_no)!=-1){ |
|
1112 |
+ /* success => remove current entry (shift the entire array)*/ |
|
1113 |
+ free(sock_info[r].name.s); |
|
1114 |
+ memmove(&sock_info[r], &sock_info[r+1], |
|
1115 |
+ (sock_no-r)*sizeof(struct socket_info)); |
|
1116 |
+ sock_no--; |
|
1117 |
+ continue; |
|
1118 |
+ } |
|
1119 |
+ r++; |
|
1120 |
+ } |
|
982 | 1121 |
/* get ips & fill the port numbers*/ |
983 |
- printf("Listening on "); |
|
1122 |
+ printf("Listening on \n"); |
|
984 | 1123 |
for (r=0; r<sock_no;r++){ |
985 | 1124 |
he=resolvehost(sock_info[r].name.s); |
986 | 1125 |
if (he==0){ |
... | ... |
@@ -1010,7 +1149,7 @@ int main(int argc, char** argv) |
1010 | 1149 |
|
1011 | 1150 |
hostent2ip_addr(&sock_info[r].address, he, 0); /*convert to ip_addr |
1012 | 1151 |
format*/ |
1013 |
- tmp=ip_addr2a(&sock_info[r].address); |
|
1152 |
+ if ((tmp=ip_addr2a(&sock_info[r].address))==0) goto error; |
|
1014 | 1153 |
sock_info[r].address_str.s=(char*)malloc(strlen(tmp)+1); |
1015 | 1154 |
if (sock_info[r].address_str.s==0){ |
1016 | 1155 |
fprintf(stderr, "Out of memory.\n"); |
... | ... |
@@ -1045,9 +1184,49 @@ int main(int argc, char** argv) |
1045 | 1184 |
strncpy(sock_info[r].port_no_str.s, port_no_str, strlen(port_no_str)+1); |
1046 | 1185 |
sock_info[r].port_no_str.len=strlen(port_no_str); |
1047 | 1186 |
|
1048 |
- printf("%s [%s]:%s\n",sock_info[r].name.s, sock_info[r].address_str.s, |
|
1049 |
- sock_info[r].port_no_str.s); |
|
1187 |
+ printf(" %s [%s]:%s\n",sock_info[r].name.s, |
|
1188 |
+ sock_info[r].address_str.s, sock_info[r].port_no_str.s); |
|
1189 |
+ } |
|
1190 |
+ /* removing duplicate addresses*/ |
|
1191 |
+ for (r=0; r<sock_no; r++){ |
|
1192 |
+ for (t=r+1; t<sock_no;){ |
|
1193 |
+ if ((sock_info[r].port_no==sock_info[t].port_no) && |
|
1194 |
+ (sock_info[r].address.af==sock_info[t].address.af) && |
|
1195 |
+ (memcmp(sock_info[r].address.u.addr, |
|
1196 |
+ sock_info[t].address.u.addr, |
|
1197 |
+ sock_info[r].address.len) == 0) |
|
1198 |
+ ){ |
|
1199 |
+ printf("removing duplicate (%d) %s [%s] == (%d) %s [%s]\n", |
|
1200 |
+ r, sock_info[r].name.s, sock_info[r].address_str.s, |
|
1201 |
+ t, sock_info[t].name.s, sock_info[t].address_str.s); |
|
1202 |
+ |
|
1203 |
+ /* add the name to the alias list*/ |
|
1204 |
+ if ((!sock_info[t].is_ip) && ( |
|
1205 |
+ (sock_info[t].name.len!=sock_info[r].name.len)|| |
|
1206 |
+ (strncmp(sock_info[t].name.s, sock_info[r].name.s, |
|
1207 |
+ sock_info[r].name.len)!=0)) |
|
1208 |
+ ) |
|
1209 |
+ add_alias(sock_info[t].name.s, sock_info[t].name.len); |
|
1210 |
+ |
|
1211 |
+ /* free space*/ |
|
1212 |
+ free(sock_info[t].name.s); |
|
1213 |
+ free(sock_info[t].address_str.s); |
|
1214 |
+ free(sock_info[t].port_no_str.s); |
|
1215 |
+ /* shift the array*/ |
|
1216 |
+ memmove(&sock_info[t], &sock_info[t+1], |
|
1217 |
+ (sock_no-t)*sizeof(struct socket_info)); |
|
1218 |
+ sock_no--; |
|
1219 |
+ continue; |
|
1220 |
+ } |
|
1221 |
+ t++; |
|
1222 |
+ } |
|
1050 | 1223 |
} |
1224 |
+ /* print all the listen addresses */ |
|
1225 |
+ printf("Listening on \n"); |
|
1226 |
+ for (r=0; r<sock_no; r++) |
|
1227 |
+ printf(" %s [%s]:%s\n",sock_info[r].name.s, |
|
1228 |
+ sock_info[r].address_str.s, sock_info[r].port_no_str.s); |
|
1229 |
+ |
|
1051 | 1230 |
printf("Aliases: "); |
1052 | 1231 |
for(a=aliases; a; a=a->next) printf("%.*s ", a->alias.len, a->alias.s); |
1053 | 1232 |
printf("\n"); |
... | ... |
@@ -53,7 +53,7 @@ int check_address(struct ip_addr* ip, char *name, int resolver) |
53 | 53 |
/* maybe we are lucky and name it's an ip */ |
54 | 54 |
s=ip_addr2a(ip); |
55 | 55 |
if (s){ |
56 |
- DBG("check_address(%s, %s, %d)\n", ip_addr2a(ip), name, resolver); |
|
56 |
+ DBG("check_address(%s, %s, %d)\n", s, name, resolver); |
|
57 | 57 |
#ifdef USE_IPV6 |
58 | 58 |
if ((ip->af==AF_INET6) && (strcasecmp(name, s)==0)) |
59 | 59 |
return 0; |
... | ... |
@@ -164,7 +164,8 @@ char* received_builder(struct sip_msg *msg, int *received_len) |
164 | 164 |
inet_ntoa(*(struct in_addr *)&source_ip)); |
165 | 165 |
*/ |
166 | 166 |
memcpy(buf, RECEIVED, RECEIVED_LEN); |
167 |
- tmp=ip_addr2a(source_ip); |
|
167 |
+ if ( (tmp=ip_addr2a(source_ip))==0) |
|
168 |
+ return 0; /* error*/ |
|
168 | 169 |
tmp_len=strlen(tmp); |
169 | 170 |
len=RECEIVED_LEN+tmp_len; |
170 | 171 |
if(source_ip->af==AF_INET6){ |
... | ... |
@@ -6,9 +6,8 @@ |
6 | 6 |
|
7 | 7 |
|
8 | 8 |
debug=9 # debug level (cmd line: -dddddddddd) |
9 |
-#fork=yes # (cmd. line: -D) |
|
10 |
-fork=yes |
|
11 |
-fork=no |
|
9 |
+fork=yes # (cmd. line: -D) |
|
10 |
+#fork=no |
|
12 | 11 |
log_stderror=yes # (cmd line: -E) |
13 | 12 |
#log_stderror=no # (cmd line: -E) |
14 | 13 |
|
... | ... |
@@ -18,7 +17,8 @@ check_via=no # (cmd. line: -v) |
18 | 17 |
dns=off # (cmd. line: -r) |
19 | 18 |
rev_dns=off # (cmd. line: -R) |
20 | 19 |
#port=5070 |
21 |
-#listen=10.0.0.179 |
|
20 |
+listen=10.0.0.179 lo dorian |
|
21 |
+listen=eth0 |
|
22 | 22 |
#listen=127.0.0.1 |
23 | 23 |
#listen=192.168.57.33 |
24 | 24 |
#listen=192.168.57.72 |