diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-03-25 18:44:51 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-03-25 18:44:51 +0000 |
commit | 84b0defcf6903a8b014ab1ba38d8923282f230ed (patch) | |
tree | 4f6ba42e6908ed6803e7793b61c350676e165697 /pjlib | |
parent | cd2cbf5e5a3a0393054a4bbd60ee03576f3fa504 (diff) |
ICE (work in progress): use single socket for all candidates in component, and implemented IP interface enumeration on Win32
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1104 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r-- | pjlib/build/pjlib.dsp | 13 | ||||
-rw-r--r-- | pjlib/build/pjlib.vcproj | 60 | ||||
-rw-r--r-- | pjlib/include/pj/ip_helper.h | 88 | ||||
-rw-r--r-- | pjlib/include/pj/sock.h | 1 | ||||
-rw-r--r-- | pjlib/include/pjlib.h | 1 | ||||
-rw-r--r-- | pjlib/src/pj/ip_helper_generic.c | 69 | ||||
-rw-r--r-- | pjlib/src/pj/ip_helper_win32.c | 136 |
7 files changed, 352 insertions, 16 deletions
diff --git a/pjlib/build/pjlib.dsp b/pjlib/build/pjlib.dsp index 39df8bcc..bd841f71 100644 --- a/pjlib/build/pjlib.dsp +++ b/pjlib/build/pjlib.dsp @@ -110,6 +110,11 @@ SOURCE=..\src\pj\ioqueue_epoll.c # End Source File
# Begin Source File
+SOURCE=..\src\pj\ip_helper_generic.c
+# PROP Exclude_From_Build 1
+# End Source File
+# Begin Source File
+
SOURCE=..\src\pj\log_writer_printk.c
# PROP Exclude_From_Build 1
# End Source File
@@ -254,6 +259,10 @@ SOURCE=..\src\pj\ioqueue_winnt.c # End Source File
# Begin Source File
+SOURCE=..\src\pj\ip_helper_win32.c
+# End Source File
+# Begin Source File
+
SOURCE=..\src\pj\list.c
# End Source File
# Begin Source File
@@ -518,6 +527,10 @@ SOURCE=..\include\pj\ioqueue.h # End Source File
# Begin Source File
+SOURCE=..\include\pj\ip_helper.h
+# End Source File
+# Begin Source File
+
SOURCE=..\include\pj\list.h
# End Source File
# Begin Source File
diff --git a/pjlib/build/pjlib.vcproj b/pjlib/build/pjlib.vcproj index ec3c5644..92183780 100644 --- a/pjlib/build/pjlib.vcproj +++ b/pjlib/build/pjlib.vcproj @@ -16,8 +16,8 @@ <Configurations>
<Configuration
Name="Debug|Win32"
- OutputDirectory=".\output\pjlib-i386-win32-vc6-debug"
- IntermediateDirectory=".\output\pjlib-i386-win32-vc6-debug"
+ OutputDirectory=".\output\pjlib-i386-win32-vc8-debug"
+ IntermediateDirectory=".\output\pjlib-i386-win32-vc8-debug"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
@@ -47,10 +47,10 @@ MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
- PrecompiledHeaderFile=".\output\pjlib-i386-win32-vc6-debug/pjlib.pch"
- AssemblerListingLocation=".\output\pjlib-i386-win32-vc6-debug/"
- ObjectFile=".\output\pjlib-i386-win32-vc6-debug/"
- ProgramDataBaseFileName=".\output\pjlib-i386-win32-vc6-debug/"
+ PrecompiledHeaderFile=".\output\pjlib-i386-win32-vc8-debug/pjlib.pch"
+ AssemblerListingLocation=".\output\pjlib-i386-win32-vc8-debug/"
+ ObjectFile=".\output\pjlib-i386-win32-vc8-debug/"
+ ProgramDataBaseFileName=".\output\pjlib-i386-win32-vc8-debug/"
BrowseInformation="1"
WarningLevel="4"
SuppressStartupBanner="true"
@@ -69,7 +69,7 @@ />
<Tool
Name="VCLibrarianTool"
- OutputFile="../lib/pjlib-i386-win32-vc6-debug.lib"
+ OutputFile="../lib/pjlib-i386-win32-vc8-debug.lib"
SuppressStartupBanner="true"
/>
<Tool
@@ -81,7 +81,7 @@ <Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
- OutputFile=".\output\pjlib-i386-win32-vc6-debug/pjlib.bsc"
+ OutputFile=".\output\pjlib-i386-win32-vc8-debug/pjlib.bsc"
/>
<Tool
Name="VCFxCopTool"
@@ -92,8 +92,8 @@ </Configuration>
<Configuration
Name="Release|Win32"
- OutputDirectory=".\output\pjlib-i386-win32-vc6-release"
- IntermediateDirectory=".\output\pjlib-i386-win32-vc6-release"
+ OutputDirectory=".\output\pjlib-i386-win32-vc8-release"
+ IntermediateDirectory=".\output\pjlib-i386-win32-vc8-release"
ConfigurationType="4"
InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
UseOfMFC="0"
@@ -124,10 +124,10 @@ StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile=".\output\pjlib-i386-win32-vc6-release/pjlib.pch"
- AssemblerListingLocation=".\output\pjlib-i386-win32-vc6-release/"
- ObjectFile=".\output\pjlib-i386-win32-vc6-release/"
- ProgramDataBaseFileName=".\output\pjlib-i386-win32-vc6-release/"
+ PrecompiledHeaderFile=".\output\pjlib-i386-win32-vc8-release/pjlib.pch"
+ AssemblerListingLocation=".\output\pjlib-i386-win32-vc8-release/"
+ ObjectFile=".\output\pjlib-i386-win32-vc8-release/"
+ ProgramDataBaseFileName=".\output\pjlib-i386-win32-vc8-release/"
BrowseInformation="1"
WarningLevel="4"
SuppressStartupBanner="true"
@@ -146,7 +146,7 @@ />
<Tool
Name="VCLibrarianTool"
- OutputFile="../lib/pjlib-i386-win32-vc6-release.lib"
+ OutputFile="../lib/pjlib-i386-win32-vc8-release.lib"
SuppressStartupBanner="true"
/>
<Tool
@@ -158,7 +158,7 @@ <Tool
Name="VCBscMakeTool"
SuppressStartupBanner="true"
- OutputFile=".\output\pjlib-i386-win32-vc6-release/pjlib.bsc"
+ OutputFile=".\output\pjlib-i386-win32-vc8-release/pjlib.bsc"
/>
<Tool
Name="VCFxCopTool"
@@ -538,6 +538,10 @@ </FileConfiguration>
</File>
<File
+ RelativePath="..\src\pj\ip_helper_win32.c"
+ >
+ </File>
+ <File
RelativePath="..\src\pj\list.c"
>
<FileConfiguration
@@ -1121,6 +1125,26 @@ </FileConfiguration>
</File>
<File
+ RelativePath="..\src\pj\ip_helper_generic.c"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ ExcludedFromBuild="true"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ />
+ </FileConfiguration>
+ </File>
+ <File
RelativePath="..\src\pj\log_writer_printk.c"
>
<FileConfiguration
@@ -1459,6 +1483,10 @@ >
</File>
<File
+ RelativePath="..\include\pj\ip_helper.h"
+ >
+ </File>
+ <File
RelativePath="..\include\pj\list.h"
>
</File>
diff --git a/pjlib/include/pj/ip_helper.h b/pjlib/include/pj/ip_helper.h new file mode 100644 index 00000000..9515d978 --- /dev/null +++ b/pjlib/include/pj/ip_helper.h @@ -0,0 +1,88 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __PJ_IP_ROUTE_H__ +#define __PJ_IP_ROUTE_H__ + +/** + * @file ip_helper.h + * @brief IP helper API + */ + +#include <pj/sock.h> + +PJ_BEGIN_DECL + +/** + * @defgroup pj_ip_helper IP Interface and Routing Helper + * @ingroup PJ_IO + * @{ + * + * This module provides functions to query local host's IP interface and + * routing table. + */ + +/** + * This structure describes IP routing entry. + */ +typedef union pj_ip_route_entry +{ + /** IP routing entry for IP version 4 routing */ + struct + { + pj_in_addr if_addr; /**< Local interface IP address. */ + pj_in_addr dst_addr; /**< Destination IP address. */ + pj_in_addr mask; /**< Destination mask. */ + } ipv4; +} pj_ip_route_entry; + + +/** + * Enumerate the local IP interface currently active in the host. + * + * @param count On input, specify the number of entries. On output, + * it will be filled with the actual number of entries. + * @param ifs Array of IP addresses. + * + * @return PJ_SUCCESS on success, or the appropriate error code. + */ +PJ_DECL(pj_status_t) pj_enum_ip_interface(unsigned *count, + pj_in_addr ifs[]); + + +/** + * Enumerate the IP routing table for this host. + * + * @param count On input, specify the number of routes entries. On output, + * it will be filled with the actual number of route entries. + * @param routes Array of IP routing entries. + * + * @return PJ_SUCCESS on success, or the appropriate error code. + */ +PJ_DECL(pj_status_t) pj_enum_ip_route(unsigned *count, + pj_ip_route_entry routes[]); + + + +/** @} */ + +PJ_END_DECL + + +#endif /* __PJ_IP_ROUTE_H__ */ + diff --git a/pjlib/include/pj/sock.h b/pjlib/include/pj/sock.h index d2da570c..0be02589 100644 --- a/pjlib/include/pj/sock.h +++ b/pjlib/include/pj/sock.h @@ -207,6 +207,7 @@ struct pj_sockaddr_in char sin_zero[8]; /**< Padding. */ }; +#undef s6_addr /** * This structure describes IPv6 address. diff --git a/pjlib/include/pjlib.h b/pjlib/include/pjlib.h index e300d487..025fe219 100644 --- a/pjlib/include/pjlib.h +++ b/pjlib/include/pjlib.h @@ -37,6 +37,7 @@ #include <pj/guid.h> #include <pj/hash.h> #include <pj/ioqueue.h> +#include <pj/ip_helper.h> #include <pj/list.h> #include <pj/lock.h> #include <pj/log.h> diff --git a/pjlib/src/pj/ip_helper_generic.c b/pjlib/src/pj/ip_helper_generic.c new file mode 100644 index 00000000..3b713f5a --- /dev/null +++ b/pjlib/src/pj/ip_helper_generic.c @@ -0,0 +1,69 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <pj/ip_helper.h> +#include <pj/addr_resolv.h> +#include <pj/assert.h> +#include <pj/errno.h> +#include <pj/string.h> + +/* + * Enumerate the local IP interface currently active in the host. + */ +PJ_DEF(pj_status_t) pj_enum_ip_interface(unsigned *p_cnt, + pj_in_addr ifs[]) +{ + pj_status_t status; + + PJ_ASSERT_RETURN(p_cnt && *p_cnt > 0 && ifs, PJ_EINVAL); + + pj_bzero(ifs, sizeof(ifs[0]) * (*p_cnt)); + + /* Just get one default route */ + status = pj_gethostip(&ifs[0]); + if (status != PJ_SUCCESS) + return status; + + *p_cnt = 1; + return PJ_SUCCESS; +} + +/* + * Enumerate the IP routing table for this host. + */ +PJ_DEF(pj_status_t) pj_enum_ip_route(unsigned *p_cnt, + pj_ip_route_entry routes[]) +{ + pj_status_t status; + + PJ_ASSERT_RETURN(p_cnt && *p_cnt > 0 && routes, PJ_EINVAL); + + pj_bzero(routes, sizeof(routes[0]) * (*p_cnt)); + + /* Just get one default route */ + status = pj_gethostip(&routes[0].ipv4.if_addr); + if (status != PJ_SUCCESS) + return status; + + routes[0].ipv4.dst_addr.s_addr = 0; + routes[0].ipv4.mask.s_addr = 0; + *p_cnt = 1; + + return PJ_SUCCESS; +} + diff --git a/pjlib/src/pj/ip_helper_win32.c b/pjlib/src/pj/ip_helper_win32.c new file mode 100644 index 00000000..094cfc9f --- /dev/null +++ b/pjlib/src/pj/ip_helper_win32.c @@ -0,0 +1,136 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +/* PMIB_ICMP_EX is not declared in VC6, causing error */ +#if defined(_MSC_VER) && _MSC_VER < 1400 +# define PMIB_ICMP_EX void* +#endif +#include <Iphlpapi.h> + +#include <pj/ip_helper.h> +#include <pj/assert.h> +#include <pj/errno.h> +#include <pj/string.h> + + +/* + * Enumerate the local IP interface currently active in the host. + */ +PJ_DEF(pj_status_t) pj_enum_ip_interface(unsigned *p_cnt, + pj_in_addr ifs[]) +{ + /* Provide enough buffer or otherwise it will fail with + * error 22 ("Not Enough Buffer") error. + */ + MIB_IPADDRTABLE ipTabBuff[4]; + MIB_IPADDRTABLE *pTab; + ULONG tabSize; + unsigned i, count; + DWORD rc; + + PJ_ASSERT_RETURN(p_cnt && ifs, PJ_EINVAL); + + pTab = ipTabBuff; + + /* Get IP address table */ + tabSize = sizeof(ipTabBuff); + rc = GetIpAddrTable(ipTabBuff, &tabSize, FALSE); + if (rc != NO_ERROR) + return PJ_RETURN_OS_ERROR(rc); + + /* Reset result */ + pj_bzero(ifs, sizeof(ifs[0]) * (*p_cnt)); + + /* Now fill out the entries */ + count = (pTab->dwNumEntries < *p_cnt) ? pTab->dwNumEntries : *p_cnt; + for (i=0; i<count; ++i) { + ifs[i].s_addr = pTab->table[i].dwAddr; + } + + *p_cnt = count; + + return PJ_SUCCESS; + +} + + +/* + * Enumerate the IP routing table for this host. + */ +PJ_DEF(pj_status_t) pj_enum_ip_route(unsigned *p_cnt, + pj_ip_route_entry routes[]) +{ + MIB_IPADDRTABLE ipTabBuff[4]; + MIB_IPADDRTABLE *pIpTab; + MIB_IPFORWARDTABLE rtabBuff[4]; + MIB_IPFORWARDTABLE *prTab; + ULONG tabSize; + unsigned i, count; + DWORD rc; + + PJ_ASSERT_RETURN(p_cnt && routes, PJ_EINVAL); + + pIpTab = ipTabBuff; + prTab = rtabBuff; + + /* First get IP address table */ + tabSize = sizeof(ipTabBuff); + rc = GetIpAddrTable(ipTabBuff, &tabSize, FALSE); + if (rc != NO_ERROR) + return PJ_RETURN_OS_ERROR(rc); + + /* Next get IP route table */ + tabSize = sizeof(rtabBuff); + rc = GetIpForwardTable(rtabBuff, &tabSize, 1); + if (rc != NO_ERROR) + return PJ_RETURN_OS_ERROR(rc); + + /* Reset routes */ + pj_bzero(routes, sizeof(routes[0]) * (*p_cnt)); + + /* Now fill out the route entries */ + count = (prTab->dwNumEntries < *p_cnt) ? prTab->dwNumEntries : *p_cnt; + *p_cnt = 0; + for (i=0; i<count; ++i) { + unsigned j; + + /* Find interface entry */ + for (j=0; j<pIpTab->dwNumEntries; ++j) { + if (pIpTab->table[j].dwIndex == prTab->table[i].dwForwardIfIndex) + break; + } + + if (j==pIpTab->dwNumEntries) + continue; /* Interface not found */ + + routes[*p_cnt].ipv4.if_addr.s_addr = pIpTab->table[j].dwAddr; + routes[*p_cnt].ipv4.dst_addr.s_addr = prTab->table[i].dwForwardDest; + routes[*p_cnt].ipv4.mask.s_addr = prTab->table[i].dwForwardMask; + + (*p_cnt)++; + } + + return PJ_SUCCESS; +} + + + |