Mercurial > mplayer.hg
annotate stream/udp.c @ 36873:05efbb5ab47e
Add VOCTRL_GUISUPPORT.
The video output driver may support it depending on sub_vo.
author | ib |
---|---|
date | Sun, 02 Mar 2014 21:12:33 +0000 |
parents | 05916e37848e |
children |
rev | line source |
---|---|
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
1 /* |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
2 * network helpers for UDP connections (originally borrowed from rtp.c) |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
3 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
4 * Copyright (C) 2006 Benjamin Zores |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
5 * |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
6 * This file is part of MPlayer. |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
7 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
8 * MPlayer is free software; you can redistribute it and/or modify |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
11 * (at your option) any later version. |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
12 * |
26737
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
13 * MPlayer is distributed in the hope that it will be useful, |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
16 * GNU General Public License for more details. |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
17 * |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
19 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
a26e50cae389
Use standard license headers with standard formatting.
diego
parents:
24558
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
21 */ |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
22 |
35907
05916e37848e
Add _BSD_SOURCE #define for struct hostent and struct ip_mreq.
diego
parents:
35249
diff
changeset
|
23 #define _BSD_SOURCE |
05916e37848e
Add _BSD_SOURCE #define for struct hostent and struct ip_mreq.
diego
parents:
35249
diff
changeset
|
24 |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
25 #include "config.h" |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
26 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
27 #include <stdlib.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
28 #include <string.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
29 #include <errno.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
30 #include <unistd.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
31 #include <stdlib.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
32 #include <sys/types.h> |
19464 | 33 #include <sys/time.h> |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
34 #include <ctype.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
35 |
28402 | 36 #if !HAVE_WINSOCK2_H |
27472
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
37 #include <netdb.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
38 #include <netinet/in.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
39 #include <sys/socket.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
40 #include <arpa/inet.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
41 #else |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
42 #include <winsock2.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
43 #include <ws2tcpip.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
44 #endif |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
45 |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
46 #include "mp_msg.h" |
27473
ae5da477539e
Move '#define closesocket close' preprocessor directive to a common place
diego
parents:
27472
diff
changeset
|
47 #include "network.h" |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
48 #include "url.h" |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
49 #include "udp.h" |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
50 |
22473
011d1adc0133
optionally reuse the socket if -reuse-socket is selected; patch by Yong Hwan (sio4 users sf net) simplified by me
nicodvb
parents:
19544
diff
changeset
|
51 int reuse_socket=0; |
011d1adc0133
optionally reuse the socket if -reuse-socket is selected; patch by Yong Hwan (sio4 users sf net) simplified by me
nicodvb
parents:
19544
diff
changeset
|
52 |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
53 /* Start listening on a UDP port. If multicast, join the group. */ |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
54 int |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
55 udp_open_socket (URL_t *url) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
56 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
57 int socket_server_fd, rxsockbufsz; |
19330 | 58 int err; |
59 socklen_t err_len; | |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
60 fd_set set; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
61 struct sockaddr_in server_address; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
62 struct ip_mreq mcast; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
63 struct timeval tv; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
64 struct hostent *hp; |
22473
011d1adc0133
optionally reuse the socket if -reuse-socket is selected; patch by Yong Hwan (sio4 users sf net) simplified by me
nicodvb
parents:
19544
diff
changeset
|
65 int reuse=reuse_socket; |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
66 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
67 mp_msg (MSGT_NETWORK, MSGL_V, |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
68 "Listening for traffic on %s:%d ...\n", url->hostname, url->port); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
69 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
70 socket_server_fd = socket (AF_INET, SOCK_DGRAM, 0); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
71 if (socket_server_fd == -1) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
72 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
73 mp_msg (MSGT_NETWORK, MSGL_ERR, "Failed to create socket\n"); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
74 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
75 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
76 |
28697
5b749a93fc89
Use memset to make sure all parts of struct sockaddr_in are always initialized.
reimar
parents:
28404
diff
changeset
|
77 memset(&server_address, 0, sizeof(server_address)); |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
78 if (isalpha (url->hostname[0])) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
79 { |
28402 | 80 #if !HAVE_WINSOCK2_H |
35249 | 81 hp = gethostbyname (url->hostname); |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
82 if (!hp) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
83 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
84 mp_msg (MSGT_NETWORK, MSGL_ERR, |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
85 "Counldn't resolve name: %s\n", url->hostname); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
86 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
87 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
88 } |
35249 | 89 memcpy (&server_address.sin_addr.s_addr, |
90 hp->h_addr_list[0], hp->h_length); | |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
91 #else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
92 server_address.sin_addr.s_addr = htonl (INADDR_ANY); |
27461
5a30f5bc23a0
Rename HAVE_WINSOCK preprocessor condition to HAVE_WINSOCK_H.
diego
parents:
27359
diff
changeset
|
93 #endif /* HAVE_WINSOCK2_H */ |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
94 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
95 else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
96 { |
28404
613f075b4ef0
Restructure network tests: Always check for both inet_aton and inet_pton.
diego
parents:
28402
diff
changeset
|
97 #if HAVE_INET_PTON |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
98 inet_pton (AF_INET, url->hostname, &server_address.sin_addr); |
28404
613f075b4ef0
Restructure network tests: Always check for both inet_aton and inet_pton.
diego
parents:
28402
diff
changeset
|
99 #elif HAVE_INET_ATON |
613f075b4ef0
Restructure network tests: Always check for both inet_aton and inet_pton.
diego
parents:
28402
diff
changeset
|
100 inet_aton (url->hostname, &server_address.sin_addr); |
613f075b4ef0
Restructure network tests: Always check for both inet_aton and inet_pton.
diego
parents:
28402
diff
changeset
|
101 #elif !HAVE_WINSOCK2_H |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
102 server_address.sin_addr.s_addr = htonl(INADDR_ANY); |
28404
613f075b4ef0
Restructure network tests: Always check for both inet_aton and inet_pton.
diego
parents:
28402
diff
changeset
|
103 #endif |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
104 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
105 server_address.sin_family = AF_INET; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
106 server_address.sin_port = htons (url->port); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
107 |
22473
011d1adc0133
optionally reuse the socket if -reuse-socket is selected; patch by Yong Hwan (sio4 users sf net) simplified by me
nicodvb
parents:
19544
diff
changeset
|
108 if(reuse_socket && setsockopt(socket_server_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse))) |
011d1adc0133
optionally reuse the socket if -reuse-socket is selected; patch by Yong Hwan (sio4 users sf net) simplified by me
nicodvb
parents:
19544
diff
changeset
|
109 mp_msg(MSGT_NETWORK, MSGL_ERR, "SO_REUSEADDR failed! ignore.\n"); |
011d1adc0133
optionally reuse the socket if -reuse-socket is selected; patch by Yong Hwan (sio4 users sf net) simplified by me
nicodvb
parents:
19544
diff
changeset
|
110 |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
111 if (bind (socket_server_fd, (struct sockaddr *) &server_address, |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
112 sizeof (server_address)) == -1) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
113 { |
28402 | 114 #if !HAVE_WINSOCK2_H |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
115 if (errno != EINPROGRESS) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
116 #else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
117 if (WSAGetLastError () != WSAEINPROGRESS) |
27461
5a30f5bc23a0
Rename HAVE_WINSOCK preprocessor condition to HAVE_WINSOCK_H.
diego
parents:
27359
diff
changeset
|
118 #endif /* HAVE_WINSOCK2_H */ |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
119 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
120 mp_msg (MSGT_NETWORK, MSGL_ERR, "Failed to connect to server\n"); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
121 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
122 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
123 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
124 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28697
diff
changeset
|
125 |
28402 | 126 #if HAVE_WINSOCK2_H |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
127 if (isalpha (url->hostname[0])) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
128 { |
35249 | 129 hp = gethostbyname (url->hostname); |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
130 if (!hp) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
131 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
132 mp_msg (MSGT_NETWORK, MSGL_ERR, |
24558 | 133 "Could not resolve name: %s\n", url->hostname); |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
134 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
135 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
136 } |
35249 | 137 memcpy (&server_address.sin_addr.s_addr, |
138 hp->h_addr, hp->h_length); | |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
139 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
140 else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
141 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
142 unsigned int addr = inet_addr (url->hostname); |
35249 | 143 memcpy (&server_address.sin_addr, &addr, sizeof (addr)); |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
144 } |
27461
5a30f5bc23a0
Rename HAVE_WINSOCK preprocessor condition to HAVE_WINSOCK_H.
diego
parents:
27359
diff
changeset
|
145 #endif /* HAVE_WINSOCK2_H */ |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
146 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
147 /* Increase the socket rx buffer size to maximum -- this is UDP */ |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
148 rxsockbufsz = 240 * 1024; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
149 if (setsockopt (socket_server_fd, SOL_SOCKET, SO_RCVBUF, |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
150 &rxsockbufsz, sizeof (rxsockbufsz))) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
151 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
152 mp_msg (MSGT_NETWORK, MSGL_ERR, |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
153 "Couldn't set receive socket buffer size\n"); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
154 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
155 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
156 if ((ntohl (server_address.sin_addr.s_addr) >> 28) == 0xe) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
157 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
158 mcast.imr_multiaddr.s_addr = server_address.sin_addr.s_addr; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
159 mcast.imr_interface.s_addr = 0; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
160 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
161 if (setsockopt (socket_server_fd, IPPROTO_IP, |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
162 IP_ADD_MEMBERSHIP, &mcast, sizeof (mcast))) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
163 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
164 mp_msg (MSGT_NETWORK, MSGL_ERR, "IP_ADD_MEMBERSHIP failed (do you have multicasting enabled in your kernel?)\n"); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
165 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
166 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
167 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
168 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
169 |
24026 | 170 tv.tv_sec = 1; /* 1 second timeout */ |
171 tv.tv_usec = 0; | |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
172 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
173 FD_ZERO (&set); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
174 FD_SET (socket_server_fd, &set); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28697
diff
changeset
|
175 |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
176 err = select (socket_server_fd + 1, &set, NULL, NULL, &tv); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
177 if (err < 0) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
178 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
179 mp_msg (MSGT_NETWORK, MSGL_FATAL, |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
180 "Select failed: %s\n", strerror (errno)); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
181 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
182 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
183 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
184 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
185 if (err == 0) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
186 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
187 mp_msg (MSGT_NETWORK, MSGL_ERR, |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
188 "Timeout! No data from host %s\n", url->hostname); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
189 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
190 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
191 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
192 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
193 err_len = sizeof (err); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
194 getsockopt (socket_server_fd, SOL_SOCKET, SO_ERROR, &err, &err_len); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
195 if (err) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
196 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
197 mp_msg (MSGT_NETWORK, MSGL_DBG2, "Socket error: %d\n", err); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
198 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
199 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
200 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
201 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
202 return socket_server_fd; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
203 } |