diff options
author | Stefan Metzmacher <metze@samba.org> | 2015-05-21 11:39:38 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2015-06-12 17:08:17 +0200 |
commit | 36b97d0bb9fe004f3d8a500f3af83dff34f86d7b (patch) | |
tree | d95abbb1f1a83051f9f3a526f57197cf4c4d55c9 /lib/tsocket | |
parent | 3a8b7b0518b33b016d2dbb8dd23d35ef1c6aaa5c (diff) | |
download | samba-36b97d0bb9fe004f3d8a500f3af83dff34f86d7b.tar.gz |
lib/tsocket: add tdgram_inet_udp_broadcast_socket()
This is similar to tdgram_inet_udp_socket(), but it allows
the use of ipv4 broadcast traffic.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/tsocket')
-rw-r--r-- | lib/tsocket/tsocket.h | 29 | ||||
-rw-r--r-- | lib/tsocket/tsocket_bsd.c | 30 |
2 files changed, 59 insertions, 0 deletions
diff --git a/lib/tsocket/tsocket.h b/lib/tsocket/tsocket.h index 296c7c555ae..f52b7466dfb 100644 --- a/lib/tsocket/tsocket.h +++ b/lib/tsocket/tsocket.h @@ -705,6 +705,8 @@ bool tdgram_bsd_optimize_recvfrom(struct tdgram_context *dgram, * communication. The function will allocate the memory. * * @return 0 on success, -1 on error with errno set. + * + * @see tdgram_inet_udp_broadcast_socket() */ int tdgram_inet_udp_socket(const struct tsocket_address *local, const struct tsocket_address *remote, @@ -722,6 +724,33 @@ int _tdgram_inet_udp_socket(const struct tsocket_address *local, #ifdef DOXYGEN /** + * @brief Create a tdgram_context for a ipv4 UDP broadcast (and unicast) communication. + * + * @param[in] local An 'inet' (ipv4 only) tsocket_address for the local endpoint. + * + * @param[in] mem_ctx The talloc memory context to use. + * + * @param[in] dgram The tdgram_context pointer to setup the udp + * communication. The function will allocate the memory. + * + * @return 0 on success, -1 on error with errno set. + * + * @see tdgram_inet_udp_socket() + */ +int tdgram_inet_udp_broadcast_socket(const struct tsocket_address *local, + TALLOC_CTX *mem_ctx, + struct tdgram_context **dgram); +#else +int _tdgram_inet_udp_broadcast_socket(const struct tsocket_address *local, + TALLOC_CTX *mem_ctx, + struct tdgram_context **dgram, + const char *location); +#define tdgram_inet_udp_broadcast_socket(local, mem_ctx, dgram) \ + _tdgram_inet_udp_broadcast_socket(local, mem_ctx, dgram, __location__) +#endif + +#ifdef DOXYGEN +/** * @brief Create a tdgram_context for unix domain datagram communication. * * @param[in] local An 'unix' tsocket_address for the local endpoint. diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c index 9ddbc061b94..f1ece7595e0 100644 --- a/lib/tsocket/tsocket_bsd.c +++ b/lib/tsocket/tsocket_bsd.c @@ -1441,6 +1441,36 @@ int _tdgram_inet_udp_socket(const struct tsocket_address *local, return ret; } +int _tdgram_inet_udp_broadcast_socket(const struct tsocket_address *local, + TALLOC_CTX *mem_ctx, + struct tdgram_context **dgram, + const char *location) +{ + struct tsocket_address_bsd *lbsda = + talloc_get_type_abort(local->private_data, + struct tsocket_address_bsd); + int ret; + + switch (lbsda->u.sa.sa_family) { + case AF_INET: + break; +#ifdef HAVE_IPV6 + case AF_INET6: + /* only ipv4 */ + errno = EINVAL; + return -1; +#endif + default: + errno = EINVAL; + return -1; + } + + ret = tdgram_bsd_dgram_socket(local, NULL, true, + mem_ctx, dgram, location); + + return ret; +} + int _tdgram_unix_socket(const struct tsocket_address *local, const struct tsocket_address *remote, TALLOC_CTX *mem_ctx, |