[vlc-commits] [Git][videolan/vlc][3.0.x] sap: use union to avoid one bad and two ugly casts
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed Sep 2 09:29:30 UTC 2026
Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC
Commits:
d20eef97 by Rémi Denis-Courmont at 2026-09-02T09:22:49+00:00
sap: use union to avoid one bad and two ugly casts
(cherry picked from commit b9413a68a6a80e20128eb93302cb2a2dc3be477d)
fix #30082
- - - - -
1 changed file:
- src/stream_output/sap.c
Changes:
=====================================
src/stream_output/sap.c
=====================================
@@ -63,7 +63,11 @@ typedef struct sap_address_t
vlc_cond_t wait;
char group[NI_MAXNUMERICHOST];
- struct sockaddr_storage orig;
+ union {
+ struct sockaddr a;
+ struct sockaddr_in in;
+ struct sockaddr_in6 in6;
+ } orig;
socklen_t origlen;
int fd;
unsigned interval;
@@ -97,7 +101,7 @@ static sap_address_t *AddressCreate (vlc_object_t *obj, const char *group)
strlcpy (addr->group, group, sizeof (addr->group));
addr->fd = fd;
addr->origlen = sizeof (addr->orig);
- getsockname (fd, (struct sockaddr *)&addr->orig, &addr->origlen);
+ getsockname(fd, &addr->orig.a, &addr->origlen);
addr->interval = var_CreateGetInteger (obj, "sap-interval");
vlc_mutex_init (&addr->lock);
@@ -312,29 +316,27 @@ sout_AnnounceRegisterSDP (vlc_object_t *obj, const char *sdp,
/* SAPv1, not encrypted, not compressed */
uint8_t flags = 0x20;
#ifdef AF_INET6
- if (sap_addr->orig.ss_family == AF_INET6)
+ if (sap_addr->orig.a.sa_family == AF_INET6)
flags |= 0x10;
#endif
vlc_memstream_putc(&stream, flags);
vlc_memstream_putc(&stream, 0x00); /* No authentication length */
vlc_memstream_write(&stream, &(uint16_t){ mdate() }, 2); /* ID hash */
- switch (sap_addr->orig.ss_family)
+ switch (sap_addr->orig.a.sa_family)
{
#ifdef AF_INET6
case AF_INET6:
{
- const struct in6_addr *a6 =
- &((const struct sockaddr_in6 *)&sap_addr->orig)->sin6_addr;
- vlc_memstream_write(&stream, &a6, 16);
+ const struct in6_addr *a6 = &sap_addr->orig.in6.sin6_addr;
+ vlc_memstream_write(&stream, a6, 16);
break;
}
#endif
case AF_INET:
{
- const struct in_addr *a4 =
- &((const struct sockaddr_in *)&sap_addr->orig)->sin_addr;
- vlc_memstream_write(&stream, &a4, 4);
+ const struct in_addr *a4 = &sap_addr->orig.in.sin_addr;
+ vlc_memstream_write(&stream, a4, 4);
break;
}
default:
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d20eef97302501f0a21aee9e2fa5bef7c867edf0
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d20eef97302501f0a21aee9e2fa5bef7c867edf0
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list