]> git.sesse.net Git - vlc/blob - src/network/udp.c
src: fixed multicast reception on OS X when using the 10.7 SDK (close #6104)
[vlc] / src / network / udp.c
1 /*****************************************************************************
2  * udp.c:
3  *****************************************************************************
4  * Copyright (C) 2004-2006 VLC authors and VideoLAN
5  * Copyright © 2006-2007 Rémi Denis-Courmont
6  *
7  * $Id$
8  *
9  * Authors: Laurent Aimar <fenrir@videolan.org>
10  *          Rémi Denis-Courmont <rem # videolan.org>
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU Lesser General Public License as published by
14  * the Free Software Foundation; either version 2.1 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this program; if not, write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <vlc_common.h>
35
36 #include <errno.h>
37 #include <assert.h>
38
39 #include <vlc_network.h>
40
41 #ifdef WIN32
42 #   if defined(UNDER_CE)
43 #       undef IP_MULTICAST_TTL
44 #       define IP_MULTICAST_TTL 3
45 #       undef IP_ADD_MEMBERSHIP
46 #       define IP_ADD_MEMBERSHIP 5
47 #   endif
48 #   define EAFNOSUPPORT WSAEAFNOSUPPORT
49 #else
50 #   include <unistd.h>
51 #   ifdef HAVE_NET_IF_H
52 #       include <net/if.h>
53 #   endif
54 #endif
55
56 #ifdef HAVE_LINUX_DCCP_H
57 # include <linux/dccp.h>
58 # ifndef SOCK_DCCP /* provisional API */
59 #  define SOCK_DCCP 6
60 # endif
61 #endif
62
63 #ifndef SOL_IP
64 # define SOL_IP IPPROTO_IP
65 #endif
66 #ifndef SOL_IPV6
67 # define SOL_IPV6 IPPROTO_IPV6
68 #endif
69 #ifndef IPPROTO_IPV6
70 # define IPPROTO_IPV6 41 /* IANA */
71 #endif
72 #ifndef SOL_DCCP
73 # define SOL_DCCP IPPROTO_DCCP
74 #endif
75 #ifndef IPPROTO_DCCP
76 # define IPPROTO_DCCP 33 /* IANA */
77 #endif
78 #ifndef SOL_UDPLITE
79 # define SOL_UDPLITE IPPROTO_UDPLITE
80 #endif
81 #ifndef IPPROTO_UDPLITE
82 # define IPPROTO_UDPLITE 136 /* IANA */
83 #endif
84
85 #if defined (HAVE_NETINET_UDPLITE_H)
86 # include <netinet/udplite.h>
87 #elif defined (__linux__)
88 /* still missing from glibc 2.6 */
89 # define UDPLITE_SEND_CSCOV     10
90 # define UDPLITE_RECV_CSCOV     11
91 #endif
92
93 extern int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype,
94                        int i_protocol );
95
96 /* */
97 static int net_SetupDgramSocket( vlc_object_t *p_obj, int fd, const struct addrinfo *ptr )
98 {
99 #ifdef SO_REUSEPORT
100     setsockopt (fd, SOL_SOCKET, SO_REUSEPORT, &(int){ 1 }, sizeof (int));
101 #endif
102
103 #ifdef SO_RCVBUF
104     /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s)
105      * to avoid packet loss caused in case of scheduling hiccups */
106     setsockopt (fd, SOL_SOCKET, SO_RCVBUF,
107                 (void *)&(int){ 0x80000 }, sizeof (int));
108     setsockopt (fd, SOL_SOCKET, SO_SNDBUF,
109                 (void *)&(int){ 0x80000 }, sizeof (int));
110 #endif
111
112 #if defined (WIN32) || defined (UNDER_CE)
113     if (net_SockAddrIsMulticast (ptr->ai_addr, ptr->ai_addrlen)
114      && (sizeof (struct sockaddr_storage) >= ptr->ai_addrlen))
115     {
116         // This works for IPv4 too - don't worry!
117         struct sockaddr_in6 dumb =
118         {
119             .sin6_family = ptr->ai_addr->sa_family,
120             .sin6_port =  ((struct sockaddr_in *)(ptr->ai_addr))->sin_port
121         };
122
123         bind (fd, (struct sockaddr *)&dumb, ptr->ai_addrlen);
124     }
125     else
126 #endif
127     if (bind (fd, ptr->ai_addr, ptr->ai_addrlen))
128     {
129         msg_Err( p_obj, "socket bind error (%m)" );
130         net_Close (fd);
131         return -1;
132     }
133     return fd;
134 }
135
136 /* */
137 static int net_ListenSingle (vlc_object_t *obj, const char *host, int port,
138                              int protocol)
139 {
140     struct addrinfo hints, *res;
141
142     memset (&hints, 0, sizeof( hints ));
143     hints.ai_socktype = SOCK_DGRAM;
144     hints.ai_protocol = protocol;
145     hints.ai_flags = AI_PASSIVE;
146
147     if (host && !*host)
148         host = NULL;
149
150     msg_Dbg (obj, "net: opening %s datagram port %d",
151              host ? host : "any", port);
152
153     int val = vlc_getaddrinfo (obj, host, port, &hints, &res);
154     if (val)
155     {
156         msg_Err (obj, "Cannot resolve %s port %d : %s", host, port,
157                  gai_strerror (val));
158         return -1;
159     }
160
161     val = -1;
162
163     for (const struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
164     {
165         int fd = net_Socket (obj, ptr->ai_family, ptr->ai_socktype,
166                              ptr->ai_protocol);
167         if (fd == -1)
168         {
169             msg_Dbg (obj, "socket error: %m");
170             continue;
171         }
172
173 #ifdef IPV6_V6ONLY
174         /* Try dual-mode IPv6 if available. */
175         if (ptr->ai_family == AF_INET6)
176             setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, &(int){ 0 }, sizeof (int));
177 #endif
178         fd = net_SetupDgramSocket( obj, fd, ptr );
179         if( fd == -1 )
180             continue;
181
182         if (net_SockAddrIsMulticast (ptr->ai_addr, ptr->ai_addrlen)
183          && net_Subscribe (obj, fd, ptr->ai_addr, ptr->ai_addrlen))
184         {
185             net_Close (fd);
186             continue;
187         }
188
189         val = fd;
190         break;
191     }
192
193     freeaddrinfo (res);
194     return val;
195 }
196
197
198 static int net_SetMcastHopLimit( vlc_object_t *p_this,
199                                  int fd, int family, int hlim )
200 {
201     int proto, cmd;
202
203     /* There is some confusion in the world whether IP_MULTICAST_TTL
204      * takes a byte or an int as an argument.
205      * BSD seems to indicate byte so we are going with that and use
206      * int as a fallback to be safe */
207     switch( family )
208     {
209 #ifdef IP_MULTICAST_TTL
210         case AF_INET:
211             proto = SOL_IP;
212             cmd = IP_MULTICAST_TTL;
213             break;
214 #endif
215
216 #ifdef IPV6_MULTICAST_HOPS
217         case AF_INET6:
218             proto = SOL_IPV6;
219             cmd = IPV6_MULTICAST_HOPS;
220             break;
221 #endif
222
223         default:
224             errno = EAFNOSUPPORT;
225             msg_Warn( p_this, "%m" );
226             return VLC_EGENERIC;
227     }
228
229     if( setsockopt( fd, proto, cmd, &hlim, sizeof( hlim ) ) < 0 )
230     {
231         /* BSD compatibility */
232         unsigned char buf;
233
234         msg_Dbg( p_this, "cannot set hop limit (%d): %m", hlim );
235         buf = (unsigned char)(( hlim > 255 ) ? 255 : hlim);
236         if( setsockopt( fd, proto, cmd, &buf, sizeof( buf ) ) )
237         {
238             msg_Err( p_this, "cannot set hop limit (%d): %m", hlim );
239             return VLC_EGENERIC;
240         }
241     }
242
243     return VLC_SUCCESS;
244 }
245
246
247 static int net_SetMcastOut (vlc_object_t *p_this, int fd, int family,
248                             const char *iface)
249 {
250     int scope = if_nametoindex (iface);
251     if (scope == 0)
252     {
253         msg_Err (p_this, "invalid multicast interface: %s", iface);
254         return -1;
255     }
256
257     switch (family)
258     {
259 #ifdef IPV6_MULTICAST_IF
260         case AF_INET6:
261             if (setsockopt (fd, SOL_IPV6, IPV6_MULTICAST_IF,
262                             &scope, sizeof (scope) == 0))
263                 return 0;
264 #endif
265
266 #ifdef __linux__
267         case AF_INET:
268         {
269             struct ip_mreqn req = { .imr_ifindex = scope };
270             if (setsockopt (fd, SOL_IP, IP_MULTICAST_IF,
271                             &req, sizeof (req)) == 0)
272                 return 0;
273         }
274 #endif
275         default:
276             errno = EAFNOSUPPORT;
277     }
278     msg_Err (p_this, "cannot force multicast interface %s: %m", iface);
279     return -1;
280 }
281
282
283 static unsigned var_GetIfIndex (vlc_object_t *obj)
284 {
285     char *ifname = var_InheritString (obj, "miface");
286     if (ifname == NULL)
287         return 0;
288
289     unsigned ifindex = if_nametoindex (ifname);
290     if (ifindex == 0)
291         msg_Err (obj, "invalid multicast interface: %s", ifname);
292     free (ifname);
293     return ifindex;
294 }
295
296
297 /**
298  * IP-agnostic multicast join,
299  * with fallback to old APIs, and fallback from SSM to ASM.
300  */
301 static int
302 net_SourceSubscribe (vlc_object_t *obj, int fd,
303                      const struct sockaddr *src, socklen_t srclen,
304                      const struct sockaddr *grp, socklen_t grplen)
305 {
306 #ifdef MCAST_JOIN_SOURCE_GROUP
307     /* Agnostic SSM multicast join */
308     int level;
309     struct group_source_req gsr;
310
311     memset (&gsr, 0, sizeof (gsr));
312     gsr.gsr_interface = var_GetIfIndex (obj);
313
314     switch (grp->sa_family)
315     {
316 #ifdef AF_INET6
317         case AF_INET6:
318         {
319             const struct sockaddr_in6 *g6 = (const struct sockaddr_in6 *)grp;
320
321             level = SOL_IPV6;
322             assert (grplen >= sizeof (struct sockaddr_in6));
323             if (g6->sin6_scope_id != 0)
324                 gsr.gsr_interface = g6->sin6_scope_id;
325             break;
326         }
327 #endif
328         case AF_INET:
329             level = SOL_IP;
330             break;
331         default:
332             errno = EAFNOSUPPORT;
333             return -1;
334     }
335
336     assert (grplen <= sizeof (gsr.gsr_group));
337     memcpy (&gsr.gsr_source, src, srclen);
338     assert (srclen <= sizeof (gsr.gsr_source));
339     memcpy (&gsr.gsr_group,  grp, grplen);
340     if (setsockopt (fd, level, MCAST_JOIN_SOURCE_GROUP,
341                     &gsr, sizeof (gsr)) == 0)
342         return 0;
343
344 #else
345     if (src->sa_family != grp->sa_family)
346     {
347         errno = EAFNOSUPPORT;
348         return -1;
349     }
350
351     switch (grp->sa_family)
352     {
353 # ifdef IP_ADD_SOURCE_MEMBERSHIP
354         /* IPv4-specific API */
355         case AF_INET:
356         {
357             struct ip_mreq_source imr;
358
359             memset (&imr, 0, sizeof (imr));
360             assert (grplen >= sizeof (struct sockaddr_in));
361             imr.imr_multiaddr = ((const struct sockaddr_in *)grp)->sin_addr;
362             assert (srclen >= sizeof (struct sockaddr_in));
363             imr.imr_sourceaddr = ((const struct sockaddr_in *)src)->sin_addr;
364             if (setsockopt (fd, SOL_IP, IP_ADD_SOURCE_MEMBERSHIP,
365                             &imr, sizeof (imr)) == 0)
366                 return 0;
367             break;
368         }
369 # endif
370         default:
371             errno = EAFNOSUPPORT;
372     }
373
374 #endif
375     msg_Err (obj, "cannot join source multicast group: %m");
376     msg_Warn (obj, "trying ASM instead of SSM...");
377     return net_Subscribe (obj, fd, grp, grplen);
378 }
379
380
381 int net_Subscribe (vlc_object_t *obj, int fd,
382                    const struct sockaddr *grp, socklen_t grplen)
383 {
384 /* MCAST_JOIN_GROUP was introduced to OS X in v10.7, but it doesn't work,
385  * so ignore it to use the same code as on 10.5 or 10.6 */
386 #if defined (MCAST_JOIN_GROUP) && !defined (__APPLE__)
387     /* Agnostic SSM multicast join */
388     int level;
389     struct group_req gr;
390
391     memset (&gr, 0, sizeof (gr));
392     gr.gr_interface = var_GetIfIndex (obj);
393
394     switch (grp->sa_family)
395     {
396 #ifdef AF_INET6
397         case AF_INET6:
398         {
399             const struct sockaddr_in6 *g6 = (const struct sockaddr_in6 *)grp;
400
401             level = SOL_IPV6;
402             assert (grplen >= sizeof (struct sockaddr_in6));
403             if (g6->sin6_scope_id != 0)
404                 gr.gr_interface = g6->sin6_scope_id;
405             break;
406         }
407 #endif
408         case AF_INET:
409             level = SOL_IP;
410             break;
411         default:
412             errno = EAFNOSUPPORT;
413             return -1;
414     }
415
416     assert (grplen <= sizeof (gr.gr_group));
417     memcpy (&gr.gr_group, grp, grplen);
418     if (setsockopt (fd, level, MCAST_JOIN_GROUP, &gr, sizeof (gr)) == 0)
419         return 0;
420
421 #else
422     VLC_UNUSED( grplen );
423     switch (grp->sa_family)
424     {
425 # ifdef IPV6_JOIN_GROUP
426         case AF_INET6:
427         {
428             struct ipv6_mreq ipv6mr;
429             const struct sockaddr_in6 *g6 = (const struct sockaddr_in6 *)grp;
430
431             memset (&ipv6mr, 0, sizeof (ipv6mr));
432             assert (grplen >= sizeof (struct sockaddr_in6));
433             ipv6mr.ipv6mr_multiaddr = g6->sin6_addr;
434             ipv6mr.ipv6mr_interface = g6->sin6_scope_id;
435             if (!setsockopt (fd, SOL_IPV6, IPV6_JOIN_GROUP,
436                              &ipv6mr, sizeof (ipv6mr)))
437                 return 0;
438             break;
439         }
440 # endif
441 # ifdef IP_ADD_MEMBERSHIP
442         case AF_INET:
443         {
444             struct ip_mreq imr;
445
446             memset (&imr, 0, sizeof (imr));
447             assert (grplen >= sizeof (struct sockaddr_in));
448             imr.imr_multiaddr = ((const struct sockaddr_in *)grp)->sin_addr;
449             if (setsockopt (fd, SOL_IP, IP_ADD_MEMBERSHIP,
450                             &imr, sizeof (imr)) == 0)
451                 return 0;
452             break;
453         }
454 # endif
455         default:
456             errno = EAFNOSUPPORT;
457     }
458
459 #endif
460     msg_Err (obj, "cannot join multicast group: %m");
461     return -1;
462 }
463
464
465 static int net_SetDSCP( int fd, uint8_t dscp )
466 {
467     struct sockaddr_storage addr;
468     if( getsockname( fd, (struct sockaddr *)&addr, &(socklen_t){ sizeof (addr) }) )
469         return -1;
470
471     int level, cmd;
472
473     switch( addr.ss_family )
474     {
475 #ifdef IPV6_TCLASS
476         case AF_INET6:
477             level = SOL_IPV6;
478             cmd = IPV6_TCLASS;
479             break;
480 #endif
481
482         case AF_INET:
483             level = SOL_IP;
484             cmd = IP_TOS;
485             break;
486
487         default:
488 #ifdef ENOPROTOOPT
489             errno = ENOPROTOOPT;
490 #endif
491             return -1;
492     }
493
494     return setsockopt( fd, level, cmd, &(int){ dscp }, sizeof (int));
495 }
496
497 #undef net_ConnectDgram
498 /*****************************************************************************
499  * net_ConnectDgram:
500  *****************************************************************************
501  * Open a datagram socket to send data to a defined destination, with an
502  * optional hop limit.
503  *****************************************************************************/
504 int net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
505                       int i_hlim, int proto )
506 {
507     struct addrinfo hints, *res, *ptr;
508     int             i_val, i_handle = -1;
509     bool      b_unreach = false;
510
511     if( i_hlim < 0 )
512         i_hlim = var_InheritInteger( p_this, "ttl" );
513
514     memset( &hints, 0, sizeof( hints ) );
515     hints.ai_socktype = SOCK_DGRAM;
516     hints.ai_protocol = proto;
517
518     msg_Dbg( p_this, "net: connecting to [%s]:%d", psz_host, i_port );
519
520     i_val = vlc_getaddrinfo( p_this, psz_host, i_port, &hints, &res );
521     if( i_val )
522     {
523         msg_Err( p_this, "cannot resolve [%s]:%d : %s", psz_host, i_port,
524                  gai_strerror( i_val ) );
525         return -1;
526     }
527
528     for( ptr = res; ptr != NULL; ptr = ptr->ai_next )
529     {
530         char *str;
531         int fd = net_Socket (p_this, ptr->ai_family, ptr->ai_socktype,
532                              ptr->ai_protocol);
533         if (fd == -1)
534             continue;
535
536         /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s)
537         * to avoid packet loss caused by scheduling problems */
538         setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &(int){ 0x80000 }, sizeof (int));
539         setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &(int){ 0x80000 }, sizeof (int));
540
541         /* Allow broadcast sending */
542         setsockopt (fd, SOL_SOCKET, SO_BROADCAST, &(int){ 1 }, sizeof (int));
543
544         if( i_hlim >= 0 )
545             net_SetMcastHopLimit( p_this, fd, ptr->ai_family, i_hlim );
546
547         str = var_InheritString (p_this, "miface");
548         if (str != NULL)
549         {
550             net_SetMcastOut (p_this, fd, ptr->ai_family, str);
551             free (str);
552         }
553
554         net_SetDSCP (fd, var_InheritInteger (p_this, "dscp"));
555
556         if( connect( fd, ptr->ai_addr, ptr->ai_addrlen ) == 0 )
557         {
558             /* success */
559             i_handle = fd;
560             break;
561         }
562
563 #if defined( WIN32 ) || defined( UNDER_CE )
564         if( WSAGetLastError () == WSAENETUNREACH )
565 #else
566         if( errno == ENETUNREACH )
567 #endif
568             b_unreach = true;
569         else
570         {
571             msg_Warn( p_this, "%s port %d : %m", psz_host, i_port);
572             net_Close( fd );
573             continue;
574         }
575     }
576
577     freeaddrinfo( res );
578
579     if( i_handle == -1 )
580     {
581         if( b_unreach )
582             msg_Err( p_this, "Host %s port %d is unreachable", psz_host,
583                      i_port );
584         return -1;
585     }
586
587     return i_handle;
588 }
589
590 #undef net_OpenDgram
591 /*****************************************************************************
592  * net_OpenDgram:
593  *****************************************************************************
594  * OpenDgram a datagram socket and return a handle
595  *****************************************************************************/
596 int net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
597                    const char *psz_server, int i_server, int protocol )
598 {
599     if ((psz_server == NULL) || (psz_server[0] == '\0'))
600         return net_ListenSingle (obj, psz_bind, i_bind, protocol);
601
602     msg_Dbg (obj, "net: connecting to [%s]:%d from [%s]:%d",
603              psz_server, i_server, psz_bind, i_bind);
604
605     struct addrinfo hints, *loc, *rem;
606     int val;
607
608     memset (&hints, 0, sizeof (hints));
609     hints.ai_socktype = SOCK_DGRAM;
610     hints.ai_protocol = protocol;
611
612     val = vlc_getaddrinfo (obj, psz_server, i_server, &hints, &rem);
613     if (val)
614     {
615         msg_Err (obj, "cannot resolve %s port %d : %s", psz_bind, i_bind,
616                  gai_strerror (val));
617         return -1;
618     }
619
620     hints.ai_flags = AI_PASSIVE;
621     val = vlc_getaddrinfo (obj, psz_bind, i_bind, &hints, &loc);
622     if (val)
623     {
624         msg_Err (obj, "cannot resolve %s port %d : %s", psz_bind, i_bind,
625                  gai_strerror (val));
626         freeaddrinfo (rem);
627         return -1;
628     }
629
630     val = -1;
631     for (struct addrinfo *ptr = loc; ptr != NULL; ptr = ptr->ai_next)
632     {
633         int fd = net_Socket (obj, ptr->ai_family, ptr->ai_socktype,
634                              ptr->ai_protocol);
635         if (fd == -1)
636             continue; // usually, address family not supported
637
638         fd = net_SetupDgramSocket( obj, fd, ptr );
639         if( fd == -1 )
640             continue;
641
642         for (struct addrinfo *ptr2 = rem; ptr2 != NULL; ptr2 = ptr2->ai_next)
643         {
644             if ((ptr2->ai_family != ptr->ai_family)
645              || (ptr2->ai_socktype != ptr->ai_socktype)
646              || (ptr2->ai_protocol != ptr->ai_protocol))
647                 continue;
648
649             if (net_SockAddrIsMulticast (ptr->ai_addr, ptr->ai_addrlen)
650               ? net_SourceSubscribe (obj, fd,
651                                      ptr2->ai_addr, ptr2->ai_addrlen,
652                                      ptr->ai_addr, ptr->ai_addrlen)
653               : connect (fd, ptr2->ai_addr, ptr2->ai_addrlen))
654             {
655                 msg_Err (obj, "cannot connect to %s port %d: %m",
656                          psz_server, i_server);
657                 continue;
658             }
659             val = fd;
660             break;
661         }
662
663         if (val != -1)
664             break;
665
666         net_Close (fd);
667     }
668
669     freeaddrinfo (rem);
670     freeaddrinfo (loc);
671     return val;
672 }
673
674
675 /**
676  * net_SetCSCov:
677  * Sets the send and receive checksum coverage of a socket:
678  * @param fd socket
679  * @param sendcov payload coverage of sent packets (bytes), -1 for full
680  * @param recvcov minimum payload coverage of received packets, -1 for full
681  */
682 int net_SetCSCov (int fd, int sendcov, int recvcov)
683 {
684     int type;
685
686     if (getsockopt (fd, SOL_SOCKET, SO_TYPE,
687                     &type, &(socklen_t){ sizeof (type) }))
688         return VLC_EGENERIC;
689
690     switch (type)
691     {
692 #ifdef UDPLITE_RECV_CSCOV
693         case SOCK_DGRAM: /* UDP-Lite */
694             if (sendcov == -1)
695                 sendcov = 0;
696             else
697                 sendcov += 8; /* partial */
698             if (setsockopt (fd, SOL_UDPLITE, UDPLITE_SEND_CSCOV, &sendcov,
699                             sizeof (sendcov)))
700                 return VLC_EGENERIC;
701
702             if (recvcov == -1)
703                 recvcov = 0;
704             else
705                 recvcov += 8;
706             if (setsockopt (fd, SOL_UDPLITE, UDPLITE_RECV_CSCOV,
707                             &recvcov, sizeof (recvcov)))
708                 return VLC_EGENERIC;
709
710             return VLC_SUCCESS;
711 #endif
712 #ifdef DCCP_SOCKOPT_SEND_CSCOV
713         case SOCK_DCCP: /* DCCP and its ill-named socket type */
714             if ((sendcov == -1) || (sendcov > 56))
715                 sendcov = 0;
716             else
717                 sendcov = (sendcov + 3) / 4;
718             if (setsockopt (fd, SOL_DCCP, DCCP_SOCKOPT_SEND_CSCOV,
719                             &sendcov, sizeof (sendcov)))
720                 return VLC_EGENERIC;
721
722             if ((recvcov == -1) || (recvcov > 56))
723                 recvcov = 0;
724             else
725                 recvcov = (recvcov + 3) / 4;
726             if (setsockopt (fd, SOL_DCCP, DCCP_SOCKOPT_RECV_CSCOV,
727                             &recvcov, sizeof (recvcov)))
728                 return VLC_EGENERIC;
729
730             return VLC_SUCCESS;
731 #endif
732     }
733 #if !defined( UDPLITE_RECV_CSCOV ) && !defined( DCCP_SOCKOPT_SEND_CSCOV )
734     VLC_UNUSED(sendcov);
735     VLC_UNUSED(recvcov);
736 #endif
737
738     return VLC_EGENERIC;
739 }