Permalink
Browse files

Fix a backward compatibility bug with inet:parse_strict_address/1

inet:parse_strict_address/1 was introduced in R16. For previous releases, we
need to rely on inet_parse:ipv4strict_address/1 and
inet_parse:ipv6strict_address/1 functions.
  • Loading branch information...
1 parent cba96bc commit 8ff00fe0c88600d6d91b477ec5dee91892b291c1 @capflam capflam committed Jun 23, 2014
Showing with 34 additions and 1 deletion.
  1. +12 −0 configure.ac
  2. +4 −0 include.mk
  3. +18 −1 src/yaws.erl
View
12 configure.ac
@@ -332,6 +332,18 @@ fi
AM_CONDITIONAL(HAVE_CRYPTO_HASH, [test "x$HAVE_CRYPTO_HASH" = "xtrue"])
AC_SUBST(HAVE_CRYPTO_HASH)
+AC_MSG_CHECKING([for inet:parse_strict_address/1])
+HAVE_INET_PARSE_STRICT_ADDRESS=false
+inet_parse_strict_address=`"${ERL}" -noshell -eval 'code:ensure_loaded(inet), io:format("~p~n",[[erlang:function_exported(inet, parse_strict_address,1)]]), erlang:halt().' | tail -1`
+if test "$inet_parse_strict_address" = true; then
+ HAVE_INET_PARSE_STRICT_ADDRESS=true
+ AC_MSG_RESULT([yes])
+else
+ AC_MSG_RESULT([no])
+fi
+AM_CONDITIONAL(HAVE_INET_PARSE_STRICT_ADDRESS, [test "x$INET_PARSE_STRICT_ADDRESS" = "xtrue"])
+AC_SUBST(HAVE_INET_PARSE_STRICT_ADDRESS)
+
dnl ------------------------------------------------------------------
dnl Check for programs used during Yaws compilation/installation
dnl ------------------------------------------------------------------
View
4 include.mk
@@ -20,6 +20,10 @@ ifeq ($(HAVE_CRYPTO_HASH),true)
ERLC_GENERIC_FLAGS += -DHAVE_CRYPTO_HASH
endif
+ifeq ($(HAVE_INET_PARSE_STRICT_ADDRESS),true)
+ ERLC_GENERIC_FLAGS += -DHAVE_INET_PARSE_STRICT_ADDRESS
+endif
+
# Local Variables:
# tab-width: 8
# End:
View
19 src/yaws.erl
@@ -2029,7 +2029,7 @@ parse_ipaddr_and_connect(Proto, Host, Port, Options, Timeout) ->
%% First, try to parse an IP address, because inet:getaddr/2 could
%% return nxdomain if the family doesn't match the IP address
%% format.
- case inet:parse_strict_address(Host) of
+ case parse_strict_address(Host) of
{ok, IP} ->
filter_tcpoptions_and_connect(Proto, undefined,
IP, Port, Options, Timeout);
@@ -2039,6 +2039,23 @@ parse_ipaddr_and_connect(Proto, Host, Port, Options, Timeout) ->
Host, Port, Options, Timeout)
end.
+-ifdef(HAVE_INET_PARSE_STRICT_ADDRESS).
+
+parse_strict_address(Host) ->
+ inet:parse_strict_address(Host).
+
+-else.
+
+parse_strict_address(Host) when is_list(Host) ->
+ case inet_parse:ipv4strict_address(Host) of
+ {ok,IP} -> {ok,IP};
+ _ -> inet_parse:ipv6strict_address(Host)
+ end;
+parse_strict_address(_) ->
+ {error, einval}.
+
+-endif.
+
filter_tcpoptions_and_connect(Proto, NsLookupPref,
Host, Port, Options, Timeout) ->
%% Now that we have IP addresses, remove family from the TCP options,

0 comments on commit 8ff00fe

Please sign in to comment.