Mercurial > mplayer.hg
annotate stream/udp.c @ 28106:4932a522100e
Replace informal GPL notes by standard GPL header.
author | diego |
---|---|
date | Sat, 13 Dec 2008 12:13:48 +0000 |
parents | ae5da477539e |
children | 9202b9245819 |
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 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
23 #include "config.h" |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
24 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
25 #include <stdlib.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
26 #include <string.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
27 #include <errno.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
28 #include <unistd.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
29 #include <stdlib.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
30 #include <sys/types.h> |
19464 | 31 #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
|
32 #include <ctype.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
33 |
27472
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
34 #ifndef HAVE_WINSOCK2_H |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
35 #include <netdb.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
36 #include <netinet/in.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
37 #include <sys/socket.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
38 #include <arpa/inet.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
39 #else |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
40 #include <winsock2.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
41 #include <ws2tcpip.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
42 #endif |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
43 |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
44 #include "mp_msg.h" |
27473
ae5da477539e
Move '#define closesocket close' preprocessor directive to a common place
diego
parents:
27472
diff
changeset
|
45 #include "network.h" |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
46 #include "url.h" |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
47 #include "udp.h" |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
48 |
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
|
49 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
|
50 |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
51 /* 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
|
52 int |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
53 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
|
54 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
55 int socket_server_fd, rxsockbufsz; |
19330 | 56 int err; |
57 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
|
58 fd_set set; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
59 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
|
60 struct ip_mreq mcast; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
61 struct timeval tv; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
62 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
|
63 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
|
64 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
65 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
|
66 "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
|
67 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
68 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
|
69 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
|
70 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
71 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
|
72 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
73 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
74 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
75 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
|
76 { |
27461
5a30f5bc23a0
Rename HAVE_WINSOCK preprocessor condition to HAVE_WINSOCK_H.
diego
parents:
27359
diff
changeset
|
77 #ifndef HAVE_WINSOCK2_H |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
78 hp = (struct hostent *) gethostbyname (url->hostname); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
79 if (!hp) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
80 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
81 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
|
82 "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
|
83 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
84 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
85 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
86 memcpy ((void *) &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
|
87 (void *) hp->h_addr_list[0], hp->h_length); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
88 #else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
89 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
|
90 #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
|
91 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
92 else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
93 { |
27461
5a30f5bc23a0
Rename HAVE_WINSOCK preprocessor condition to HAVE_WINSOCK_H.
diego
parents:
27359
diff
changeset
|
94 #ifndef HAVE_WINSOCK2_H |
27359
d788e177a35e
Rename some preprocessor directives from CONFIG_* to HAVE_* where appropriate;
diego
parents:
27341
diff
changeset
|
95 #ifdef HAVE_ATON |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
96 inet_aton (url->hostname, &server_address.sin_addr); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
97 #else |
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); |
27359
d788e177a35e
Rename some preprocessor directives from CONFIG_* to HAVE_* where appropriate;
diego
parents:
27341
diff
changeset
|
99 #endif /* HAVE_ATON */ |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
100 #else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
101 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
|
102 #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
|
103 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
104 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
|
105 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
|
106 |
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
|
107 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
|
108 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
|
109 |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
110 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
|
111 sizeof (server_address)) == -1) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
112 { |
27461
5a30f5bc23a0
Rename HAVE_WINSOCK preprocessor condition to HAVE_WINSOCK_H.
diego
parents:
27359
diff
changeset
|
113 #ifndef HAVE_WINSOCK2_H |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
114 if (errno != EINPROGRESS) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
115 #else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
116 if (WSAGetLastError () != WSAEINPROGRESS) |
27461
5a30f5bc23a0
Rename HAVE_WINSOCK preprocessor condition to HAVE_WINSOCK_H.
diego
parents:
27359
diff
changeset
|
117 #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
|
118 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
119 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
|
120 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
121 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
122 } |
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 |
27461
5a30f5bc23a0
Rename HAVE_WINSOCK preprocessor condition to HAVE_WINSOCK_H.
diego
parents:
27359
diff
changeset
|
125 #ifdef HAVE_WINSOCK2_H |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
126 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
|
127 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
128 hp = (struct hostent *) gethostbyname (url->hostname); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
129 if (!hp) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
130 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
131 mp_msg (MSGT_NETWORK, MSGL_ERR, |
24558 | 132 "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
|
133 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
134 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
135 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
136 memcpy ((void *) &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
|
137 (void *) hp->h_addr, hp->h_length); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
138 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
139 else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
140 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
141 unsigned int addr = inet_addr (url->hostname); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
142 memcpy ((void *) &server_address.sin_addr, (void *) &addr, sizeof (addr)); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
143 } |
27461
5a30f5bc23a0
Rename HAVE_WINSOCK preprocessor condition to HAVE_WINSOCK_H.
diego
parents:
27359
diff
changeset
|
144 #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
|
145 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
146 /* 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
|
147 rxsockbufsz = 240 * 1024; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
148 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
|
149 &rxsockbufsz, sizeof (rxsockbufsz))) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
150 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
151 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
|
152 "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
|
153 } |
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 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
|
156 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
157 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
|
158 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
|
159 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
160 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
|
161 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
|
162 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
163 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
|
164 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
165 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
166 } |
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 |
24026 | 169 tv.tv_sec = 1; /* 1 second timeout */ |
170 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
|
171 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
172 FD_ZERO (&set); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
173 FD_SET (socket_server_fd, &set); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
174 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
175 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
|
176 if (err < 0) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
177 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
178 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
|
179 "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
|
180 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
181 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
182 } |
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 if (err == 0) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
185 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
186 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
|
187 "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
|
188 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
189 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
190 } |
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 err_len = sizeof (err); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
193 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
|
194 if (err) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
195 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
196 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
|
197 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
198 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
199 } |
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 return socket_server_fd; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
202 } |