fixes a socket list => resolve addresses, * interface names, fills missing members, remove duplicates */
| 1086 | /* fixes a socket list => resolve addresses, |
| 1087 | * interface names, fills missing members, remove duplicates */ |
| 1088 | int fix_socket_list(struct socket_info_full **list) |
| 1089 | { |
| 1090 | struct socket_info_full* sif; |
| 1091 | struct socket_info* si; |
| 1092 | struct socket_info_full* l; |
| 1093 | struct socket_info_full* next; |
| 1094 | |
| 1095 | /* try to change all the interface names into addresses |
| 1096 | * --ugly hack */ |
| 1097 | |
| 1098 | for (sif=*list;sif;){ |
| 1099 | next=sif->next; |
| 1100 | si = &sif->socket_info; |
| 1101 | // fix the SI_IS_LO flag for sockets specified by IP/hostname as expand_interface |
| 1102 | // below will only do it for sockets specified using the network interface name |
| 1103 | if (is_localhost(si)) |
| 1104 | si->flags |= SI_IS_LO; |
| 1105 | if (expand_interface(si, list)!=-1){ |
| 1106 | /* success => remove current entry (shift the entire array)*/ |
| 1107 | sock_listrm(list, sif); |
| 1108 | free_sock_info(sif); |
| 1109 | } |
| 1110 | sif=next; |
| 1111 | } |
| 1112 | /* get ips & fill the port numbers*/ |
| 1113 | #ifdef EXTRA_DEBUG |
| 1114 | LM_DBG("listening on \n"); |
| 1115 | #endif |
| 1116 | for (sif=*list;sif;sif=sif->next){ |
| 1117 | si = &sif->socket_info; |
| 1118 | if (fix_socket(sif, auto_aliases) < 0) { |
| 1119 | sock_listrm(list, sif); |
| 1120 | free_sock_info(sif); |
| 1121 | } |
| 1122 | } |
| 1123 | /* removing duplicate addresses*/ |
| 1124 | for (sif=*list;sif; sif=sif->next){ |
| 1125 | for (l=sif->next;l;){ |
| 1126 | next=l->next; |
| 1127 | si = &sif->socket_info; |
| 1128 | const struct socket_info *sl = &l->socket_info; |
| 1129 | if ((si->port_no==sl->port_no) && |
| 1130 | (si->address.af==sl->address.af) && |
| 1131 | (memcmp(si->address.u.addr, sl->address.u.addr, si->address.len) |
| 1132 | == 0) |
| 1133 | ){ |
| 1134 | #ifdef EXTRA_DEBUG |
| 1135 | printf("removing duplicate %s [%s] == %s [%s]\n", |
| 1136 | si->name.s, si->address_str.s, |
| 1137 | sl->name.s, sl->address_str.s); |
| 1138 | #endif |
| 1139 | /* add the name to the alias list*/ |
| 1140 | if ((!(sl->flags& SI_IS_IP)) && ( |
| 1141 | (sl->name.len!=si->name.len)|| |
| 1142 | (strncmp(sl->name.s, si->name.s, si->name.len)!=0)) |
| 1143 | ) |
| 1144 | if (add_alias(sl->name.s,sl->name.len,sl->port_no,sl->proto, |
| 1145 | ACCEPT_SUBDOMAIN_ALIAS(sl->flags))<0) |
no test coverage detected