]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add netmask code for windows
authorMichael Jerris <mike@jerris.com>
Thu, 4 Jun 2009 05:23:19 +0000 (05:23 +0000)
committerMichael Jerris <mike@jerris.com>
Thu, 4 Jun 2009 05:23:19 +0000 (05:23 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13607 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch_utils.c

index 825a020146961c23a3eb63b2a63e4070adb36b16..4b5c7d9b19301744c228e485883a3d8e44e78487 100644 (file)
@@ -822,7 +822,34 @@ static int get_netmask(struct sockaddr_in *me, int *mask)
 
 static int get_netmask(struct sockaddr_in *me, int *mask)
 {
-       return -1;
+       SOCKET sock = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
+       INTERFACE_INFO interfaces[20];
+       unsigned long bytes;
+       int interface_count, x;
+
+       *mask = 0;
+
+       if (sock == SOCKET_ERROR) {
+               return -1;
+       }
+
+       if (WSAIoctl(sock, SIO_GET_INTERFACE_LIST, 0, 0, &interfaces, sizeof(interfaces), &bytes, 0, 0) == SOCKET_ERROR) {
+               return -1;
+       }
+
+    interface_count = bytes / sizeof(INTERFACE_INFO);
+
+       for (x = 0; x < interface_count; ++x) {
+               struct sockaddr_in *addr = (struct sockaddr_in *) & (interfaces[x].iiAddress);
+
+               if (addr->sin_addr.s_addr == me->sin_addr.s_addr) {
+                       struct sockaddr_in *netmask = (struct sockaddr_in *) & (interfaces[x].iiNetmask);
+                       *mask = netmask->sin_addr.s_addr;
+                       break;
+               }
+    }
+
+       return 0;
 }
 
 #else
@@ -888,17 +915,15 @@ SWITCH_DECLARE(switch_status_t) switch_find_local_ip(char *buf, int len, int *ma
                return status;
        }
 
-       if (mask) {
-               *mask = 0;  // find the right one
-       }
 
        closesocket(tmp_socket);
        freeaddrinfo(address_info);
 
        if (!getnameinfo((const struct sockaddr *) &l_address, l_address_len, buf, len, NULL, 0, NI_NUMERICHOST)) {
-
-               status = SWITCH_STATUS_SUCCESS;
-
+               status = SWITCH_STATUS_SUCCESS; 
+               if (mask) {
+                       get_netmask((struct sockaddr_in *) &l_address, mask);
+               }
        }
 #else