From e3c0d6611087184b37399df2bf04053c60c9f043 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 30 Oct 2010 16:07:31 +0200 Subject: socket_wrapper: don't allow connect() to the broadcast address This will simplify other code later. metze --- lib/socket_wrapper/socket_wrapper.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c index 563c3a860d..346e0dfd45 100644 --- a/lib/socket_wrapper/socket_wrapper.c +++ b/lib/socket_wrapper/socket_wrapper.c @@ -1695,6 +1695,7 @@ _PUBLIC_ int swrap_connect(int s, const struct sockaddr *serv_addr, socklen_t ad int ret; struct sockaddr_un un_addr; struct socket_info *si = find_socket_info(s); + int bcast = 0; if (!si) { return real_connect(s, serv_addr, addrlen); @@ -1710,9 +1711,15 @@ _PUBLIC_ int swrap_connect(int s, const struct sockaddr *serv_addr, socklen_t ad return -1; } - ret = sockaddr_convert_to_un(si, (const struct sockaddr *)serv_addr, addrlen, &un_addr, 0, NULL); + ret = sockaddr_convert_to_un(si, (const struct sockaddr *)serv_addr, + addrlen, &un_addr, 0, &bcast); if (ret == -1) return -1; + if (bcast) { + errno = ENETUNREACH; + return -1; + } + if (si->type == SOCK_DGRAM) { si->defer_connect = 1; ret = 0; -- cgit