Originale 134 Posted February 23, 2014 Share Posted February 23, 2014 search bool GetIPInfo() in Config.cpp then replace all the code with its bool GetIPInfo() { struct ifaddrs* ifaddrp = NULL; if (0 != getifaddrs(&ifaddrp)) return false; for( struct ifaddrs* ifap=ifaddrp ; NULL != ifap ; ifap = ifap->ifa_next ) { struct sockaddr_in * sai = (struct sockaddr_in *) ifap->ifa_addr; if (!ifap->ifa_netmask || sai->sin_addr.s_addr == 0 || sai->sin_addr.s_addr == 16777343) continue; char * netip = inet_ntoa(sai->sin_addr); if (g_szPublicIP[0] != '0') { strlcpy(g_szInternalIP, netip, sizeof(g_szInternalIP)); fprintf(stderr, "INTERNAL_IP: %s interface %sn", netip, ifap->ifa_name); } else if (g_szPublicIP[0] == '0') { strlcpy(g_szPublicIP, netip, sizeof(g_szPublicIP)); fprintf(stderr, "PUBLIC_IP: %s interface %sn", netip, ifap->ifa_name); } } } 5 Link to comment Share on other sites More sharing options...
Sinval 9 Posted March 29, 2014 Share Posted March 29, 2014 bool GetIPInfo() { #ifndef __WIN32__ struct ifaddrs* ifaddrp = NULL; if (0 != getifaddrs(&ifaddrp)) return false; for( struct ifaddrs* ifap=ifaddrp ; NULL != ifap ; ifap = ifap->ifa_next ) { struct sockaddr_in * sai = (struct sockaddr_in *) ifap->ifa_addr; if (!ifap->ifa_netmask || // ignore if no netmask sai->sin_addr.s_addr == 0 || // ignore if address is 0.0.0.0 sai->sin_addr.s_addr == 16777343) // ignore if address is 127.0.0.1 continue; #else WSADATA wsa_data; char host_name[100]; HOSTENT* host_ent; int n = 0; if (WSAStartup(0x0101, &wsa_data)) { return false; } gethostname(host_name, sizeof(host_name)); host_ent = gethostbyname(host_name); if (host_ent == NULL) { return false; } for ( ; host_ent->h_addr_list[n] != NULL; ++n) { struct sockaddr_in addr; struct sockaddr_in* sai = &addr; memcpy(&sai->sin_addr.s_addr, host_ent->h_addr_list[n], host_ent->h_length); #endif char * netip = inet_ntoa(sai->sin_addr); if (!strncmp(netip, "192.168", 7)) // ignore if address is starting with 192 { strlcpy(g_szInternalIP, netip, sizeof(g_szInternalIP)); #ifndef __WIN32__ fprintf(stderr, "INTERNAL_IP: %s interface %sn", netip, ifap->ifa_name); #else fprintf(stderr, "INTERNAL_IP: %sn", netip); #endif } else if (!strncmp(netip, "10.", 3)) { strlcpy(g_szInternalIP, netip, sizeof(g_szInternalIP)); #ifndef __WIN32__ fprintf(stderr, "INTERNAL_IP: %s interface %sn", netip, ifap->ifa_name); #else fprintf(stderr, "INTERNAL_IP: %sn", netip); #endif } else if (g_szPublicIP[0] == '0') { strlcpy(g_szPublicIP, netip, sizeof(g_szPublicIP)); #ifndef __WIN32__ fprintf(stderr, "PUBLIC_IP: %s interface %sn", netip, ifap->ifa_name); #else fprintf(stderr, "PUBLIC_IP: %sn", netip); #endif } } #ifndef __WIN32__ freeifaddrs( ifaddrp ); #else WSACleanup(); #endif if (g_szPublicIP[0] != '0') return true; else return false; } > bool GetIPInfo() { struct ifaddrs* ifaddrp = NULL; if (0 != getifaddrs(&ifaddrp)) return false; for( struct ifaddrs* ifap=ifaddrp ; NULL != ifap ; ifap = ifap->ifa_next ) { struct sockaddr_in * sai = (struct sockaddr_in *) ifap->ifa_addr; if (!ifap->ifa_netmask || sai->sin_addr.s_addr == 0 || sai->sin_addr.s_addr == 16777343) continue; char * netip = inet_ntoa(sai->sin_addr); if (g_szPublicIP[0] != '0') { strlcpy(g_szInternalIP, netip, sizeof(g_szInternalIP)); fprintf(stderr, "INTERNAL_IP: %s interface %sn", netip, ifap->ifa_name); } else if (g_szPublicIP[0] == '0') { strlcpy(g_szPublicIP, netip, sizeof(g_szPublicIP)); fprintf(stderr, "PUBLIC_IP: %s interface %sn", netip, ifap->ifa_name); } } } well? "Some come to see you fall, others come pick you upSome come make you smile, others will make you crySome lie by lie, lie to deceive others " Link to comment Share on other sites More sharing options...
Originale 134 Posted April 20, 2014 Author Share Posted April 20, 2014 yes for FreeBsd Only Link to comment Share on other sites More sharing options...
ThatGuyPT 4 Posted April 21, 2014 Share Posted April 21, 2014 The way I fixed it isn't automatic but I used a CONFIG variable to define the IP. I'm pretty sure that dns would work fine aswell. Link to comment Share on other sites More sharing options...
TheSLZ 105 Posted August 19, 2014 Share Posted August 19, 2014 I tried this fix but my friends still can't connect without MC. How to start the server ? Is it need "-I ip" or something ? Link to comment Share on other sites More sharing options...
miguelmig 13 Posted August 22, 2014 Share Posted August 22, 2014 Yeah, let's just delete everything about Win32, that will work! /s 1 Link to comment Share on other sites More sharing options...
Think 117 Posted August 22, 2014 Share Posted August 22, 2014 Worth mentioning you are leaking memory and not returning any value. Link to comment Share on other sites More sharing options...
Recommended Posts