Browse code

- group fixed

Andrei Pelinescu-Onciul authored on 26/11/2003 23:35:52
Showing 2 changed files
... ...
@@ -44,7 +44,6 @@
44 44
  *                see comment above it for explanations. (andrei)
45 45
  *  2003-06-29  replaced port_no_str snprintf w/ int2str (andrei)
46 46
  *  2003-10-10  added switch for config check (-c) (andrei)
47
- *  2003-10-24  converted to the new socket_info lists (andrei)
48 47
  *
49 48
  */
50 49
 
... ...
@@ -331,15 +330,17 @@ int names_len[MAX_LISTEN];            /* lengths of the names*/
331 330
 struct ip_addr addresses[MAX_LISTEN]; /* our ips */
332 331
 int addresses_no=0;                   /* number of names/ips */
333 332
 #endif
334
-struct socket_info* udp_listen=0;
333
+struct socket_info sock_info[MAX_LISTEN];/*all addresses we listen/send from*/
335 334
 #ifdef USE_TCP
336
-struct socket_info* tcp_listen=0;
335
+struct socket_info tcp_info[MAX_LISTEN];/*all tcp addresses we listen on*/
337 336
 #endif
338 337
 #ifdef USE_TLS
339
-struct socket_info* tls_listen=0;
338
+struct socket_info tls_info[MAX_LISTEN]; /* all tls addresses we listen on*/
340 339
 #endif
340
+int sock_no=0; /* number of addresses/open sockets*/
341 341
 struct socket_info* bind_address=0; /* pointer to the crt. proc.
342 342
 									 listening address*/
343
+int bind_idx; /* same as above but index in the bound[] array */
343 344
 struct socket_info* sendipv4; /* ipv4 socket to use when msg. comes from ipv6*/
344 345
 struct socket_info* sendipv6; /* same as above for ipv6 */
345 346
 #ifdef USE_TCP
... ...
@@ -753,12 +754,16 @@ error:
753 754
 /* main loop */
754 755
 int main_loop()
