aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2014-09-12 12:06:34 +0200
committerLukas Larsson <[email protected]>2014-09-12 12:06:34 +0200
commita5bfb0a58783c472887ce0ad2060e4a395aa941d (patch)
tree93dd76737309acb93b79d58a6079ddf15833c5a1
parentdaa9e1a0d97612f6689685e5a597375ceb9e7b81 (diff)
downloadotp-a5bfb0a58783c472887ce0ad2060e4a395aa941d.tar.gz
otp-a5bfb0a58783c472887ce0ad2060e4a395aa941d.tar.bz2
otp-a5bfb0a58783c472887ce0ad2060e4a395aa941d.zip
erts: getsockname is not allowed on non-bound sockets
This only produces an error on win32, but should not really be called on *nix either.
-rw-r--r--erts/emulator/drivers/common/inet_drv.c12
-rw-r--r--lib/kernel/test/gen_tcp_api_SUITE_data/gen_tcp_api_SUITE.c4
2 files changed, 10 insertions, 6 deletions
diff --git a/erts/emulator/drivers/common/inet_drv.c b/erts/emulator/drivers/common/inet_drv.c
index 891589d1c5..db8a251fdd 100644
--- a/erts/emulator/drivers/common/inet_drv.c
+++ b/erts/emulator/drivers/common/inet_drv.c
@@ -4542,11 +4542,13 @@ static ErlDrvSSizeT inet_ctl_fdopen(inet_descriptor* desc, int domain, int type,
inet_address name;
unsigned int sz = sizeof(name);
- /* check that it is a socket and that the socket is bound */
- if (IS_SOCKET_ERROR(sock_name(s, (struct sockaddr*) &name, &sz)))
- return ctl_error(sock_errno(), rbuf, rsize);
- if (name.sa.sa_family != domain)
- return ctl_error(EINVAL, rbuf, rsize);
+ if (bound) {
+ /* check that it is a socket and that the socket is bound */
+ if (IS_SOCKET_ERROR(sock_name(s, (struct sockaddr*) &name, &sz)))
+ return ctl_error(sock_errno(), rbuf, rsize);
+ if (name.sa.sa_family != domain)
+ return ctl_error(EINVAL, rbuf, rsize);
+ }
#ifdef __OSE__
/* for fdopen duplicating the sd will allow to uniquely identify
the signal from OSE with erlang port */
diff --git a/lib/kernel/test/gen_tcp_api_SUITE_data/gen_tcp_api_SUITE.c b/lib/kernel/test/gen_tcp_api_SUITE_data/gen_tcp_api_SUITE.c
index 73a6568b30..d774767624 100644
--- a/lib/kernel/test/gen_tcp_api_SUITE_data/gen_tcp_api_SUITE.c
+++ b/lib/kernel/test/gen_tcp_api_SUITE_data/gen_tcp_api_SUITE.c
@@ -26,8 +26,10 @@
#ifdef __WIN32__
#include <winsock2.h>
+#define sock_close(s) closesocket(s)
#else
#include <sys/socket.h>
+#define sock_close(s) close(s)
#endif
#define sock_open(af, type, proto) socket((af), (type), (proto))
@@ -46,7 +48,7 @@ static ERL_NIF_TERM closesockfd(ErlNifEnv* env, int argc, const ERL_NIF_TERM arg
enif_get_int(env, argv[0], &fd);
- close(fd);
+ sock_close(fd);
return enif_make_int(env, fd);
}