153a5a1b3Sopenharmony_ci/*** 253a5a1b3Sopenharmony_ci This file is part of PulseAudio. 353a5a1b3Sopenharmony_ci 453a5a1b3Sopenharmony_ci Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB 553a5a1b3Sopenharmony_ci 653a5a1b3Sopenharmony_ci PulseAudio is free software; you can redistribute it and/or modify 753a5a1b3Sopenharmony_ci it under the terms of the GNU Lesser General Public License as 853a5a1b3Sopenharmony_ci published by the Free Software Foundation; either version 2.1 of the 953a5a1b3Sopenharmony_ci License, or (at your option) any later version. 1053a5a1b3Sopenharmony_ci 1153a5a1b3Sopenharmony_ci PulseAudio is distributed in the hope that it will be useful, but 1253a5a1b3Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 1353a5a1b3Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1453a5a1b3Sopenharmony_ci Lesser General Public License for more details. 1553a5a1b3Sopenharmony_ci 1653a5a1b3Sopenharmony_ci You should have received a copy of the GNU Lesser General Public 1753a5a1b3Sopenharmony_ci License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 1853a5a1b3Sopenharmony_ci***/ 1953a5a1b3Sopenharmony_ci 2053a5a1b3Sopenharmony_ci#ifdef HAVE_CONFIG_H 2153a5a1b3Sopenharmony_ci#include <config.h> 2253a5a1b3Sopenharmony_ci#endif 2353a5a1b3Sopenharmony_ci 2453a5a1b3Sopenharmony_ci#if !defined(HAVE_ARPA_INET_H) && defined(OS_IS_WIN32) && (_WIN32_WINNT < 0x0600) 2553a5a1b3Sopenharmony_ci 2653a5a1b3Sopenharmony_ci#include <errno.h> 2753a5a1b3Sopenharmony_ci 2853a5a1b3Sopenharmony_ci#include <pulsecore/macro.h> 2953a5a1b3Sopenharmony_ci#include <pulsecore/socket.h> 3053a5a1b3Sopenharmony_ci#include <pulsecore/core-util.h> 3153a5a1b3Sopenharmony_ci 3253a5a1b3Sopenharmony_ci#include "arpa-inet.h" 3353a5a1b3Sopenharmony_ci 3453a5a1b3Sopenharmony_ciconst char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt) { 3553a5a1b3Sopenharmony_ci struct in_addr *in = (struct in_addr*)src; 3653a5a1b3Sopenharmony_ci#ifdef HAVE_IPV6 3753a5a1b3Sopenharmony_ci struct in6_addr *in6 = (struct in6_addr*)src; 3853a5a1b3Sopenharmony_ci#endif 3953a5a1b3Sopenharmony_ci 4053a5a1b3Sopenharmony_ci pa_assert(src); 4153a5a1b3Sopenharmony_ci pa_assert(dst); 4253a5a1b3Sopenharmony_ci 4353a5a1b3Sopenharmony_ci switch (af) { 4453a5a1b3Sopenharmony_ci case AF_INET: 4553a5a1b3Sopenharmony_ci pa_snprintf(dst, cnt, "%d.%d.%d.%d", 4653a5a1b3Sopenharmony_ci#ifdef WORDS_BIGENDIAN 4753a5a1b3Sopenharmony_ci (int)(in->s_addr >> 24) & 0xff, 4853a5a1b3Sopenharmony_ci (int)(in->s_addr >> 16) & 0xff, 4953a5a1b3Sopenharmony_ci (int)(in->s_addr >> 8) & 0xff, 5053a5a1b3Sopenharmony_ci (int)(in->s_addr >> 0) & 0xff); 5153a5a1b3Sopenharmony_ci#else 5253a5a1b3Sopenharmony_ci (int)(in->s_addr >> 0) & 0xff, 5353a5a1b3Sopenharmony_ci (int)(in->s_addr >> 8) & 0xff, 5453a5a1b3Sopenharmony_ci (int)(in->s_addr >> 16) & 0xff, 5553a5a1b3Sopenharmony_ci (int)(in->s_addr >> 24) & 0xff); 5653a5a1b3Sopenharmony_ci#endif 5753a5a1b3Sopenharmony_ci break; 5853a5a1b3Sopenharmony_ci#ifdef HAVE_IPV6 5953a5a1b3Sopenharmony_ci case AF_INET6: 6053a5a1b3Sopenharmony_ci pa_snprintf(dst, cnt, "%x:%x:%x:%x:%x:%x:%x:%x", 6153a5a1b3Sopenharmony_ci in6->s6_addr[ 0] << 8 | in6->s6_addr[ 1], 6253a5a1b3Sopenharmony_ci in6->s6_addr[ 2] << 8 | in6->s6_addr[ 3], 6353a5a1b3Sopenharmony_ci in6->s6_addr[ 4] << 8 | in6->s6_addr[ 5], 6453a5a1b3Sopenharmony_ci in6->s6_addr[ 6] << 8 | in6->s6_addr[ 7], 6553a5a1b3Sopenharmony_ci in6->s6_addr[ 8] << 8 | in6->s6_addr[ 9], 6653a5a1b3Sopenharmony_ci in6->s6_addr[10] << 8 | in6->s6_addr[11], 6753a5a1b3Sopenharmony_ci in6->s6_addr[12] << 8 | in6->s6_addr[13], 6853a5a1b3Sopenharmony_ci in6->s6_addr[14] << 8 | in6->s6_addr[15]); 6953a5a1b3Sopenharmony_ci break; 7053a5a1b3Sopenharmony_ci#endif 7153a5a1b3Sopenharmony_ci default: 7253a5a1b3Sopenharmony_ci errno = EAFNOSUPPORT; 7353a5a1b3Sopenharmony_ci return NULL; 7453a5a1b3Sopenharmony_ci } 7553a5a1b3Sopenharmony_ci 7653a5a1b3Sopenharmony_ci return dst; 7753a5a1b3Sopenharmony_ci} 7853a5a1b3Sopenharmony_ci 7953a5a1b3Sopenharmony_ciint inet_pton(int af, const char *src, void *dst) { 8053a5a1b3Sopenharmony_ci struct in_addr *in = (struct in_addr*)dst; 8153a5a1b3Sopenharmony_ci#ifdef HAVE_IPV6 8253a5a1b3Sopenharmony_ci struct in6_addr *in6 = (struct in6_addr*)dst; 8353a5a1b3Sopenharmony_ci#endif 8453a5a1b3Sopenharmony_ci 8553a5a1b3Sopenharmony_ci pa_assert(src); 8653a5a1b3Sopenharmony_ci pa_assert(dst); 8753a5a1b3Sopenharmony_ci 8853a5a1b3Sopenharmony_ci switch (af) { 8953a5a1b3Sopenharmony_ci case AF_INET: 9053a5a1b3Sopenharmony_ci in->s_addr = inet_addr(src); 9153a5a1b3Sopenharmony_ci if (in->s_addr == INADDR_NONE) 9253a5a1b3Sopenharmony_ci return 0; 9353a5a1b3Sopenharmony_ci break; 9453a5a1b3Sopenharmony_ci#ifdef HAVE_IPV6 9553a5a1b3Sopenharmony_ci case AF_INET6: 9653a5a1b3Sopenharmony_ci /* FIXME */ 9753a5a1b3Sopenharmony_ci#endif 9853a5a1b3Sopenharmony_ci default: 9953a5a1b3Sopenharmony_ci errno = EAFNOSUPPORT; 10053a5a1b3Sopenharmony_ci return -1; 10153a5a1b3Sopenharmony_ci } 10253a5a1b3Sopenharmony_ci 10353a5a1b3Sopenharmony_ci return 1; 10453a5a1b3Sopenharmony_ci} 10553a5a1b3Sopenharmony_ci 10653a5a1b3Sopenharmony_ci#endif 107