755 756
 {
756
-	int  i;
757
+	int r, i;
757 758
 	pid_t pid;
758
-	struct socket_info* si;
759 759
 #ifdef USE_TCP
760 760
 	int sockfd[2];
761 761
 #endif
762
+#ifdef USE_TLS
763
+	char* tmp;
764
+	int len;
765
+#endif
766
+		
762 767
 
763 768
 	/* one "main" process and n children handling i/o */
764 769
 
... ...
@@ -767,17 +772,13 @@ int main_loop()
767 772
 #ifdef STATS
768 773
 		setstats( 0 );
769 774
 #endif
770
-		if (udp_listen==0){
771
-			LOG(L_ERR, "ERROR: no fork mode requires at least one"
772
-					" udp listen address, exiting...\n");
773
-			goto error;
774
-		}
775 775
 		/* only one address, we ignore all the others */
776
-		if (udp_init(udp_listen)==-1) goto error;
777
-		bind_address=udp_listen;
776
+		if (udp_init(&sock_info[0])==-1) goto error;
777
+		bind_address=&sock_info[0];
778 778
 		sendipv4=bind_address;
779 779
 		sendipv6=bind_address; /*FIXME*/
780
-		if (udp_listen->next){
780
+		bind_idx=0;
781
+		if (sock_no>1){
781 782
 			LOG(L_WARN, "WARNING: using only the first listen address"
782 783
 						" (no fork)\n");
783 784
 		}
... ...
@@ -852,55 +853,66 @@ int main_loop()
852 853
 		/* process_no now initialized to zero -- increase from now on
853 854
 		   as new processes are forked (while skipping 0 reserved for main )
854 855
 		*/
855
-		for(si=udp_listen;si;si=si->next){
856
+		for(r=0;r<sock_no;r++){
856 857
 			/* create the listening socket (for each address)*/
857 858
 			/* udp */
858
-			if (udp_init(si)==-1) goto error;
859
+			if (udp_init(&sock_info[r])==-1) goto error;
859 860
 			/* get first ipv4/ipv6 socket*/
860
-			if ((si->address.af==AF_INET)&&
861
-					((sendipv4==0)||(sendipv4->flags&SI_IS_LO)))
862
-				sendipv4=si;
861
+			if ((sock_info[r].address.af==AF_INET)&&
862
+					((sendipv4==0)||(sendipv4->is_lo)))
863
+				sendipv4=&sock_info[r];
863 864
 	#ifdef USE_IPV6
864
-			if((sendipv6==0)&&(si->address.af==AF_INET6))
865
-				sendipv6=si;
865
+			if((sendipv6==0)&&(sock_info[r].address.af==AF_INET6))
866
+				sendipv6=&sock_info[r];
866 867
 	#endif
867
-		}
868 868
 #ifdef USE_TCP
869
-		if (!tcp_disable){
870
-			for(si=tcp_listen; si; si=si->next){
869
+			if (!tcp_disable){
870
+				tcp_info[r]=sock_info[r]; /* copy the sockets */
871 871
 				/* same thing for tcp */
872
-				if (tcp_init(si)==-1)  goto error;
872
+				if (tcp_init(&tcp_info[r])==-1)  goto error;
873 873
 				/* get first ipv4/ipv6 socket*/
874
-				if ((si->address.af==AF_INET)&&
875
-						((sendipv4_tcp==0)||(sendipv4_tcp->flags&SI_IS_LO)))
876
-					sendipv4_tcp=si;
874
+				if ((tcp_info[r].address.af==AF_INET)&&
875
+						((sendipv4_tcp==0)||(sendipv4_tcp->is_lo)))
876
+					sendipv4_tcp=&tcp_info[r];
877 877
 		#ifdef USE_IPV6
878
-				if((sendipv6_tcp==0)&&(si->address.af==AF_INET6))
879
-					sendipv6_tcp=si;
878
+				if((sendipv6_tcp==0)&&(tcp_info[r].address.af==AF_INET6))
879
+					sendipv6_tcp=&tcp_info[r];
880 880
 		#endif
881 881
 			}
882
-		}
883 882
 #ifdef USE_TLS
884
-		if (!tls_disable){
885
-			for(si=tls_listen; si; si=si->next){
883
+			if (!tls_disable){
884
+				tls_info[r]=sock_info[r]; /* copy the sockets */
885
+				/* fix the port number -- there is no way so far to set-up
886
+				 * individual tls port numbers */
887
+				tls_info[r].port_no=tls_port_no; /* FIXME: */
888
+				tmp=int2str(tls_info[r].port_no, &len);
889
+				/* we don't need to free the previous content, is uesd
890
+				 * by tcp & udp! */
891
+				tls_info[r].port_no_str.s=(char*)pkg_malloc(len+1);
892
+				if (tls_info[r].port_no_str.s==0){
893
+					LOG(L_CRIT, "memory allocation failure\n");
894
+					goto error;
895
+				}
896
+				strncpy(tls_info[r].port_no_str.s, tmp, len+1);
897
+				tls_info[r].port_no_str.len=len;
898
+				
886 899
 				/* same as for tcp*/
887
-				if (tls_init(si)==-1)  goto error;
900
+				if (tls_init(&tls_info[r])==-1)  goto error;
888 901
 				/* get first ipv4/ipv6 socket*/
889
-				if ((si->address.af==AF_INET)&&
890
-						((sendipv4_tls==0)||(sendipv4_tls->flags&SI_IS_LO)))
891
-					sendipv4_tls=si;
902
+				if ((tls_info[r].address.af==AF_INET)&&
903
+						((sendipv4_tls==0)||(sendipv4_tls->is_lo)))
904
+					sendipv4_tls=&tls_info[r];
892 905
 		#ifdef USE_IPV6
893
-				if((sendipv6_tls==0)&&(si->address.af==AF_INET6))
894
-					sendipv6_tls=si;
906
+				if((sendipv6_tls==0)&&(tls_info[r].address.af==AF_INET6))
907
+					sendipv6_tls=&tls_info[r];
895 908
 		#endif
896 909
 			}
897
-		}
898 910
 #endif /* USE_TLS */
899 911
 #endif /* USE_TCP */
900 912
 			/* all procs should have access to all the sockets (for sending)
901 913
 			 * so we open all first*/
902
-		/* udp processes */
903
-		for(si=udp_listen; si; si=si->next){
914
+		}
915
+		for(r=0; r<sock_no;r++){
904 916
 			for(i=0;i<children_no;i++){
905 917
 				process_no++;
906 918
 #ifdef USE_TCP
... ...
@@ -923,7 +935,8 @@ int main_loop()
923 935
 						unix_tcp_sock=sockfd[1];
924 936
 					}
925 937
 #endif
926
-					bind_address=si; /* shortcut */
938
+					bind_address=&sock_info[r]; /* shortcut */
939
+					bind_idx=r;
927 940
 					if (init_child(i + 1) < 0) {
928 941
 						LOG(L_ERR, "init_child failed\n");
929 942
 						goto error;
... ...
@@ -935,8 +948,8 @@ int main_loop()
935 948
 				}else{
936 949
 						pt[process_no].pid=pid; /*should be in shared mem.*/
937 950
 						snprintf(pt[process_no].desc, MAX_PT_DESC,
938
-							"receiver child=%d sock= %s:%s", i, 	
939
-							si->name.s, si->port_no_str.s );
951
+							"receiver child=%d sock=%d @ %s:%s", i, r, 	
952
+							sock_info[r].name.s, sock_info[r].port_no_str.s );
940 953
 #ifdef USE_TCP
941 954
 						if (!tcp_disable){
942 955
 							close(sockfd[1]);
... ...
@@ -954,6 +967,8 @@ int main_loop()
954 967
 
955 968
 	/*this is the main process*/
956 969
 	bind_address=0;				/* main proc -> it shouldn't send anything, */
970
+	bind_idx=0;					/* if it does get_send_sock should return
971
+	                               a good socket */
957 972
 	
958 973
 	/* if configured to do so, start a server for accepting FIFO commands */
959 974
 	if (open_fifo_server()<0) {
... ...
@@ -1053,9 +1068,8 @@ int main_loop()
1053 1068
 #endif
1054 1069
 	/*DEBUG- remove it*/
1055 1070
 #ifdef DEBUG
1056
-	fprintf(stderr, "\n% 3d processes (%3d), % 3d children * "
1057
-			"listening addresses + tcp listeners + tls listeners"
1058
-			"+ main + fifo %s\n", process_no+1, process_count(), children_no,
1071
+	fprintf(stderr, "\n% 3d processes (%3d), % 3d children * % 3d listening addresses"
1072
+			"+ main + fifo %s\n", process_no+1, process_count(), children_no, sock_no,
1059 1073
 			(timer_list)?"+ timer":"");
1060 1074
 	for (r=0; r<=process_no; r++){
1061 1075
 		fprintf(stderr, "% 3d   % 5d - %s\n", r, pt[r].pid, pt[r].desc);
... ...
@@ -1081,6 +1095,134 @@ int main_loop()
1081 1095
 
1082 1096
 }
1083 1097
 
1098
+/* add all family type addresses of interface if_name to the socket_info array
1099
+ * if if_name==0, adds all addresses on all interfaces
1100
+ * WARNING: it only works with ipv6 addresses on FreeBSD
1101
+ * return: -1 on error, 0 on success
1102
+ */
1103
+int add_interfaces(char* if_name, int family, unsigned short port)
1104
+{
1105
+	struct ifconf ifc;
1106
+	struct ifreq ifr;
1107
+	struct ifreq ifrcopy;
1108
+	char*  last;
1109
+	char* p;
1110
+	int size;
1111
+	int lastlen;
1112
+	int s;
1113
+	char* tmp;
1114
+	struct ip_addr addr;
1115
+	int ret;
1116
+
1117
+#ifdef HAVE_SOCKADDR_SA_LEN
1118
+	#ifndef MAX
1119
+		#define MAX(a,b) ( ((a)>(b))?(a):(b))
1120
+	#endif
1121
+#endif
1122
+	/* ipv4 or ipv6 only*/
1123
+	s=socket(family, SOCK_DGRAM, 0);
1124
+	ret=-1;
1125
+	lastlen=0;
1126
+	ifc.ifc_req=0;
1127
+	for (size=10; ; size*=2){
1128
+		ifc.ifc_len=size*sizeof(struct ifreq);
1129
+		ifc.ifc_req=(struct ifreq*) pkg_malloc(size*sizeof(struct ifreq));
1130
+		if (ifc.ifc_req==0){
1131
+			fprintf(stderr, "memory allocation failure\n");
1132
+			goto error;
1133
+		}
1134
+		if (ioctl(s, SIOCGIFCONF, &ifc)==-1){
1135
+			if(errno==EBADF) return 0; /* invalid descriptor => no such ifs*/
1136
+			fprintf(stderr, "ioctl failed: %s\n", strerror(errno));
1137
+			goto error;
1138
+		}
1139
+		if  ((lastlen) && (ifc.ifc_len==lastlen)) break; /*success,
1140
+														   len not changed*/
1141
+		lastlen=ifc.ifc_len;
1142
+		/* try a bigger array*/
1143
+		pkg_free(ifc.ifc_req);
1144
+	}
1145
+	
1146
+	last=(char*)ifc.ifc_req+ifc.ifc_len;
1147
+	for(p=(char*)ifc.ifc_req; p<last;
1148
+			p+=(sizeof(ifr.ifr_name)+
1149
+			#ifdef  HAVE_SOCKADDR_SA_LEN
1150
+				MAX(ifr.ifr_addr.sa_len, sizeof(struct sockaddr))
1151
+			#else
1152
+				( (ifr.ifr_addr.sa_family==AF_INET)?
1153
+					sizeof(struct sockaddr_in):
1154
+					((ifr.ifr_addr.sa_family==AF_INET6)?
1155
+						sizeof(struct sockaddr_in6):sizeof(struct sockaddr)) )
1156
+			#endif
1157
+				)
1158
+		)
1159
+	{
1160
+		/* copy contents into ifr structure
1161
+		 * warning: it might be longer (e.g. ipv6 address) */
1162
+		memcpy(&ifr, p, sizeof(ifr));
1163
+		if (ifr.ifr_addr.sa_family!=family){
1164
+			/*printf("strange family %d skipping...\n",
1165
+					ifr->ifr_addr.sa_family);*/
1166
+			continue;
1167
+		}
1168
+		
1169
+		/*get flags*/
1170
+		ifrcopy=ifr;
1171
+		if (ioctl(s, SIOCGIFFLAGS,  &ifrcopy)!=-1){ /* ignore errors */
1172
+			/* ignore down ifs only if listening on all of them*/
1173
+			if (if_name==0){ 
1174
+				/* if if not up, skip it*/
1175
+				if (!(ifrcopy.ifr_flags & IFF_UP)) continue;
1176
+			}
1177
+		}
1178
+		
1179
+		
1180
+		
1181
+		if ((if_name==0)||
1182
+			(strncmp(if_name, ifr.ifr_name, sizeof(ifr.ifr_name))==0)){
1183
+			
1184
+				/*add address*/
1185
+			if (sock_no<MAX_LISTEN){
1186
+				sockaddr2ip_addr(&addr, 
1187
+					(struct sockaddr*)(p+(long)&((struct ifreq*)0)->ifr_addr));
1188
+				if ((tmp=ip_addr2a(&addr))==0) goto error;
1189
+				/* fill the strings*/
1190
+				sock_info[sock_no].name.s=(char*)pkg_malloc(strlen(tmp)+1);
1191
+				if(sock_info[sock_no].name.s==0){
1192
+					fprintf(stderr, "Out of memory.\n");
1193
+					goto error;
1194
+				}
1195
+				/* fill in the new name and port */
1196
+				sock_info[sock_no].name.len=strlen(tmp);
1197
+				strncpy(sock_info[sock_no].name.s, tmp, 
1198
+							sock_info[sock_no].name.len+1);
1199
+				sock_info[sock_no].port_no=port;
1200
+				/* mark if loopback */
1201
+				if (ifrcopy.ifr_flags & IFF_LOOPBACK) 
1202
+					sock_info[sock_no].is_lo=1;
1203
+				sock_no++;
1204
+				ret=0;
1205
+			}else{
1206
+				fprintf(stderr, "Too many addresses (max %d)\n", MAX_LISTEN);
1207
+				goto error;
1208
+			}
1209
+		}
1210
+			/*
1211
+			printf("%s:\n", ifr->ifr_name);
1212
+			printf("        ");
1213
+			print_sockaddr(&(ifr->ifr_addr));
1214
+			printf("        ");
1215
+			ls_ifflags(ifr->ifr_name, family, options);
1216
+			printf("\n");*/
1217
+	}
1218
+	pkg_free(ifc.ifc_req); /*clean up*/
1219
+	close(s);
1220
+	return  ret;
1221
+error:
1222
+	if (ifc.ifc_req) pkg_free(ifc.ifc_req);
1223
+	close(s);
1224
+	return -1;
1225
+}
1084 1226
 
1085 1227
 
1086 1228
 
... ...
@@ -1088,9 +1230,14 @@ int main(int argc, char** argv)
1088 1230
 {
1089 1231
 
1090 1232
 	FILE* cfg_stream;
1091
-	int c,r;
1233
+	struct hostent* he;
1234
+	int c,r,t;
1092 1235
 	char *tmp;
1236
+	char** h;
1237
+	struct host_alias* a;
1238
+	struct utsname myname;
1093 1239
 	char *options;
1240
+	int len;
1094 1241
 	int ret;
1095 1242
 	struct passwd *pw_entry;
1096 1243
 	struct group  *gr_entry;
... ...
@@ -1140,7 +1287,9 @@ int main(int argc, char** argv)
1140 1287
 						fprintf(stderr, "bad port number: -p %s\n", optarg);
1141 1288
 						goto error;
1142 1289
 					}
1290
+					if (sock_no>0) sock_info[sock_no-1].port_no=port_no;
1143 1291
 					break;
1292
+
1144 1293
 			case 'm':
1145 1294
 					shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;
1146 1295
 					if (tmp &&(*tmp)){
... ...
@@ -1162,8 +1311,23 @@ int main(int argc, char** argv)
1162 1311
 					break;
1163 1312
 			case 'l':
1164 1313
 					/* add a new addr. to our address list */
1165
-					if (add_listen_iface(optarg, 0, 0, 0)!=0){
1166
-						fprintf(stderr, "failed to add new listen address\n");
1314
+					if (sock_no < MAX_LISTEN){
1315
+						sock_info[sock_no].name.s=
1316
+										(char*)pkg_malloc(strlen(optarg)+1);
1317
+						if (sock_info[sock_no].name.s==0){
1318
+							fprintf(stderr, "Out of memory.\n");
1319
+							goto error;
1320
+						}
1321
+						strncpy(sock_info[sock_no].name.s, optarg,
1322
+												strlen(optarg)+1);
1323
+						sock_info[sock_no].name.len=strlen(optarg);
1324
+						/* set default port */
1325
+						sock_info[sock_no].port_no=port_no;
1326
+						sock_no++;
1327
+					}else{
1328
+						fprintf(stderr, 
1329
+									"Too many addresses (max. %d).\n",
1330
+									MAX_LISTEN);
1167 1331
 						goto error;
1168 1332
 					}
1169 1333
 					break;
... ...
@@ -1309,11 +1473,11 @@ try_again:
1309 1473
 		goto error;
1310 1474
 	}
1311 1475
 	
1312
-	/* register a diagnostic FIFO command  - moved to fifo server - bogdan
1476
+	/* register a diagnostic FIFO command */
1313 1477
 	if (register_core_fifo()<0) {
1314 1478
 		LOG(L_CRIT, "unable to register core FIFO commands\n");
1315 1479
 		goto error;
1316
-	}*/
1480
+	}
1317 1481
 
1318 1482
 	/*register builtin  modules*/
1319 1483
 	register_builtin_modules();
... ...
@@ -1359,7 +1523,7 @@ try_again:
1359 1523
 		}
1360 1524
 	}
1361 1525
 	if (group){
1362
-		gid=strtol(user, &tmp, 10);
1526
+		gid=strtol(group, &tmp, 10);
1363 1527
 		if ((tmp==0) ||(*tmp)){
1364 1528
 			/* maybe it's a string */
1365 1529
 			gr_entry=getgrnam(group);
... ...
@@ -1370,25 +1534,188 @@ try_again:
1370 1534
 			gid=gr_entry->gr_gid;
1371 1535
 		}
1372 1536
 	}
1373
-	
1374
-	if (fix_all_socket_lists()!=0){
1375
-		fprintf(stderr,  "failed to initialize liste addresses\n");
1376
-		goto error;
1537
+
1538
+	if (sock_no==0) {
1539
+		/* try to get all listening ipv4 interfaces */
1540
+		if (add_interfaces(0, AF_INET, 0)==-1){
1541
+			/* if error fall back to get hostname*/
1542
+			/* get our address, only the first one */
1543
+			if (uname (&myname) <0){
1544
+				fprintf(stderr, "cannot determine hostname, try -l address\n");
1545
+				goto error;
1546
+			}
1547
+			sock_info[sock_no].name.s=
1548
+								(char*)pkg_malloc(strlen(myname.nodename)+1);
1549
+			if (sock_info[sock_no].name.s==0){
1550
+				fprintf(stderr, "Out of memory.\n");
1551
+				goto error;
1552
+			}
1553
+			sock_info[sock_no].name.len=strlen(myname.nodename);
1554
+			strncpy(sock_info[sock_no].name.s, myname.nodename,
1555
+					sock_info[sock_no].name.len+1);
1556
+			sock_no++;
1557
+		}
1558
+	}
1559
+
1560
+	/* try to change all the interface names into addresses
1561
+	 *  --ugly hack */
1562
+	for (r=0; r<sock_no;){
1563
+		if (add_interfaces(sock_info[r].name.s, AF_INET,
1564
+					sock_info[r].port_no)!=-1){
1565
+			/* success => remove current entry (shift the entire array)*/
1566
+			pkg_free(sock_info[r].name.s);
1567
+			memmove(&sock_info[r], &sock_info[r+1], 
1568
+						(sock_no-r)*sizeof(struct socket_info));
1569
+			sock_no--;
1570
+			continue;
1571
+		}
1572
+		r++;
1573
+	}
1574
+	/* get ips & fill the port numbers*/
1575
+#ifdef EXTRA_DEBUG
1576
+	printf("Listening on \n");
1577
+#endif
1578
+	for (r=0; r<sock_no;r++){
1579
+		/* fix port number, port_no should be !=0 here */
1580
+		if (sock_info[r].port_no==0) sock_info[r].port_no=port_no;
1581
+		tmp=int2str(sock_info[r].port_no, &len);
1582
+		if (len>=MAX_PORT_LEN){
1583
+			fprintf(stderr, "ERROR: bad port number: %d\n", 
1584
+						sock_info[r].port_no);
1585
+			goto error;
1586
+		}
1587
+		sock_info[r].port_no_str.s=(char*)pkg_malloc(len+1);
1588
+		if (sock_info[r].port_no_str.s==0){
1589
+			fprintf(stderr, "Out of memory.\n");
1590
+			goto error;
1591
+		}
1592
+		strncpy(sock_info[r].port_no_str.s, tmp, len+1);
1593
+		sock_info[r].port_no_str.len=len;
1594
+		
1595
+		/* get "official hostnames", all the aliases etc. */
1596
+		he=resolvehost(sock_info[r].name.s);
1597
+		if (he==0){
1598
+			DPrint("ERROR: could not resolve %s\n", sock_info[r].name.s);
1599
+			goto error;
1600
+		}
1601
+		/* check if we got the official name */
1602
+		if (strcasecmp(he->h_name, sock_info[r].name.s)!=0){
1603
+			if (add_alias(sock_info[r].name.s, sock_info[r].name.len,
1604
+							sock_info[r].port_no)<0){
1605
+				LOG(L_ERR, "ERROR: main: add_alias failed\n");
1606
+			}
1607
+			/* change the oficial name */
1608
+			pkg_free(sock_info[r].name.s);
1609
+			sock_info[r].name.s=(char*)pkg_malloc(strlen(he->h_name)+1);
1610
+			if (sock_info[r].name.s==0){
1611
+				fprintf(stderr, "Out of memory.\n");
1612
+				goto error;
1613
+			}
1614
+			sock_info[r].name.len=strlen(he->h_name);
1615
+			strncpy(sock_info[r].name.s, he->h_name, sock_info[r].name.len+1);
1616
+		}
1617
+		/* add the aliases*/
1618
+		for(h=he->h_aliases; h && *h; h++)
1619
+			if (add_alias(*h, strlen(*h), sock_info[r].port_no)<0){
1620
+				LOG(L_ERR, "ERROR: main: add_alias failed\n");
1621
+			}
1622
+		hostent2ip_addr(&sock_info[r].address, he, 0); /*convert to ip_addr 
1623
+														 format*/
1624
+		if ((tmp=ip_addr2a(&sock_info[r].address))==0) goto error;
1625
+		sock_info[r].address_str.s=(char*)pkg_malloc(strlen(tmp)+1);
1626
+		if (sock_info[r].address_str.s==0){
1627
+			fprintf(stderr, "Out of memory.\n");
1628
+			goto error;
1629
+		}
1630
+		strncpy(sock_info[r].address_str.s, tmp, strlen(tmp)+1);
1631
+		/* set is_ip (1 if name is an ip address, 0 otherwise) */
1632
+		sock_info[r].address_str.len=strlen(tmp);
1633
+		if 	(	(sock_info[r].address_str.len==sock_info[r].name.len)&&
1634
+				(strncasecmp(sock_info[r].address_str.s, sock_info[r].name.s,
1635
+						 sock_info[r].address_str.len)==0)
1636
+			){
1637
+				sock_info[r].is_ip=1;
1638
+				/* do rev. dns on it (for aliases)*/
1639
+				he=rev_resolvehost(&sock_info[r].address);
1640
+				if (he==0){
1641
+					DPrint("WARNING: could not rev. resolve %s\n",
1642
+							sock_info[r].name.s);
1643
+				}else{
1644
+					/* add the aliases*/
1645
+					if (add_alias(he->h_name, strlen(he->h_name),
1646
+									sock_info[r].port_no)<0){
1647
+						LOG(L_ERR, "ERROR: main: add_alias failed\n");
1648
+					}
1649
+					for(h=he->h_aliases; h && *h; h++)
1650
+						if (add_alias(*h,strlen(*h),sock_info[r].port_no)<0){
1651
+							LOG(L_ERR, "ERROR: main: add_alias failed\n");
1652
+						}
1653
+				}
1654
+		}else{ sock_info[r].is_ip=0; };
1655
+			
1656
+#ifdef EXTRA_DEBUG
1657
+		printf("              %.*s [%s]:%s\n", sock_info[r].name.len, 
1658
+				sock_info[r].name.s,
1659
+				sock_info[r].address_str.s, sock_info[r].port_no_str.s);
1660
+#endif
1661
+	}
1662
+	/* removing duplicate addresses*/
1663
+	for (r=0; r<sock_no; r++){
1664
+		for (t=r+1; t<sock_no;){
1665
+			if ((sock_info[r].port_no==sock_info[t].port_no) &&
1666
+				(sock_info[r].address.af==sock_info[t].address.af) &&
1667
+				(memcmp(sock_info[r].address.u.addr, 
1668
+						sock_info[t].address.u.addr,
1669
+						sock_info[r].address.len)  == 0)
1670
+				){
1671
+#ifdef EXTRA_DEBUG
1672
+				printf("removing duplicate (%d) %s [%s] == (%d) %s [%s]\n",
1673
+						r, sock_info[r].name.s, sock_info[r].address_str.s,
1674
+						t, sock_info[t].name.s, sock_info[t].address_str.s);
1675
+#endif
1676
+				/* add the name to the alias list*/
1677
+				if ((!sock_info[t].is_ip) && (
1678
+						(sock_info[t].name.len!=sock_info[r].name.len)||
1679
+						(strncmp(sock_info[t].name.s, sock_info[r].name.s,
1680
+								 sock_info[r].name.len)!=0))
1681
+					)
1682
+					add_alias(sock_info[t].name.s, sock_info[t].name.len,
1683
+								sock_info[t].port_no);
1684
+						
1685
+				/* free space*/
1686
+				pkg_free(sock_info[t].name.s);
1687
+				pkg_free(sock_info[t].address_str.s);
1688
+				pkg_free(sock_info[t].port_no_str.s);
1689
+				/* shift the array*/
1690
+				memmove(&sock_info[t], &sock_info[t+1], 
1691
+							(sock_no-t)*sizeof(struct socket_info));
1692
+				sock_no--;
1693
+				continue;
1694
+			}
1695
+			t++;
1696
+		}
1377 1697
 	}
1378 1698
 	/* print all the listen addresses */
1379 1699
 	printf("Listening on \n");
1380
-	print_all_socket_lists();
1381
-	printf("Aliases: \n");
1382
-	/*print_aliases();*/
1383
-	print_aliases();
1700
+	for (r=0; r<sock_no; r++)
1701
+		printf("              %s [%s]:%s\n",sock_info[r].name.s,
1702
+				sock_info[r].address_str.s, sock_info[r].port_no_str.s);
1703
+
1704
+	printf("Aliases: ");
1705
+	for(a=aliases; a; a=a->next) 
1706
+		if (a->port)
1707
+			printf("%.*s:%d ", a->alias.len, a->alias.s, a->port);
1708
+		else
1709
+			printf("%.*s:* ", a->alias.len, a->alias.s);
1384 1710
 	printf("\n");
1385
-	
1711
+	if (sock_no==0){
1712
+		fprintf(stderr, "ERROR: no listening sockets");
1713
+		goto error;
1714
+	}
1386 1715
 	if (dont_fork){
1387 1716
 		fprintf(stderr, "WARNING: no fork mode %s\n", 
1388
-				(udp_listen)?(
1389
-				(udp_listen->next)?" and more than one listen address found"
1390
-				"(will use only the the first one)":""
1391
-				):"and no udp listen address found" );
1717
+				(sock_no>1)?" and more than one listen address found (will"
1718
+							" use only the the first one)":"");
1392 1719
 	}
1393 1720
 	if (config_check){
1394 1721
 		fprintf(stderr, "config file ok, exiting...\n");
... ...
@@ -27,6 +27,7 @@ alias=iptel.org
27 27
 alias="foo.bar"
28 28
 syn_branch=0
29 29
 fifo="/tmp/ser_fifo"
30
+#group=mobra
30 31
 
31 32
 #modules
32 33