~ubuntu-branches/ubuntu/natty/vlc/natty

« back to all changes in this revision

Viewing changes to src/network/udp.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-06-25 01:09:16 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20100625010916-asxhep2mutg6g6pd
Tags: 1.1.0-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - build and install the libx264 plugin
  - add Xb-Npp header to vlc package
  - Add apport hook to include more vlc dependencies in bug reports
* Drop xulrunner patches.
* Drop 502_xulrunner_191.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Copyright (C) 2004-2006 the VideoLAN team
5
5
 * Copyright © 2006-2007 Rémi Denis-Courmont
6
6
 *
7
 
 * $Id: 2bbf4a127de2b557c5a4417fa142c1e34e300463 $
 
7
 * $Id: 3b2f5454670a1b5fb26bdfcfb3b9dde58341f702 $
8
8
 *
9
9
 * Authors: Laurent Aimar <fenrir@videolan.org>
10
10
 *          Rémi Denis-Courmont <rem # videolan.org>
35
35
 
36
36
#include <errno.h>
37
37
 
38
 
#ifdef HAVE_SYS_TIME_H
39
 
#    include <sys/time.h>
40
 
#endif
41
 
 
42
38
#include <vlc_network.h>
43
39
 
44
40
#ifdef WIN32
146
142
    memset (&hints, 0, sizeof( hints ));
147
143
    hints.ai_family = family;
148
144
    hints.ai_socktype = SOCK_DGRAM;
 
145
    hints.ai_protocol = protocol;
149
146
    hints.ai_flags = AI_PASSIVE;
150
147
 
151
148
    if (host && !*host)
164
161
 
165
162
    val = -1;
166
163
 
167
 
    int fd6 = -1;
168
164
    for (const struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
169
165
    {
170
166
        int fd = net_Socket (obj, ptr->ai_family, ptr->ai_socktype,
171
 
                             protocol ? protocol : ptr->ai_protocol);
 
167
                             ptr->ai_protocol);
172
168
        if (fd == -1)
173
169
        {
174
170
            msg_Dbg (obj, "socket error: %m");
184
180
            int on = (family == AF_INET6);
185
181
            setsockopt (fd, SOL_IPV6, IPV6_V6ONLY, &on, sizeof (on));
186
182
        }
187
 
        else if (ptr->ai_family == AF_INET && family == AF_UNSPEC)
188
 
        {
189
 
            for (const struct addrinfo *p = ptr; p != NULL; p = p->ai_next)
190
 
                if (p->ai_family == AF_INET6)
191
 
                {
192
 
                    net_Close (fd);
193
 
                    fd = -1;
194
 
                    break;
195
 
                }
196
 
            if (fd == -1)
197
 
                continue;
198
 
        }
199
 
#else
 
183
        if (ptr->ai_family == AF_INET)
 
184
#endif
200
185
        if (family == AF_UNSPEC && ptr->ai_next != NULL)
201
186
        {
202
187
            msg_Warn (obj, "ambiguous network protocol specification");
203
188
            msg_Warn (obj, "please select IP version explicitly");
204
189
        }
205
 
#endif
206
190
 
207
191
        fd = net_SetupDgramSocket( obj, fd, ptr );
208
192
        if( fd == -1 )
260
244
        /* BSD compatibility */
261
245
        unsigned char buf;
262
246
 
 
247
        msg_Dbg( p_this, "cannot set hop limit (%d): %m", hlim );
263
248
        buf = (unsigned char)(( hlim > 255 ) ? 255 : hlim);
264
249
        if( setsockopt( fd, proto, cmd, &buf, sizeof( buf ) ) )
 
250
        {
 
251
            msg_Err( p_this, "cannot set hop limit (%d): %m", hlim );
265
252
            return VLC_EGENERIC;
 
253
        }
266
254
    }
267
255
 
268
256
    return VLC_SUCCESS;
646
634
    return setsockopt( fd, level, cmd, &(int){ dscp }, sizeof (int));
647
635
}
648
636
 
649
 
 
 
637
#undef net_ConnectDgram
650
638
/*****************************************************************************
651
 
 * __net_ConnectDgram:
 
639
 * net_ConnectDgram:
652
640
 *****************************************************************************
653
641
 * Open a datagram socket to send data to a defined destination, with an
654
642
 * optional hop limit.
655
643
 *****************************************************************************/
656
 
int __net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
657
 
                        int i_hlim, int proto )
 
644
int net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
 
645
                      int i_hlim, int proto )
658
646
{
659
647
    struct addrinfo hints, *res, *ptr;
660
648
    int             i_val, i_handle = -1;
665
653
 
666
654
    memset( &hints, 0, sizeof( hints ) );
667
655
    hints.ai_socktype = SOCK_DGRAM;
 
656
    hints.ai_protocol = proto;
668
657
 
669
658
    msg_Dbg( p_this, "net: connecting to [%s]:%d", psz_host, i_port );
670
659
 
680
669
    {
681
670
        char *str;
682
671
        int fd = net_Socket (p_this, ptr->ai_family, ptr->ai_socktype,
683
 
                             proto ? proto : ptr->ai_protocol);
 
672
                             ptr->ai_protocol);
684
673
        if (fd == -1)
685
674
            continue;
686
675
 
747
736
    return i_handle;
748
737
}
749
738
 
750
 
 
 
739
#undef net_OpenDgram
751
740
/*****************************************************************************
752
 
 * __net_OpenDgram:
 
741
 * net_OpenDgram:
753
742
 *****************************************************************************
754
743
 * OpenDgram a datagram socket and return a handle
755
744
 *****************************************************************************/
756
 
int __net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
757
 
                     const char *psz_server, int i_server,
758
 
                     int family, int protocol )
 
745
int net_OpenDgram( vlc_object_t *obj, const char *psz_bind, int i_bind,
 
746
                   const char *psz_server, int i_server,
 
747
                   int family, int protocol )
759
748
{
760
749
    if ((psz_server == NULL) || (psz_server[0] == '\0'))
761
750
        return net_ListenSingle (obj, psz_bind, i_bind, family, protocol);
769
758
    memset (&hints, 0, sizeof (hints));
770
759
    hints.ai_family = family;
771
760
    hints.ai_socktype = SOCK_DGRAM;
 
761
    hints.ai_protocol = protocol;
772
762
 
773
763
    val = vlc_getaddrinfo (obj, psz_server, i_server, &hints, &rem);
774
764
    if (val)
791
781
    for (struct addrinfo *ptr = loc; ptr != NULL; ptr = ptr->ai_next)
792
782
    {
793
783
        int fd = net_Socket (obj, ptr->ai_family, ptr->ai_socktype,
794
 
                             protocol ? protocol : ptr->ai_protocol);
 
784
                             ptr->ai_protocol);
795
785
        if (fd == -1)
796
786
            continue; // usually, address family not supported
797
787