2018-04-10 13:57:17 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016-2018 Chung, Hyung-Hwan. All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2023-11-21 15:24:57 +00:00
|
|
|
|
2024-05-14 12:14:39 +00:00
|
|
|
#include <hcl-x.h>
|
2018-04-10 13:57:17 +00:00
|
|
|
#include "hcl-prv.h"
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
# include <winsock2.h>
|
|
|
|
# include <ws2tcpip.h> /* sockaddr_in6 */
|
|
|
|
# include <windows.h>
|
|
|
|
#elif defined(__OS2__)
|
|
|
|
# if defined(TCPV40HDRS)
|
|
|
|
# define BSD_SELECT
|
|
|
|
# endif
|
|
|
|
# include <types.h>
|
|
|
|
# include <sys/socket.h>
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#else
|
2024-04-21 07:29:55 +00:00
|
|
|
# if defined(HAVE_SYS_IOCTL_H)
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
# endif
|
|
|
|
# if defined(HAVE_NET_IF_H)
|
|
|
|
# include <net/if.h>
|
|
|
|
# endif
|
2018-04-10 13:57:17 +00:00
|
|
|
# include <netinet/in.h>
|
2024-04-21 07:29:55 +00:00
|
|
|
# include <unistd.h>
|
|
|
|
# include <errno.h>
|
2018-04-10 13:57:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
union sockaddr_t
|
|
|
|
{
|
|
|
|
struct sockaddr sa;
|
|
|
|
#if (HCL_SIZEOF_STRUCT_SOCKADDR_IN > 0)
|
|
|
|
struct sockaddr_in in4;
|
|
|
|
#endif
|
|
|
|
#if (HCL_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
|
|
|
struct sockaddr_in6 in6;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
typedef union sockaddr_t sockaddr_t;
|
|
|
|
|
2024-04-21 07:29:55 +00:00
|
|
|
#undef ooch_mode
|
2018-04-10 13:57:17 +00:00
|
|
|
#undef ooch_t
|
|
|
|
#undef oocs_t
|
|
|
|
#undef str_to_ipv4
|
|
|
|
#undef str_to_ipv6
|
|
|
|
#undef str_to_sockaddr
|
2024-04-21 07:29:55 +00:00
|
|
|
#undef str_to_ifindex
|
2018-04-10 13:57:17 +00:00
|
|
|
|
2024-04-21 07:29:55 +00:00
|
|
|
#define ooch_mode (1)
|
2018-04-10 13:57:17 +00:00
|
|
|
#define ooch_t hcl_bch_t
|
|
|
|
#define oocs_t hcl_bcs_t
|
|
|
|
#define str_to_ipv4 bchars_to_ipv4
|
|
|
|
#define str_to_ipv6 bchars_to_ipv6
|
2024-04-21 07:29:55 +00:00
|
|
|
#define str_to_ifindex bchars_to_ifindex
|
2018-04-10 13:57:17 +00:00
|
|
|
#define str_to_sockaddr hcl_bcharstosckaddr
|
2024-05-14 12:14:39 +00:00
|
|
|
#include "x-utl-sa.h"
|
2018-04-10 13:57:17 +00:00
|
|
|
|
2024-04-21 07:29:55 +00:00
|
|
|
#undef ooch_mode
|
2018-04-10 13:57:17 +00:00
|
|
|
#undef ooch_t
|
|
|
|
#undef oocs_t
|
|
|
|
#undef str_to_ipv4
|
|
|
|
#undef str_to_ipv6
|
2024-04-21 07:29:55 +00:00
|
|
|
#undef str_to_ifindex
|
2018-04-10 13:57:17 +00:00
|
|
|
#undef str_to_sockaddr
|
|
|
|
|
2024-04-21 07:29:55 +00:00
|
|
|
#define ooch_mode (2)
|
2018-04-10 13:57:17 +00:00
|
|
|
#define ooch_t hcl_uch_t
|
|
|
|
#define oocs_t hcl_ucs_t
|
|
|
|
#define str_to_ipv4 uchars_to_ipv4
|
|
|
|
#define str_to_ipv6 uchars_to_ipv6
|
2024-04-21 07:29:55 +00:00
|
|
|
#define str_to_ifindex uchars_to_ifindex
|
2018-04-10 13:57:17 +00:00
|
|
|
#define str_to_sockaddr hcl_ucharstosckaddr
|
2024-05-14 12:14:39 +00:00
|
|
|
#include "x-utl-sa.h"
|
2018-04-10 13:57:17 +00:00
|
|
|
|
|
|
|
int hcl_get_sckaddr_info (const hcl_sckaddr_t* sckaddr, hcl_scklen_t* scklen)
|
|
|
|
{
|
|
|
|
sockaddr_t* sa = (sockaddr_t*)sckaddr;
|
|
|
|
if (scklen)
|
|
|
|
{
|
|
|
|
switch (sa->sa.sa_family)
|
|
|
|
{
|
|
|
|
#if (HCL_SIZEOF_STRUCT_SOCKADDR_IN > 0)
|
|
|
|
case AF_INET:
|
|
|
|
*scklen = HCL_SIZEOF(sa->in4);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (HCL_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
|
|
|
case AF_INET6:
|
|
|
|
*scklen = HCL_SIZEOF(sa->in6);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
*scklen = 0; /* unknown */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sa->sa.sa_family;
|
|
|
|
}
|