From 061b69e72b87daf817e1b4fa23c8b1286de3955a Mon Sep 17 00:00:00 2001 From: Christophe Mutricy Date: Thu, 15 Feb 2007 15:34:50 +0000 Subject: [PATCH] win32 replacement for inet_ntop() --- configure.ac | 5 ++++ include/vlc_network.h | 8 +++++++ src/network/io.c | 54 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index abe3035970..11140868ee 100644 --- a/configure.ac +++ b/configure.ac @@ -2407,6 +2407,11 @@ AC_CHECK_FUNCS(inet_pton,[have_ipv6=yes],[ AS_IF([test "${have_ipv6}" = "yes"], [ AC_DEFINE(HAVE_INET_PTON, 1, [Define to 1 if you have inet_pton().])]) + +AC_CHECK_FUNCS(inet_ntop,[ + AC_DEFINE(HAVE_INET_NTOP, 1, [Define to 1 if you have inet_ntop().])]) + + dnl dnl ogg demux plugin dnl diff --git a/include/vlc_network.h b/include/vlc_network.h index 988d8d5741..826243faac 100644 --- a/include/vlc_network.h +++ b/include/vlc_network.h @@ -150,6 +150,14 @@ VLC_EXPORT( int, __net_vaPrintf, ( vlc_object_t *p_this, int fd, const v_socket_ VLC_EXPORT (int, inet_pton, (int af, const char *src, void *dst) ); #endif +#ifndef HAVE_INET_NTOP +#ifdef WIN32 +/* only in core, so no need for C++ extern "C" */ +VLC_EXPORT (const char *, inet_ntop, (int af, const void *src, + char *dst, socklen_t cnt) ); +#endif +#endif + #ifndef HAVE_POLL enum { diff --git a/src/network/io.c b/src/network/io.c index b66ddc6b1f..c88c243dbe 100644 --- a/src/network/io.c +++ b/src/network/io.c @@ -1,12 +1,13 @@ /***************************************************************************** * io.c: network I/O functions ***************************************************************************** - * Copyright (C) 2004-2005 the VideoLAN team + * Copyright (C) 2004-2005, 2007 the VideoLAN team * Copyright © 2005-2006 Rémi Denis-Courmont * $Id$ * * Authors: Laurent Aimar * Rémi Denis-Courmont + * Christophe Mutricy * * 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 @@ -649,3 +650,54 @@ int inet_pton(int af, const char *src, void *dst) return 0; } #endif /* HAVE_INET_PTON */ + +#ifndef HAVE_INET_NTOP +#ifdef WIN32 +const char *inet_ntop(int af, const void * src, + char * dst, socklen_t cnt) +{ + switch( af ) + { +#ifdef AF_INET6 + case AF_INET6: + { + struct sockaddr_in6 addr; + memset(&addr, 0, sizeof(addr)); + addr.sin6_family = AF_INET6; + addr.sin6_addr = *((struct in6_addr*)src); + if( 0 == WSAAddressToStringA((LPSOCKADDR)&addr, + sizeof(struct sockaddr_in6), + NULL, dst, &cnt) ) + { + dst[cnt] = '\0'; + return dst; + } + errno = WSAGetLastError(); + return NULL; + + } + +#endif + case AF_INET: + { + struct sockaddr_in addr; + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_addr = *((struct in_addr*)src); + if( 0 == WSAAddressToStringA((LPSOCKADDR)&addr, + sizeof(struct sockaddr_in), + NULL, dst, &cnt) ) + { + dst[cnt] = '\0'; + return dst; + } + errno = WSAGetLastError(); + return NULL; + + } + } + errno = EAFNOSUPPORT; + return NULL; +} +#endif +#endif -- 2.39.5