| 872 | } |
| 873 | |
| 874 | int fix_socket(struct socket_info_full *sif, int add_aliases) |
| 875 | { |
| 876 | char** h; |
| 877 | char* tmp; |
| 878 | int len; |
| 879 | struct hostent* he; |
| 880 | struct socket_info *si = &sif->socket_info; |
| 881 | |
| 882 | /* fix the number of processes per interface */ |
| 883 | if (!si->workers && is_udp_based_proto(si->proto)) |
| 884 | si->workers = udp_workers_no; |
| 885 | if (si->port_no==0) |
| 886 | si->port_no= protos[si->proto].default_port; |
| 887 | |
| 888 | tmp=int2str(si->port_no, &len); |
| 889 | if (len>=MAX_PORT_LEN){ |
| 890 | LM_ERR("bad port number: %d\n", si->port_no); |
| 891 | return -1; |
| 892 | } |
| 893 | |
| 894 | si->port_no_str.s=(char*)pkg_malloc(len+1); |
| 895 | if (si->port_no_str.s==0){ |
| 896 | LM_ERR("out of pkg memory.\n"); |
| 897 | goto error; |
| 898 | } |
| 899 | memcpy(si->port_no_str.s, tmp, len+1); |
| 900 | si->port_no_str.len=len; |
| 901 | /* get "official hostnames", all the aliases etc. */ |
| 902 | he=resolvehost(si->name.s,0); |
| 903 | if (he==0){ |
| 904 | LM_ERR("could not resolve %s\n", si->name.s); |
| 905 | goto error; |
| 906 | } |
| 907 | /* check if we got the official name */ |
| 908 | if (strcasecmp(he->h_name, si->name.s)!=0){ |
| 909 | if (add_aliases && add_alias(si->name.s, si->name.len, |
| 910 | si->port_no, si->proto, ACCEPT_SUBDOMAIN_ALIAS(si->flags))<0){ |
| 911 | LM_ERR("add_alias failed\n"); |
| 912 | } |
| 913 | /* change the official name */ |
| 914 | pkg_free(si->name.s); |
| 915 | si->name.s=(char*)pkg_malloc(strlen(he->h_name)+1); |
| 916 | if (si->name.s==0){ |
| 917 | LM_ERR("out of pkg memory.\n"); |
| 918 | goto error; |
| 919 | } |
| 920 | si->name.len=strlen(he->h_name); |
| 921 | memcpy(si->name.s, he->h_name, si->name.len+1); |
| 922 | } |
| 923 | /* add the aliases*/ |
| 924 | if (add_aliases) { |
| 925 | for(h=he->h_aliases; h && *h; h++) |
| 926 | if (add_alias(*h, strlen(*h), si->port_no, si->proto, |
| 927 | ACCEPT_SUBDOMAIN_ALIAS(si->flags))<0){ |
| 928 | LM_ERR("add_alias failed\n"); |
| 929 | } |
| 930 | } |
| 931 | hostent2ip_addr(&si->address, he, 0); /*convert to ip_addr |
no test coverage detected