refactor: Assume inet_atom on unix
ported ed2d44c346\#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20a
This commit is contained in:
committed by
Nick Bolton
parent
6ff8b053af
commit
90d6fc6f08
@ -121,31 +121,6 @@ macro(configure_unix_libs)
|
||||
message(FATAL_ERROR "Missing posix sigwait")
|
||||
endif()
|
||||
|
||||
check_function_exists(inet_aton HAVE_INET_ATON)
|
||||
|
||||
# For some reason, the check_function_exists macro doesn't detect the
|
||||
# inet_aton on some pure Unix platforms (e.g. sunos5). So we need to do a more
|
||||
# detailed check and also include some extra libs.
|
||||
if(NOT HAVE_INET_ATON)
|
||||
set(CMAKE_REQUIRED_LIBRARIES nsl)
|
||||
|
||||
check_c_source_compiles(
|
||||
"#include <arpa/inet.h>\n int main() { inet_aton (0, 0); }"
|
||||
HAVE_INET_ATON_ADV)
|
||||
|
||||
set(CMAKE_REQUIRED_LIBRARIES)
|
||||
|
||||
if(HAVE_INET_ATON_ADV)
|
||||
# Override the previous fail.
|
||||
set(HAVE_INET_ATON 1)
|
||||
|
||||
# Assume that both nsl and socket will be needed, it seems safe to add
|
||||
# socket on the back of nsl, since socket only ever needed when nsl is
|
||||
# needed.
|
||||
list(APPEND libs nsl socket)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# pthread is used on both Linux and Mac
|
||||
check_library_exists("pthread" pthread_create "" HAVE_PTHREAD)
|
||||
if(HAVE_PTHREAD)
|
||||
|
||||
@ -7,9 +7,6 @@
|
||||
|
||||
// clang-format off
|
||||
|
||||
/* Define if you have the `inet_aton` function. */
|
||||
#cmakedefine HAVE_INET_ATON @HAVE_INET_ATON@
|
||||
|
||||
/* Define to 1 if you have the <X11/extensions/Xrandr.h> header file. */
|
||||
#cmakedefine HAVE_X11_EXTENSIONS_XRANDR_H @HAVE_X11_EXTENSIONS_XRANDR_H@
|
||||
|
||||
|
||||
@ -25,10 +25,6 @@
|
||||
#include <netinet/tcp.h>
|
||||
#endif
|
||||
|
||||
#if !HAVE_INET_ATON
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
static const int s_family[] = {
|
||||
PF_UNSPEC,
|
||||
PF_INET,
|
||||
@ -37,27 +33,6 @@ static const int s_family[] = {
|
||||
|
||||
static const int s_type[] = {SOCK_DGRAM, SOCK_STREAM};
|
||||
|
||||
#if !HAVE_INET_ATON
|
||||
// parse dotted quad addresses. we don't bother with the weird BSD'ism
|
||||
// of handling octal and hex and partial forms.
|
||||
static in_addr_t inet_aton(const char *cp, struct in_addr *inp)
|
||||
{
|
||||
unsigned int a, b, c, d;
|
||||
if (sscanf(cp, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) {
|
||||
return 0;
|
||||
}
|
||||
if (a >= 256 || b >= 256 || c >= 256 || d >= 256) {
|
||||
return 0;
|
||||
}
|
||||
unsigned char *incp = (unsigned char *)inp;
|
||||
incp[0] = (unsigned char)(a & 0xffu);
|
||||
incp[1] = (unsigned char)(b & 0xffu);
|
||||
incp[2] = (unsigned char)(c & 0xffu);
|
||||
incp[3] = (unsigned char)(d & 0xffu);
|
||||
return inp->s_addr;
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// ArchNetworkBSD::Deps
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user