[PATCH] iphlpapi: Use RtlIpv4AddressToString to avoid code duplication

Detlef Riekenberg wine.dev at web.de
Mon Oct 4 17:30:46 CDT 2010


How should we handle the different types for sin_addr.s_addr on
linux (in_addr_t) and Windows (in_addr)?
I used a cast: (const struct in_addr*)&sa->sin_addr.s_addr

--
By by ... Detlef
---
 dlls/iphlpapi/iphlpapi_main.c |   20 ++------------------
 include/mstcpip.h             |   12 ++++++++++++
 2 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c
index 1329466..1aa5f2c 100644
--- a/dlls/iphlpapi/iphlpapi_main.c
+++ b/dlls/iphlpapi/iphlpapi_main.c
@@ -54,6 +54,7 @@
 #include "ifenum.h"
 #include "ipstats.h"
 #include "ipifcons.h"
+#include "mstcpip.h"
 
 #include "wine/debug.h"
 
@@ -642,23 +643,6 @@ static ULONG v4addressesFromIndex(DWORD index, DWORD **addrs, ULONG *num_addrs)
     return ERROR_SUCCESS;
 }
 
-static char *debugstr_ipv4(const in_addr_t *in_addr, char *buf)
-{
-    const BYTE *addrp;
-    char *p = buf;
-
-    for (addrp = (const BYTE *)in_addr;
-     addrp - (const BYTE *)in_addr < sizeof(*in_addr);
-     addrp++)
-    {
-        if (addrp == (const BYTE *)in_addr + sizeof(*in_addr) - 1)
-            sprintf(p, "%d", *addrp);
-        else
-            p += sprintf(p, "%d.", *addrp);
-    }
-    return buf;
-}
-
 static char *debugstr_ipv6(const struct WS_sockaddr_in6 *sin, char *buf)
 {
     const IN6_ADDR *addr = &sin->sin6_addr;
@@ -841,7 +825,7 @@ static ULONG adapterAddressesFromIndex(ULONG family, DWORD index, IP_ADAPTER_ADD
                 sa->sin_addr.s_addr = v4addrs[i];
                 sa->sin_port        = 0;
                 TRACE("IPv4 %d/%d: %s\n", i + 1, num_v4addrs,
-                      debugstr_ipv4(&sa->sin_addr.s_addr, addr_buf));
+                      RtlIpv4AddressToStringA((const struct in_addr*)&sa->sin_addr.s_addr, addr_buf));
 
                 ptr += ua->u.s.Length + ua->Address.iSockaddrLength;
                 if (i < num_v4addrs - 1)
diff --git a/include/mstcpip.h b/include/mstcpip.h
index 55fa542..a73146f 100644
--- a/include/mstcpip.h
+++ b/include/mstcpip.h
@@ -16,6 +16,9 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#ifndef _MSTCPIP_
+#define _MSTCPIP_
+
 struct tcp_keepalive
 {
     ULONG onoff;
@@ -60,3 +63,12 @@ struct tcp_keepalive
 #define WS_RCVALL_SOCKETLEVELONLY 2
 
 #endif /* USE_WS_PREFIX */
+
+
+CHAR * WINAPI RtlIpv4AddressToStringA(const struct in_addr *, LPSTR);
+WCHAR * WINAPI RtlIpv4AddressToStringW(const struct in_addr *, LPWSTR);
+#define RtlIpv4AddressToString WINELIB_NAME_AW(RtlIpv4AddressToString)
+
+
+
+#endif
-- 
1.7.0.4




More information about the wine-patches mailing list