Commit 061b69e7 authored by Christophe Mutricy's avatar Christophe Mutricy

win32 replacement for inet_ntop()

parent 9979fb83
......@@ -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
......
......@@ -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
{
......
/*****************************************************************************
* 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 <fenrir@videolan.org>
* Rémi Denis-Courmont <rem # videolan.org>
* Christophe Mutricy <xtophe at videolan dot 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
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment