File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -863,7 +863,28 @@ int mc_FindIPv4ServerAddress(uint32_t *all_ips,int max_ips)
863863 result=0 ;
864864 c=0 ;
865865
866- #ifndef WIN32
866+ #ifdef MAC_OSX
867+ struct ifaddrs *ifaddr = NULL ;
868+ if (getifaddrs (&ifaddr) == -1 ) {
869+ return c;
870+ }
871+ if (!ifaddr) {
872+ return c;
873+ }
874+ int sock = socket (AF_INET, SOCK_DGRAM, 0 );
875+ if (sock > 0 ) {
876+ for (struct ifaddrs *ifa = ifaddr; ifa != NULL ; ifa = ifa->ifa_next ) {
877+ if (ifa->ifa_addr == 0 ) {
878+ continue ;
879+ }
880+ int family = ifa->ifa_addr ->sa_family ;
881+ if (family != AF_INET) {
882+ continue ;
883+ }
884+ uint32_t a = ((struct sockaddr_in *)ifa->ifa_addr )->sin_addr .s_addr ;
885+ ptr=(unsigned char *)&a;
886+
887+ #elif !defined WIN32
867888
868889 int sock;
869890 struct ifreq ifreqs[20 ];
@@ -919,6 +940,12 @@ int mc_FindIPv4ServerAddress(uint32_t *all_ips,int max_ips)
919940
920941 }
921942 }
943+ #ifdef MAC_OSX
944+ if (sock > 0 ) {
945+ close (sock);
946+ }
947+ freeifaddrs (ifaddr);
948+ #endif
922949 return c;
923950}
924951
You can’t perform that action at this time.
0 commit comments