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