Skip to content

Commit 86872f3

Browse files
authored
Merge pull request #595 from nielsdg/feature/use-inet_pton-if-available
Use inet_pton() when available
2 parents 95adfca + 15e8709 commit 86872f3

File tree

7 files changed

+21
-3
lines changed

7 files changed

+21
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ check_include_file(winsock2.h HAVE_WINSOCK2_H)
3737

3838
check_function_exists(sigaction HAVE_SIGACTION)
3939
check_function_exists(inet_aton HAVE_INET_ATON)
40+
check_function_exists(inet_pton HAVE_INET_PTON)
4041
check_function_exists(usleep HAVE_USLEEP)
4142

4243
check_type_size(uint8_t UINT8_T)

config_in.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
/* Define to 1 if you have the `inet_aton' function. */
3131
#undef HAVE_INET_ATON
3232

33+
/* Define to 1 if you have the `inet_pton' function. */
34+
#undef HAVE_INET_PTON
35+
3336
/* Define to 1 if the system has the type `int16_t'. */
3437
#undef HAVE_INT16_T
3538

config_in_cmake.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
/* Define to 1 if you have the `inet_aton' function. */
8383
#cmakedefine HAVE_INET_ATON 1
8484

85+
/* Define to 1 if you have the `inet_pton' function. */
86+
#cmakedefine HAVE_INET_PTON 1
87+
8588
/* Define to 1 if you have the `sigaction' function. */
8689
#cmakedefine HAVE_SIGACTION 1
8790

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5195,7 +5195,7 @@ _ACEOF
51955195
fi
51965196

51975197

5198-
for ac_func in socket inet_aton usleep sigaction
5198+
for ac_func in socket inet_aton inet_pton usleep sigaction
51995199
do :
52005200
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
52015201
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ AC_C_INLINE
166166
AC_TYPE_SIZE_T
167167

168168
dnl Checks for library functions.
169-
AC_CHECK_FUNCS([socket inet_aton usleep sigaction])
169+
AC_CHECK_FUNCS([socket inet_aton inet_pton usleep sigaction])
170170

171171
dnl Find socket function if not found yet.
172172
if test "x$ac_cv_func_socket" = "xno"; then

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ endforeach
4646
check_functions = [
4747
'sigaction',
4848
'inet_aton',
49+
'inet_pton',
4950
'usleep',
5051
'socket',
5152
]

test/rtpw.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,17 @@ int main(int argc, char *argv[])
285285
port = atoi(argv[optind_s++]);
286286

287287
/* set address */
288-
#ifdef HAVE_INET_ATON
288+
#ifdef HAVE_INET_PTON
289+
if (0 == inet_pton(AF_INET, address, &rcvr_addr)) {
290+
fprintf(stderr, "%s: cannot parse IP v4 address %s\n", argv[0],
291+
address);
292+
exit(1);
293+
}
294+
if (rcvr_addr.s_addr == INADDR_NONE) {
295+
fprintf(stderr, "%s: address error", argv[0]);
296+
exit(1);
297+
}
298+
#elif HAVE_INET_ATON
289299
if (0 == inet_aton(address, &rcvr_addr)) {
290300
fprintf(stderr, "%s: cannot parse IP v4 address %s\n", argv[0],
291301
address);

0 commit comments

Comments
 (0)