]> git.sesse.net Git - vlc/blob - src/network/udp.c
d58910da379e633c98d76607781cff87a6272997
[vlc] / src / network / udp.c
1 /*****************************************************************************
2  * udp.c:
3  *****************************************************************************
4  * Copyright (C) 2004-2006 the VideoLAN team
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
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 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 General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, 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 #ifdef MCAST_JOIN_GROUP
385     /* Agnostic SSM multicast join */
386     int level;
387     struct group_req gr;
388
389     memset (&gr, 0, sizeof (gr));
390     gr.gr_interface = var_GetIfIndex (obj);
391
392     switch (grp->sa_family)
393     {
394 #ifdef AF_INET6
395         case AF_INET6:
396         {
397             const struct sockaddr_in6 *g6 = (const struct sockaddr_in6 *)grp;
398
399             level = SOL_IPV6;
400             assert (grplen >= sizeof (struct sockaddr_in6));
401             if (g6->sin6_scope_id != 0)
402                 gr.gr_interface = g6->sin6_scope_id;
403             break;
404         }
405 #endif
406         case AF_INET:
407             level = SOL_IP;
408             break;
409         default:
410             errno = EAFNOSUPPORT;
411             return -1;
412     }
413
414     assert (grplen <= sizeof (gr.gr_group));
415     memcpy (&gr.gr_group, grp, grplen);
416     if (setsockopt (fd, level, MCAST_JOIN_GROUP, &gr, sizeof (gr)) == 0)
417         return 0;
418
419 #else
420     switch (grp->sa_family)
421     {
422 # ifdef IPV6_JOIN_GROUP
423         case AF_INET6:
424         {
425             struct ipv6_mreq ipv6mr;
426             const struct sockaddr_in6 *g6 = (const struct sockaddr_in6 *)grp;
427
428             memset (&ipv6mr, 0, sizeof (ipv6mr));
429             assert (grplen >= sizeof (struct sockaddr_in6));
430             ipv6mr.ipv6mr_multiaddr = g6->sin6_addr;
431             ipv6mr.ipv6mr_interface = g6->sin6_scope_id;
432             if (!setsockopt (fd, SOL_IPV6, IPV6_JOIN_GROUP,
433                              &ipv6mr, sizeof (ipv6mr)))
434                 return 0;
435             break;
436         }
437 # endif
438 # ifdef IP_ADD_MEMBERSHIP
439         case AF_INET:
440         {
441             struct ip_mreq imr;
442
443             memset (&imr, 0, sizeof (imr));
444             assert (grplen >= sizeof (struct sockaddr_in));
445             imr.imr_multiaddr = ((const struct sockaddr_in *)grp)->sin_addr;
446             if (setsockopt (fd, SOL_IP, IP_ADD_MEMBERSHIP,
447                             &imr, sizeof (imr)) == 0)
448                 return 0;
449             break;
450         }
451 # endif
452         default:
453             errno = EAFNOSUPPORT;
454     }
455
456 #endif
457     msg_Err (obj, "cannot join multicast group: %m");
458     return -1;
459 }
460
461
462 static int net_SetDSCP( int fd, uint8_t dscp )
463 {
464     struct sockaddr_storage addr;
465     if( getsockname( fd, (struct sockaddr *)&addr, &(socklen_t){ sizeof (addr) }) )
466         return -1;
467
468     int level, cmd;
469
470     switch( addr.ss_family )
471     {
472 #ifdef IPV6_TCLASS
473         case AF_INET6:
474             level = SOL_IPV6;
475             cmd = IPV6_TCLASS;
476             break;
477 #endif
478
479         case AF_INET:
480             level = SOL_IP;
481             cmd = IP_TOS;
482             break;
483
484         default:
485 #ifdef ENOPROTOOPT
486             errno = ENOPROTOOPT;
487 #endif
488             return -1;
489     }
490
491     return setsockopt( fd, level, cmd, &(int){ dscp }, sizeof (int));
492 }
493
494 #undef net_ConnectDgram
495 /*****************************************************************************
496  * net_ConnectDgram:
497  *****************************************************************************
498  * Open a datagram socket to send data to a defined destination, with an
499  * optional hop limit.
500  *****************************************************************************/
501 int net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
502                       int i_hlim, int proto )
503 {
504     struct addrinfo hints, *res, *ptr;
505     int             i_val, i_handle = -1;
506     bool      b_unreach = false;
507
508     if( i_hlim < 0 )
509         i_hlim = var_InheritInteger( p_this, "ttl" );
510
511     memset( &hints, 0, sizeof( hints ) );
512     hints.ai_socktype = SOCK_DGRAM;
513     hints.ai_protocol = proto;
514
515     msg_Dbg( p_this, "net: connecting to [%s]:%d", psz_host, i_port );
516
517     i_val = vlc_getaddrinfo( p_this, psz_host, i_port, &hints, &res );
518     if( i_val )
519     {
520         msg_Err( p_this, "cannot resolve [%s]:%d : %s", psz_host, i_port,
521                  gai_strerror( i_val ) );
522         return -1;
523     }
524
525     for( ptr = res; ptr != NULL; ptr = ptr->ai_next )
526     {
527         char *str;
528         int fd = net_Socket (p_this, ptr->ai_family, ptr->ai_socktype,
529                              ptr->ai_protocol);
530         if (fd == -1)
531             continue;
532
533         /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s)
534         * to avoid packet loss caused by scheduling problems */
535         setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &(int){ 0x80000 }, sizeof (int));
536         setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &(int){ 0x80000 }, sizeof (int));
537
538         /* Allow broadcast sending */
539         setsockopt (fd, SOL_SOCKET, SO_BROADCAST, &(int){ 1 }, sizeof (int));
540
541         if( i_hlim >= 0 )
542             net_SetMcastHopLimit( p_this, fd, ptr->ai_family, i_hlim );
543
544         str = var_InheritString (p_this, "miface");
545         if (str != NULL)
546         {
547             net_SetMcastOut (p_this, fd, ptr->ai_family, str);
548             free (str);
549         }
550
551         net_SetDSCP (fd, var_InheritInteger (p_this, "dscp"));
552
553         if( connect( fd, ptr->ai_addr, ptr->ai_addrlen ) == 0 )
554         {
555             /* success */
556             i_handle = fd;
557             break;
558         }
559
560 #if defined( WIN32 ) || defined( UNDER_CE )
561         if( WSAGetLastError () == WSAENETUNREACH )
562 #else
563         if( errno == ENETUNREACH )
564 #endif
565             b_unreach = true;
566         else
567         {
568             msg_Warn( p_this, "%s port %d : %m", psz_host, i_port);
569             net_Close( fd );
570             continue;
571         }
572     }
573
574     freeaddrinfo( res );
575
576     if( i_handle == -1 )
577     {
578         if( b_unreach )
579             msg_Err( p_this, "Host %s port %d is unreachable", psz_host,
580                      i_port );
581         return -1;
582     }
583
584     return i_handle;
585 }
586
587 #undef net_OpenDgram
588 /*****************************************************************************
589  * net_OpenDgram:
590  *****************************************************************************
591  * OpenDgram a datagram socket and return a handle
592  *****************************************************************************/
593 int net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
594                    const char *psz_server, int i_server, int protocol )
595 {
596     if ((psz_server == NULL) || (psz_server[0] == '\0'))
597         return net_ListenSingle (obj, psz_bind, i_bind, protocol);
598
599     msg_Dbg (obj, "net: connecting to [%s]:%d from [%s]:%d",
600              psz_server, i_server, psz_bind, i_bind);
601
602     struct addrinfo hints, *loc, *rem;
603     int val;
604
605     memset (&hints, 0, sizeof (hints));
606     hints.ai_socktype = SOCK_DGRAM;
607     hints.ai_protocol = protocol;
608
609     val = vlc_getaddrinfo (obj, psz_server, i_server, &hints, &rem);
610     if (val)
611     {
612         msg_Err (obj, "cannot resolve %s port %d : %s", psz_bind, i_bind,
613                  gai_strerror (val));
614         return -1;
615     }
616
617     hints.ai_flags = AI_PASSIVE;
618     val = vlc_getaddrinfo (obj, psz_bind, i_bind, &hints, &loc);
619     if (val)
620     {
621         msg_Err (obj, "cannot resolve %s port %d : %s", psz_bind, i_bind,
622                  gai_strerror (val));
623         freeaddrinfo (rem);
624         return -1;
625     }
626
627     val = -1;
628     for (struct addrinfo *ptr = loc; ptr != NULL; ptr = ptr->ai_next)
629     {
630         int fd = net_Socket (obj, ptr->ai_family, ptr->ai_socktype,
631                              ptr->ai_protocol);
632         if (fd == -1)
633             continue; // usually, address family not supported
634
635         fd = net_SetupDgramSocket( obj, fd, ptr );
636         if( fd == -1 )
637             continue;
638
639         for (struct addrinfo *ptr2 = rem; ptr2 != NULL; ptr2 = ptr2->ai_next)
640         {
641             if ((ptr2->ai_family != ptr->ai_family)
642              || (ptr2->ai_socktype != ptr->ai_socktype)
643              || (ptr2->ai_protocol != ptr->ai_protocol))
644                 continue;
645
646             if (net_SockAddrIsMulticast (ptr->ai_addr, ptr->ai_addrlen)
647               ? net_SourceSubscribe (obj, fd,
648                                      ptr2->ai_addr, ptr2->ai_addrlen,
649                                      ptr->ai_addr, ptr->ai_addrlen)
650               : connect (fd, ptr2->ai_addr, ptr2->ai_addrlen))
651             {
652                 msg_Err (obj, "cannot connect to %s port %d: %m",
653                          psz_server, i_server);
654                 continue;
655             }
656             val = fd;
657             break;
658         }
659
660         if (val != -1)
661             break;
662
663         net_Close (fd);
664     }
665
666     freeaddrinfo (rem);
667     freeaddrinfo (loc);
668     return val;
669 }
670
671
672 /**
673  * net_SetCSCov:
674  * Sets the send and receive checksum coverage of a socket:
675  * @param fd socket
676  * @param sendcov payload coverage of sent packets (bytes), -1 for full
677  * @param recvcov minimum payload coverage of received packets, -1 for full
678  */
679 int net_SetCSCov (int fd, int sendcov, int recvcov)
680 {
681     int type;
682
683     if (getsockopt (fd, SOL_SOCKET, SO_TYPE,
684                     &type, &(socklen_t){ sizeof (type) }))
685         return VLC_EGENERIC;
686
687     switch (type)
688     {
689 #ifdef UDPLITE_RECV_CSCOV
690         case SOCK_DGRAM: /* UDP-Lite */
691             if (sendcov == -1)
692                 sendcov = 0;
693             else
694                 sendcov += 8; /* partial */
695             if (setsockopt (fd, SOL_UDPLITE, UDPLITE_SEND_CSCOV, &sendcov,
696                             sizeof (sendcov)))
697                 return VLC_EGENERIC;
698
699             if (recvcov == -1)
700                 recvcov = 0;
701             else
702                 recvcov += 8;
703             if (setsockopt (fd, SOL_UDPLITE, UDPLITE_RECV_CSCOV,
704                             &recvcov, sizeof (recvcov)))
705                 return VLC_EGENERIC;
706
707             return VLC_SUCCESS;
708 #endif
709 #ifdef DCCP_SOCKOPT_SEND_CSCOV
710         case SOCK_DCCP: /* DCCP and its ill-named socket type */
711             if ((sendcov == -1) || (sendcov > 56))
712                 sendcov = 0;
713             else
714                 sendcov = (sendcov + 3) / 4;
715             if (setsockopt (fd, SOL_DCCP, DCCP_SOCKOPT_SEND_CSCOV,
716                             &sendcov, sizeof (sendcov)))
717                 return VLC_EGENERIC;
718
719             if ((recvcov == -1) || (recvcov > 56))
720                 recvcov = 0;
721             else
722                 recvcov = (recvcov + 3) / 4;
723             if (setsockopt (fd, SOL_DCCP, DCCP_SOCKOPT_RECV_CSCOV,
724                             &recvcov, sizeof (recvcov)))
725                 return VLC_EGENERIC;
726
727             return VLC_SUCCESS;
728 #endif
729     }
730 #if !defined( UDPLITE_RECV_CSCOV ) && !defined( DCCP_SOCKOPT_SEND_CSCOV )
731     VLC_UNUSED(sendcov);
732     VLC_UNUSED(recvcov);
733 #endif
734
735     return VLC_EGENERIC;
736 }