MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / fix_socket

Function fix_socket

socket_info.c:874–1084  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

872}
873
874int 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

Callers 2

fix_socket_listFunction · 0.85
sock_mgm_use_socketFunction · 0.85

Calls 8

int2strFunction · 0.85
resolvehostFunction · 0.85
add_aliasFunction · 0.85
ip_addr2aFunction · 0.85
rev_resolvehostFunction · 0.85
str2ip6Function · 0.85
socket2strFunction · 0.85
is_mcastFunction · 0.85

Tested by

no test coverage detected