aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/nifs/common/net_nif.c
diff options
context:
space:
mode:
authorMicael Karlberg <[email protected]>2018-06-18 18:19:39 +0200
committerMicael Karlberg <[email protected]>2018-09-18 14:50:18 +0200
commitb63a16d0958bd748644d22f13f35f8956a903d6c (patch)
tree23f56ff33354c084b344804f73d71f1235a10b59 /erts/emulator/nifs/common/net_nif.c
parent978a8a855c57bdfb20d3bcd8a6055968f3be3887 (diff)
downloadotp-b63a16d0958bd748644d22f13f35f8956a903d6c.tar.gz
otp-b63a16d0958bd748644d22f13f35f8956a903d6c.tar.bz2
otp-b63a16d0958bd748644d22f13f35f8956a903d6c.zip
[socket+net-nif] Moved common functions into util files
The common stuff, like decode and encode of common types (soch as socket address), has been moved into a util file (socket_util). The debug stuff has also been moved into its own file. Also introduced a common include file for common macros and types. OTP-14831
Diffstat (limited to 'erts/emulator/nifs/common/net_nif.c')
-rw-r--r--erts/emulator/nifs/common/net_nif.c87
1 files changed, 7 insertions, 80 deletions
diff --git a/erts/emulator/nifs/common/net_nif.c b/erts/emulator/nifs/common/net_nif.c
index 9a96eff654..572813ac62 100644
--- a/erts/emulator/nifs/common/net_nif.c
+++ b/erts/emulator/nifs/common/net_nif.c
@@ -1390,7 +1390,7 @@ ERL_NIF_TERM encode_address_info(ErlNifEnv* env,
}
-/* Convert an "native" family to an erlang family
+/* Convert an "native" family to an erlang family (=domain).
* Note that this is not currently exhaustive, but only supports
* inet and inet6. Other values will be returned as is, that is
* in the form of an integer.
@@ -1401,34 +1401,15 @@ ERL_NIF_TERM encode_address_info_family(ErlNifEnv* env,
{
ERL_NIF_TERM efam;
- switch (family) {
- case AF_INET:
- efam = esock_atom_inet;
- break;
-
-#if defined(HAVE_IN6) && defined(AF_INET6)
- case AF_INET6:
- efam = esock_atom_inet6;
- break;
-#endif
-
- #ifdef HAVE_SYS_UN_H
- case AF_UNIX:
- efam = esock_atom_local;
- break;
-#endif
-
- default:
+ if (NULL != esock_encode_type(env, family, &efam))
efam = MKI(env, family);
- break;
- }
return efam;
}
-/* Convert an "native" socket type to an erlang socket type
+/* Convert an "native" socket type to an erlang socket type.
* Note that this is not currently exhaustive, but only supports
* stream and dgram. Other values will be returned as is, that is
* in the form of an integer.
@@ -1439,38 +1420,15 @@ ERL_NIF_TERM encode_address_info_type(ErlNifEnv* env,
{
ERL_NIF_TERM etype;
- switch (socktype) {
- case SOCK_STREAM:
- etype = esock_atom_stream;
- break;
-
- case SOCK_DGRAM:
- etype = esock_atom_dgram;
- break;
-
- case SOCK_RAW:
- etype = esock_atom_raw;
- break;
-
- case SOCK_RDM:
- etype = esock_atom_rdm;
- break;
-
- case SOCK_SEQPACKET:
- etype = esock_atom_seqpacket;
- break;
-
- default:
+ if (NULL != esock_encode_type(env, socktype, &etype))
etype = MKI(env, socktype);
- break;
- }
return etype;
}
-/* Convert an "native" protocol to an erlang protocol
+/* Convert an "native" protocol to an erlang protocol.
* Note that this is not currently exhaustive, but only supports
* tcp and udp. Other values will be returned as is, that is
* in the form of an integer.
@@ -1481,39 +1439,8 @@ ERL_NIF_TERM encode_address_info_proto(ErlNifEnv* env,
{
ERL_NIF_TERM eproto;
- switch (proto) {
-#if defined(SOL_IP)
- case SOL_IP:
-#else
- case IPPROTO_IP:
-#endif
- eproto = esock_atom_ip;
- break;
-
-#if defined(SOL_IPV6)
- case SOL_IPV6:
- eproto = esock_atom_ipv6;
- break;
-#endif
-
- case IPPROTO_TCP:
- eproto = esock_atom_tcp;
- break;
-
- case IPPROTO_UDP:
- eproto = esock_atom_udp;
- break;
-
-#if defined(HAVE_SCTP)
- case IPPROTO_SCTP:
- eproto = esock_atom_sctp;
- break;
-#endif
-
- default:
+ if (NULL != esock_encode_protocol(env, proto, &eproto))
eproto = MKI(env, proto);
- break;
- }
return eproto;
}
@@ -1615,7 +1542,7 @@ static
int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
{
// We should make it possible to use load_info to get default values
- data.debug = FALSE;
+ data.debug = TRUE;
NDBG( ("NET", "on_load -> entry\r\n") );