aboutsummaryrefslogtreecommitdiff
path: root/src/platform/posix/posix_udp.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-21 19:00:33 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-21 19:22:07 -0800
commitd571d3f03bf56be2a5828fe2db86308229dc5625 (patch)
treea04ec11ee3c5d28a061fae2151669ad17e46915a /src/platform/posix/posix_udp.c
parentebc020cd4f8e2121d6ecc2dfc0cd48c594329cde (diff)
downloadnng-d571d3f03bf56be2a5828fe2db86308229dc5625.tar.gz
nng-d571d3f03bf56be2a5828fe2db86308229dc5625.tar.bz2
nng-d571d3f03bf56be2a5828fe2db86308229dc5625.zip
posix udp: More explicit checks for bogus address family
This triggered an error on FreeBSD because apparently FreeBSD will return a different value when seeing an AF_UNIX socket with UDP.
Diffstat (limited to 'src/platform/posix/posix_udp.c')
-rw-r--r--src/platform/posix/posix_udp.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/platform/posix/posix_udp.c b/src/platform/posix/posix_udp.c
index 1e2f6df9..667fbaec 100644
--- a/src/platform/posix/posix_udp.c
+++ b/src/platform/posix/posix_udp.c
@@ -215,9 +215,18 @@ nni_plat_udp_open(nni_plat_udp **upp, nni_sockaddr *bindaddr)
struct sockaddr_storage sa;
int rv;
- if ((salen = nni_posix_nn2sockaddr(&sa, bindaddr)) < 1) {
+ if (bindaddr == NULL) {
return (NNG_EADDRINVAL);
}
+ switch (bindaddr->s_family) {
+ case NNG_AF_INET:
+ case NNG_AF_INET6:
+ break;
+ default:
+ return (NNG_EADDRINVAL);
+ }
+ salen = nni_posix_nn2sockaddr(&sa, bindaddr);
+ NNI_ASSERT(salen > 1);
// UDP opens can actually run synchronously.
if ((udp = NNI_ALLOC_STRUCT(udp)) == NULL) {