X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fstream_output%2Fsap.c;h=40e03e8bd603dac78c6bfc140c4d4c3a6f6f303d;hb=021bda3e79ed68f105180730223a86ee4e97ff32;hp=e3c9d19f0caa657942089245862fdd1a5b41230e;hpb=5574f54de8a088481ff209b7b87bccad4122f190;p=vlc diff --git a/src/stream_output/sap.c b/src/stream_output/sap.c index e3c9d19f0c..40e03e8bd6 100644 --- a/src/stream_output/sap.c +++ b/src/stream_output/sap.c @@ -35,7 +35,6 @@ #include /* free() */ #include /* sprintf() */ #include -#include /* tolower(), isxdigit() */ #include #include @@ -53,7 +52,7 @@ typedef struct sap_session_t struct sap_session_t *next; const session_descriptor_t *p_sd; size_t length; - uint8_t data[0]; + uint8_t data[]; } sap_session_t; /* A SAP announce address. For each of these, we run the @@ -214,7 +213,12 @@ int SAP_Add (sap_handler_t *p_sap, session_descriptor_t *p_session) bool b_ipv6 = false, b_ssm = false; sap_session_t *p_sap_session; mtime_t i_hash; - struct sockaddr_storage addr; + union + { + struct sockaddr a; + struct sockaddr_in in; + struct sockaddr_in6 in6; + } addr; socklen_t addrlen; addrlen = p_session->addrlen; @@ -227,13 +231,13 @@ int SAP_Add (sap_handler_t *p_sap, session_descriptor_t *p_session) /* Determine SAP multicast address automatically */ memcpy (&addr, &p_session->addr, addrlen); - switch( p_session->addr.ss_family ) + switch (addr.a.sa_family) { #if defined (HAVE_INET_PTON) || defined (WIN32) case AF_INET6: { /* See RFC3513 for list of valid IPv6 scopes */ - struct in6_addr *a6 = &((struct sockaddr_in6 *)&addr)->sin6_addr; + struct in6_addr *a6 = &addr.in6.sin6_addr; memcpy( a6->s6_addr + 2, "\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x02\x7f\xfe", 14 ); @@ -257,29 +261,28 @@ int SAP_Add (sap_handler_t *p_sap, session_descriptor_t *p_session) case AF_INET: { /* See RFC2365 for IPv4 scopes */ - uint32_t ipv4; + uint32_t ipv4 = addr.in.sin_addr.s_addr; - ipv4 = ntohl( ((struct sockaddr_in *)&addr)->sin_addr.s_addr ); /* 224.0.0.0/24 => 224.0.0.255 */ - if ((ipv4 & 0xffffff00) == 0xe0000000) - ipv4 = 0xe00000ff; + if ((ipv4 & htonl (0xffffff00)) == htonl (0xe0000000)) + ipv4 = htonl (0xe00000ff); else /* 239.255.0.0/16 => 239.255.255.255 */ - if ((ipv4 & 0xffff0000) == 0xefff0000) - ipv4 = 0xefffffff; + if ((ipv4 & htonl (0xffff0000)) == htonl (0xefff0000)) + ipv4 = htonl (0xefffffff); else /* 239.192.0.0/14 => 239.195.255.255 */ - if ((ipv4 & 0xfffc0000) == 0xefc00000) - ipv4 = 0xefc3ffff; + if ((ipv4 & htonl (0xfffc0000)) == htonl (0xefc00000)) + ipv4 = htonl (0xefc3ffff); else - if ((ipv4 & 0xff000000) == 0xef000000) + if ((ipv4 & htonl (0xff000000)) == htonl (0xef000000)) ipv4 = 0; else /* other addresses => 224.2.127.254 */ { /* SSM: 232.0.0.0/8 */ - b_ssm = (ipv4 >> 24) == 232; - ipv4 = 0xe0027ffe; + b_ssm = (ipv4 & htonl (255 << 24)) == htonl (232 << 24); + ipv4 = htonl (0xe0027ffe); } if( ipv4 == 0 ) @@ -289,22 +292,22 @@ int SAP_Add (sap_handler_t *p_sap, session_descriptor_t *p_session) return VLC_EGENERIC; } - ((struct sockaddr_in *)&addr)->sin_addr.s_addr = htonl( ipv4 ); + addr.in.sin_addr.s_addr = ipv4; break; } default: msg_Err( p_sap, "Address family %d not supported by SAP", - addr.ss_family ); + addr.a.sa_family ); return VLC_EGENERIC; } - i = vlc_getnameinfo( (struct sockaddr *)&addr, addrlen, + i = vlc_getnameinfo( &addr.a, addrlen, psz_addr, sizeof( psz_addr ), NULL, NI_NUMERICHOST ); if( i ) { - msg_Err( p_sap, "%s", vlc_gai_strerror( i ) ); + msg_Err( p_sap, "%s", gai_strerror( i ) ); return VLC_EGENERIC; } @@ -369,7 +372,7 @@ int SAP_Add (sap_handler_t *p_sap, session_descriptor_t *p_session) /* SAPv1, not encrypted, not compressed */ psz_head[0] = 0x20; - psz_head[1] = 0x00; /* No authentification length */ + psz_head[1] = 0x00; /* No authentication length */ i_hash = mdate(); psz_head[2] = i_hash >> 8; /* Msg id hash */