aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--erts/emulator/nifs/common/socket_nif.c59
-rw-r--r--erts/preloaded/ebin/socket.beambin44804 -> 44828 bytes
-rw-r--r--erts/preloaded/src/socket.erl9
-rw-r--r--lib/kernel/test/socket_client.erl34
-rw-r--r--lib/kernel/test/socket_server.erl8
5 files changed, 92 insertions, 18 deletions
diff --git a/erts/emulator/nifs/common/socket_nif.c b/erts/emulator/nifs/common/socket_nif.c
index 0972834cb2..22ac124802 100644
--- a/erts/emulator/nifs/common/socket_nif.c
+++ b/erts/emulator/nifs/common/socket_nif.c
@@ -372,6 +372,7 @@ typedef union {
#define SOCKET_OPT_IP_MULTICAST_TTL 16
#define SOCKET_OPT_IP_NODEFRAG 17
#define SOCKET_OPT_IP_RECVTOS 25
+#define SOCKET_OPT_IP_RECVTTL 26
#define SOCKET_OPT_IP_ROUTER_ALERT 28
#define SOCKET_OPT_IP_TOS 30
#define SOCKET_OPT_IP_TTL 32
@@ -904,6 +905,11 @@ static ERL_NIF_TERM nsetopt_lvl_ip_recvtos(ErlNifEnv* env,
SocketDescriptor* descP,
ERL_NIF_TERM eVal);
#endif
+#if defined(IP_RECVTTL)
+static ERL_NIF_TERM nsetopt_lvl_ip_recvttl(ErlNifEnv* env,
+ SocketDescriptor* descP,
+ ERL_NIF_TERM eVal);
+#endif
#if defined(IP_ROUTER_ALERT)
static ERL_NIF_TERM nsetopt_lvl_ip_router_alert(ErlNifEnv* env,
SocketDescriptor* descP,
@@ -1099,6 +1105,10 @@ static ERL_NIF_TERM ngetopt_lvl_ip_nodefrag(ErlNifEnv* env,
static ERL_NIF_TERM ngetopt_lvl_ip_recvtos(ErlNifEnv* env,
SocketDescriptor* descP);
#endif
+#if defined(IP_RECVTTL)
+static ERL_NIF_TERM ngetopt_lvl_ip_recvttl(ErlNifEnv* env,
+ SocketDescriptor* descP);
+#endif
#if defined(IP_ROUTER_ALERT)
static ERL_NIF_TERM ngetopt_lvl_ip_router_alert(ErlNifEnv* env,
SocketDescriptor* descP);
@@ -4101,6 +4111,12 @@ ERL_NIF_TERM nsetopt_lvl_ip(ErlNifEnv* env,
break;
#endif
+#if defined(IP_RECVTTL)
+ case SOCKET_OPT_IP_RECVTTL:
+ result = nsetopt_lvl_ip_recvttl(env, descP, eVal);
+ break;
+#endif
+
#if defined(IP_ROUTER_ALERT)
case SOCKET_OPT_IP_ROUTER_ALERT:
result = nsetopt_lvl_ip_router_alert(env, descP, eVal);
@@ -4398,6 +4414,25 @@ ERL_NIF_TERM nsetopt_lvl_ip_recvtos(ErlNifEnv* env,
#endif
+/* nsetopt_lvl_ip_recvttl - Level IP RECVTTL option
+ */
+#if defined(IP_RECVTTL)
+static
+ERL_NIF_TERM nsetopt_lvl_ip_recvttl(ErlNifEnv* env,
+ SocketDescriptor* descP,
+ ERL_NIF_TERM eVal)
+{
+#if defined(SOL_IP)
+ int level = SOL_IP;
+#else
+ int level = IPPROTO_IP;
+#endif
+
+ return nsetopt_bool_opt(env, descP, level, IP_RECVTTL, eVal);
+}
+#endif
+
+
/* nsetopt_lvl_ip_router_alert - Level IP ROUTER_ALERT option
*/
#if defined(IP_ROUTER_ALERT)
@@ -5656,6 +5691,12 @@ ERL_NIF_TERM ngetopt_lvl_ip(ErlNifEnv* env,
break;
#endif
+#if defined(IP_RECVTTL)
+ case SOCKET_OPT_IP_RECVTTL:
+ result = ngetopt_lvl_ip_recvttl(env, descP);
+ break;
+#endif
+
#if defined(IP_ROUTER_ALERT)
case SOCKET_OPT_IP_ROUTER_ALERT:
result = ngetopt_lvl_ip_router_alert(env, descP);
@@ -5862,6 +5903,24 @@ ERL_NIF_TERM ngetopt_lvl_ip_recvtos(ErlNifEnv* env,
#endif
+/* ngetopt_lvl_ip_recvttl - Level IP RECVTTL option
+ */
+#if defined(IP_RECVTTL)
+static
+ERL_NIF_TERM ngetopt_lvl_ip_recvttl(ErlNifEnv* env,
+ SocketDescriptor* descP)
+{
+#if defined(SOL_IP)
+ int level = SOL_IP;
+#else
+ int level = IPPROTO_IP;
+#endif
+
+ return ngetopt_bool_opt(env, descP, level, IP_RECVTTL);
+}
+#endif
+
+
/* ngetopt_lvl_ip_router_alert - Level IP ROUTER_ALERT option
*/
#if defined(IP_ROUTER_ALERT)
diff --git a/erts/preloaded/ebin/socket.beam b/erts/preloaded/ebin/socket.beam
index 359a329287..2f81e4cc29 100644
--- a/erts/preloaded/ebin/socket.beam
+++ b/erts/preloaded/ebin/socket.beam
Binary files differ
diff --git a/erts/preloaded/src/socket.erl b/erts/preloaded/src/socket.erl
index 3077a794a5..d54c8d5f33 100644
--- a/erts/preloaded/src/socket.erl
+++ b/erts/preloaded/src/socket.erl
@@ -540,7 +540,7 @@
%% -define(SOCKET_OPT_IP_RECVOPTS, 23).
%% -define(SOCKET_OPT_IP_RECVORIGDSTADDR, 24).
-define(SOCKET_OPT_IP_RECVTOS, 25).
-%% -define(SOCKET_OPT_IP_RECVTTL, 26).
+-define(SOCKET_OPT_IP_RECVTTL, 26).
%% -define(SOCKET_OPT_IP_RETOPTS, 27).
-define(SOCKET_OPT_IP_ROUTER_ALERT, 28).
%% -define(SOCKET_OPT_IP_SNDSRCADDR, 29).
@@ -2010,6 +2010,9 @@ enc_setopt_value(ip, nodefrag, V, _D, _T, _P)
enc_setopt_value(ip, recvtos, V, _D, _T, _P)
when is_boolean(V) ->
V;
+enc_setopt_value(ip, recvttl, V, _D, _T, _P)
+ when is_boolean(V) ->
+ V;
enc_setopt_value(ip, router_alert, V, _D, _T, _P)
when is_integer(V) ->
V;
@@ -2323,8 +2326,8 @@ enc_sockopt_key(ip = L, recvorigdstaddr = Opt, _Dir, _D, _T, _P) ->
not_supported({L, Opt});
enc_sockopt_key(ip, recvtos = _Opt, _Dir, _D, _T, _P) ->
?SOCKET_OPT_IP_RECVTOS;
-enc_sockopt_key(ip = L, recvttl = Opt, _Dir, _D, T, _P) when (T =/= stream) ->
- not_supported({L, Opt});
+enc_sockopt_key(ip = _L, recvttl = _Opt, _Dir, _D, T, _P) when (T =/= stream) ->
+ ?SOCKET_OPT_IP_RECVTTL;
enc_sockopt_key(ip = L, retopts = Opt, _Dir, _D, _T, _P) ->
not_supported({L, Opt});
enc_sockopt_key(ip, router_alert = _Opt, _Dir, _D, raw = _T, _P) ->
diff --git a/lib/kernel/test/socket_client.erl b/lib/kernel/test/socket_client.erl
index fa905de954..8ec9a02374 100644
--- a/lib/kernel/test/socket_client.erl
+++ b/lib/kernel/test/socket_client.erl
@@ -86,6 +86,7 @@ do_start(Domain, stream = Type, Proto, SA) ->
{ok, MIF} = socket:getopt(Sock, ip, multicast_if),
{ok, MLoop} = socket:getopt(Sock, ip, multicast_loop),
{ok, MTTL} = socket:getopt(Sock, ip, multicast_ttl),
+ {ok, RecvTOS} = socket:getopt(Sock, ip, recvtos),
i("connected: "
"~n From: ~p"
"~n To: ~p"
@@ -103,11 +104,13 @@ do_start(Domain, stream = Type, Proto, SA) ->
"~n (ip) Multicast IF: ~p"
"~n (ip) Multicast Loop: ~p"
"~n (ip) Multicast TTL: ~p"
+ "~n (ip) RecvTOS: ~p"
"~n => wait some",
[Name, Peer,
Domain, Type, Proto,
OOBI, SndBuf, RcvBuf, Linger,
- MTU, MTUDisc, MALL, MIF, MLoop, MTTL]),
+ MTU, MTUDisc, MALL, MIF, MLoop, MTTL,
+ RecvTOS]),
%% Give the server some time...
?LIB:sleep(5000),
%% ok = socket:close(Sock),
@@ -122,17 +125,19 @@ do_start(Domain, dgram = Type, Proto, SA) ->
try do_init(Domain, Type, Proto) of
Sock ->
%% Give the server some time...
- {ok, Domain} = socket:getopt(Sock, socket, domain),
- {ok, Type} = socket:getopt(Sock, socket, type),
- {ok, Proto} = socket:getopt(Sock, socket, protocol),
- {ok, OOBI} = socket:getopt(Sock, socket, oobinline),
- {ok, SndBuf} = socket:getopt(Sock, socket, sndbuf),
- {ok, RcvBuf} = socket:getopt(Sock, socket, rcvbuf),
- {ok, Linger} = socket:getopt(Sock, socket, linger),
- {ok, MALL} = socket:getopt(Sock, ip, multicast_all),
- {ok, MIF} = socket:getopt(Sock, ip, multicast_if),
- {ok, MLoop} = socket:getopt(Sock, ip, multicast_loop),
- {ok, MTTL} = socket:getopt(Sock, ip, multicast_ttl),
+ {ok, Domain} = socket:getopt(Sock, socket, domain),
+ {ok, Type} = socket:getopt(Sock, socket, type),
+ {ok, Proto} = socket:getopt(Sock, socket, protocol),
+ {ok, OOBI} = socket:getopt(Sock, socket, oobinline),
+ {ok, SndBuf} = socket:getopt(Sock, socket, sndbuf),
+ {ok, RcvBuf} = socket:getopt(Sock, socket, rcvbuf),
+ {ok, Linger} = socket:getopt(Sock, socket, linger),
+ {ok, MALL} = socket:getopt(Sock, ip, multicast_all),
+ {ok, MIF} = socket:getopt(Sock, ip, multicast_if),
+ {ok, MLoop} = socket:getopt(Sock, ip, multicast_loop),
+ {ok, MTTL} = socket:getopt(Sock, ip, multicast_ttl),
+ {ok, RecvTOS} = socket:getopt(Sock, ip, recvtos),
+ {ok, RecvTTL} = socket:getopt(Sock, ip, recvttl),
i("initiated when: "
"~n (socket) Domain: ~p"
"~n (socket) Type: ~p"
@@ -145,10 +150,13 @@ do_start(Domain, dgram = Type, Proto, SA) ->
"~n (ip) Multicast IF: ~p"
"~n (ip) Multicast Loop: ~p"
"~n (ip) Multicast TTL: ~p"
+ "~n (ip) RecvTOS: ~p"
+ "~n (ip) RecvTTL: ~p"
"~n => wait some",
[Domain, Type, Proto,
OOBI, SndBuf, RcvBuf, Linger,
- MALL, MIF, MLoop, MTTL]),
+ MALL, MIF, MLoop, MTTL,
+ RecvTOS, RecvTTL]),
?LIB:sleep(5000),
%% ok = socket:close(Sock),
send_loop(#client{socket = Sock,
diff --git a/lib/kernel/test/socket_server.erl b/lib/kernel/test/socket_server.erl
index 6a207a7b1b..ff8f6575a3 100644
--- a/lib/kernel/test/socket_server.erl
+++ b/lib/kernel/test/socket_server.erl
@@ -460,6 +460,8 @@ handler_init(Manager, ID, Peek, Sock) ->
{ok, MLoop} = socket:getopt(Sock, ip, multicast_loop),
{ok, MTTL} = socket:getopt(Sock, ip, multicast_ttl),
NF = G(nodefrag), % raw only
+ RecvTOS = G(recvtos),
+ RecvTTL = G(recvttl), % not stream
i("got continue when: "
"~n (socket) Domain: ~p"
"~n (socket) Type: ~p"
@@ -474,11 +476,13 @@ handler_init(Manager, ID, Peek, Sock) ->
"~n (ip) Multicast IF: ~p"
"~n (ip) Multicast Loop: ~p"
"~n (ip) Multicast TTL: ~p"
- "~n (ip) NodeFrag: ~s",
+ "~n (ip) NodeFrag: ~s"
+ "~n (ip) RecvTOS: ~s"
+ "~n (ip) RecvTTL: ~s",
[Domain, Type, Proto,
OOBI, SndBuf, RcvBuf, Linger,
MTU, MTUDisc, MALL, MIF, MLoop, MTTL,
- NF]),
+ NF, RecvTOS, RecvTTL]),
%% socket:setopt(Sock, otp, debug, true),
handler_loop(#handler{peek = Peek,
manager = Manager,