Mercurial > mplayer.hg
annotate stream/udp.c @ 21653:04cea12cd324
Fix possible crashes with colorized mplayer output
author | reimar |
---|---|
date | Mon, 18 Dec 2006 18:50:46 +0000 |
parents | 32cfda1ff555 |
children | 011d1adc0133 |
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 /* |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
2 * Copyright (C) 2006 Benjamin Zores |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
3 * Network helpers for UDP connections (originally borrowed from rtp.c). |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
4 * |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
5 * This program is free software; you can redistribute it and/or modify |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
6 * it under the terms of the GNU General Public License as published by |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
7 * the Free Software Foundation; either version 2 of the License, or |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
8 * (at your option) any later version. |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
9 * |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
13 * GNU General Public License for more details. |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
14 * |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
16 * along with this program; if not, write to the Free Software Foundation, |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
18 */ |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
19 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
20 #include "config.h" |
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 #include <stdlib.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
23 #include <string.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
24 #include <errno.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
25 #include <unistd.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
26 #include <stdlib.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
27 #include <sys/types.h> |
19464 | 28 #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
|
29 #include <ctype.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
30 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
31 #ifndef HAVE_WINSOCK2 |
19544 | 32 #include <netdb.h> |
19318
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
33 #include <netinet/in.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
34 #include <sys/socket.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
35 #include <arpa/inet.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
36 #define closesocket close |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
37 #else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
38 #include <winsock2.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
39 #include <ws2tcpip.h> |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
40 #endif |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
41 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
42 #include "mp_msg.h" |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
43 #include "url.h" |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
44 #include "udp.h" |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
45 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
46 /* 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
|
47 int |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
48 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
|
49 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
50 int socket_server_fd, rxsockbufsz; |
19330 | 51 int err; |
52 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
|
53 fd_set set; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
54 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
|
55 struct ip_mreq mcast; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
56 struct timeval tv; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
57 struct hostent *hp; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
58 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
59 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
|
60 "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
|
61 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
62 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
|
63 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
|
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_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
|
66 return -1; |
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 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
69 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
|
70 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
71 #ifndef HAVE_WINSOCK2 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
72 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
|
73 if (!hp) |
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 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
|
76 "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
|
77 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
78 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
79 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
80 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
|
81 (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
|
82 #else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
83 server_address.sin_addr.s_addr = htonl (INADDR_ANY); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
84 #endif /* HAVE_WINSOCK2 */ |
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 else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
87 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
88 #ifndef HAVE_WINSOCK2 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
89 #ifdef USE_ATON |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
90 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
|
91 #else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
92 inet_pton (AF_INET, 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
|
93 #endif /* USE_ATON */ |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
94 #else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
95 server_address.sin_addr.s_addr = htonl(INADDR_ANY); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
96 #endif /* HAVE_WINSOCK2 */ |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
97 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
98 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
|
99 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
|
100 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
101 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
|
102 sizeof (server_address)) == -1) |
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 #ifndef HAVE_WINSOCK2 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
105 if (errno != EINPROGRESS) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
106 #else |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
107 if (WSAGetLastError () != WSAEINPROGRESS) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
108 #endif /* HAVE_WINSOCK2 */ |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
109 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
110 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
|
111 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
112 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
113 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
114 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
115 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
116 #ifdef HAVE_WINSOCK2 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
117 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
|
118 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
119 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
|
120 if (!hp) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
121 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
122 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
|
123 "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
|
124 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
125 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
126 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
127 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
|
128 (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
|
129 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
130 else |
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 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
|
133 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
|
134 } |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
135 #endif /* HAVE_WINSOCK2 */ |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
136 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
137 /* 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
|
138 rxsockbufsz = 240 * 1024; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
139 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
|
140 &rxsockbufsz, sizeof (rxsockbufsz))) |
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 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
|
143 "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
|
144 } |
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 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
|
147 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
148 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
|
149 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
|
150 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
151 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
|
152 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
|
153 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
154 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
|
155 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
156 return -1; |
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 } |
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 tv.tv_sec = 0; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
161 tv.tv_usec = (1 * 1000000); /* 1 second timeout */ |
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 FD_ZERO (&set); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
164 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
|
165 |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
166 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
|
167 if (err < 0) |
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 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
|
170 "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
|
171 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
172 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
173 } |
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 if (err == 0) |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
176 { |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
177 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
|
178 "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
|
179 closesocket (socket_server_fd); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
180 return -1; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
181 } |
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 err_len = sizeof (err); |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
184 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
|
185 if (err) |
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_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
|
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 return socket_server_fd; |
a3ddd3320b47
removed udp socket creation code from rtp stack to a new dedicated udp helper file
ben
parents:
diff
changeset
|
193 } |