Mercurial > libavformat.hg
annotate os_support.c @ 5642:747753995dee libavformat
Dont give up after 100kb of zero bytes but returnd EAGAIN
fixes issue1729
author | michael |
---|---|
date | Wed, 10 Feb 2010 14:25:57 +0000 |
parents | a3e321e7ca38 |
children | de3bbecc27ad |
rev | line source |
---|---|
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
1 /* |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
2 * Various utilities for ffmpeg system |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard |
1506 | 4 * copyright (c) 2002 Francois Revol |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
5 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
6 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
7 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
8 * FFmpeg is free software; you can redistribute it and/or |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
10 * License as published by the Free Software Foundation; either |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
11 * version 2.1 of the License, or (at your option) any later version. |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
12 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
13 * FFmpeg is distributed in the hope that it will be useful, |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
16 * Lesser General Public License for more details. |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
17 * |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
19 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
21 */ |
3722
68749aaea50f
ensure we get explicit definition of various _XOPEN_SOURCE functions we use
aurel
parents:
3039
diff
changeset
|
22 |
68749aaea50f
ensure we get explicit definition of various _XOPEN_SOURCE functions we use
aurel
parents:
3039
diff
changeset
|
23 /* needed by inet_aton() */ |
68749aaea50f
ensure we get explicit definition of various _XOPEN_SOURCE functions we use
aurel
parents:
3039
diff
changeset
|
24 #define _SVID_SOURCE |
68749aaea50f
ensure we get explicit definition of various _XOPEN_SOURCE functions we use
aurel
parents:
3039
diff
changeset
|
25 |
443
afbe3a5aae02
libavformat/os_support.c HAVE_LOCALTIME_R patch by ("Steven M. Schultz" <sms at 2BSD dot COM>)
michael
parents:
230
diff
changeset
|
26 #include "config.h" |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
27 #include "avformat.h" |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
28 #include <unistd.h> |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
29 #include <fcntl.h> |
3732 | 30 #include <sys/time.h> |
2773 | 31 #include "os_support.h" |
1798
d1e61f4d02cd
MinGW patch by <koyama AT infocity DOT co DOT jp>, reworked. Removed placeholder for winsock.
mmu_man
parents:
1797
diff
changeset
|
32 |
4206 | 33 #if CONFIG_NETWORK |
34 #if !HAVE_POLL_H | |
35 #if HAVE_WINSOCK2_H | |
1798
d1e61f4d02cd
MinGW patch by <koyama AT infocity DOT co DOT jp>, reworked. Removed placeholder for winsock.
mmu_man
parents:
1797
diff
changeset
|
36 #include <winsock2.h> |
4206 | 37 #elif HAVE_SYS_SELECT_H |
1797 | 38 #include <sys/select.h> |
39 #endif | |
1798
d1e61f4d02cd
MinGW patch by <koyama AT infocity DOT co DOT jp>, reworked. Removed placeholder for winsock.
mmu_man
parents:
1797
diff
changeset
|
40 #endif |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
41 |
2050
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
42 #include "network.h" |
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
43 |
4206 | 44 #if !HAVE_INET_ATON |
1511
6d9dd5b5e764
MinGW compilation fix, inet_aton and #includes depend on networking support.
diego
parents:
1506
diff
changeset
|
45 #include <stdlib.h> |
6d9dd5b5e764
MinGW compilation fix, inet_aton and #includes depend on networking support.
diego
parents:
1506
diff
changeset
|
46 #include <strings.h> |
6d9dd5b5e764
MinGW compilation fix, inet_aton and #includes depend on networking support.
diego
parents:
1506
diff
changeset
|
47 |
1506 | 48 int inet_aton (const char * str, struct in_addr * add) |
49 { | |
50 unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0; | |
51 | |
2271 | 52 if (sscanf(str, "%d.%d.%d.%d", &add1, &add2, &add3, &add4) != 4) |
53 return 0; | |
1506 | 54 |
2269
dfccc156e185
fix emulated inet_aton so that it fails for invalid addresses
benoit
parents:
2267
diff
changeset
|
55 if (!add1 || (add1|add2|add3|add4) > 255) return 0; |
dfccc156e185
fix emulated inet_aton so that it fails for invalid addresses
benoit
parents:
2267
diff
changeset
|
56 |
5505
166bc62c1d57
Currently, the replacement which is used if inet_aton isn't available,
rbultje
parents:
4206
diff
changeset
|
57 add->s_addr = htonl((add1 << 24) + (add2 << 16) + (add3 << 8) + add4); |
1506 | 58 |
59 return 1; | |
60 } | |
4206 | 61 #endif /* !HAVE_INET_ATON */ |
2050
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
62 |
5516
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
63 #if !HAVE_GETADDRINFO |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
64 int ff_getaddrinfo(const char *node, const char *service, |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
65 const struct addrinfo *hints, struct addrinfo **res) |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
66 { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
67 struct hostent *h = NULL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
68 struct addrinfo *ai; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
69 struct sockaddr_in *sin; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
70 |
5588
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
71 #if HAVE_WINSOCK2_H |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
72 int (WSAAPI *win_getaddrinfo)(const char *node, const char *service, |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
73 const struct addrinfo *hints, |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
74 struct addrinfo **res); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
75 HMODULE ws2mod = GetModuleHandle("ws2_32.dll"); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
76 win_getaddrinfo = GetProcAddress(ws2mod, "getaddrinfo"); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
77 if (win_getaddrinfo) |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
78 return win_getaddrinfo(node, service, hints, res); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
79 #endif |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
80 |
5516
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
81 sin = av_mallocz(sizeof(struct sockaddr_in)); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
82 if (!sin) |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
83 return EAI_FAIL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
84 sin->sin_family = AF_INET; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
85 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
86 if (node) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
87 if (!inet_aton(node, &sin->sin_addr)) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
88 if (hints && (hints->ai_flags & AI_NUMERICHOST)) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
89 av_free(sin); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
90 return EAI_FAIL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
91 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
92 h = gethostbyname(node); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
93 if (!h) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
94 av_free(sin); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
95 return EAI_FAIL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
96 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
97 memcpy(&sin->sin_addr, h->h_addr_list[0], sizeof(struct in_addr)); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
98 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
99 } else { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
100 if (hints && (hints->ai_flags & AI_PASSIVE)) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
101 sin->sin_addr.s_addr = INADDR_ANY; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
102 } else |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
103 sin->sin_addr.s_addr = INADDR_LOOPBACK; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
104 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
105 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
106 /* Note: getaddrinfo allows service to be a string, which |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
107 * should be looked up using getservbyname. */ |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
108 if (service) |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
109 sin->sin_port = htons(atoi(service)); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
110 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
111 ai = av_mallocz(sizeof(struct addrinfo)); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
112 if (!ai) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
113 av_free(sin); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
114 return EAI_FAIL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
115 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
116 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
117 *res = ai; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
118 ai->ai_family = AF_INET; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
119 ai->ai_socktype = hints ? hints->ai_socktype : 0; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
120 switch (ai->ai_socktype) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
121 case SOCK_STREAM: ai->ai_protocol = IPPROTO_TCP; break; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
122 case SOCK_DGRAM: ai->ai_protocol = IPPROTO_UDP; break; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
123 default: ai->ai_protocol = 0; break; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
124 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
125 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
126 ai->ai_addr = (struct sockaddr *)sin; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
127 ai->ai_addrlen = sizeof(struct sockaddr_in); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
128 if (hints && (hints->ai_flags & AI_CANONNAME)) |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
129 ai->ai_canonname = h ? av_strdup(h->h_name) : NULL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
130 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
131 ai->ai_next = NULL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
132 return 0; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
133 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
134 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
135 void ff_freeaddrinfo(struct addrinfo *res) |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
136 { |
5588
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
137 #if HAVE_WINSOCK2_H |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
138 void (WSAAPI *win_freeaddrinfo)(struct addrinfo *res); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
139 HMODULE ws2mod = GetModuleHandle("ws2_32.dll"); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
140 win_freeaddrinfo = (void (WSAAPI *)(struct addrinfo *res)) |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
141 GetProcAddress(ws2mod, "freeaddrinfo"); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
142 if (win_freeaddrinfo) { |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
143 win_freeaddrinfo(res); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
144 return; |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
145 } |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
146 #endif |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
147 |
5516
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
148 av_free(res->ai_canonname); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
149 av_free(res->ai_addr); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
150 av_free(res); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
151 } |
5520
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
152 |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
153 int ff_getnameinfo(const struct sockaddr *sa, int salen, |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
154 char *host, int hostlen, |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
155 char *serv, int servlen, int flags) |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
156 { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
157 const struct sockaddr_in *sin = (const struct sockaddr_in *)sa; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
158 |
5588
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
159 #if HAVE_WINSOCK2_H |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
160 int (WSAAPI *win_getnameinfo)(const struct sockaddr *sa, socklen_t salen, |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
161 char *host, DWORD hostlen, |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
162 char *serv, DWORD servlen, int flags); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
163 HMODULE ws2mod = GetModuleHandle("ws2_32.dll"); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
164 win_getnameinfo = GetProcAddress(ws2mod, "getnameinfo"); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
165 if (win_getnameinfo) |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
166 return win_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
167 #endif |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
168 |
5520
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
169 if (sa->sa_family != AF_INET) |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
170 return EAI_FAMILY; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
171 if (!host && !serv) |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
172 return EAI_NONAME; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
173 |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
174 if (host && hostlen > 0) { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
175 struct hostent *ent = NULL; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
176 uint32_t a; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
177 if (!(flags & NI_NUMERICHOST)) |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
178 ent = gethostbyaddr((const char *)&sin->sin_addr, |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
179 sizeof(sin->sin_addr), AF_INET); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
180 |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
181 if (ent) { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
182 snprintf(host, hostlen, "%s", ent->h_name); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
183 } else if (flags & NI_NAMERQD) { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
184 return EAI_NONAME; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
185 } else { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
186 a = ntohl(sin->sin_addr.s_addr); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
187 snprintf(host, hostlen, "%d.%d.%d.%d", |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
188 ((a >> 24) & 0xff), ((a >> 16) & 0xff), |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
189 ((a >> 8) & 0xff), ( a & 0xff)); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
190 } |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
191 } |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
192 |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
193 if (serv && servlen > 0) { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
194 struct servent *ent = NULL; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
195 if (!(flags & NI_NUMERICSERV)) |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
196 ent = getservbyport(sin->sin_port, flags & NI_DGRAM ? "udp" : "tcp"); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
197 |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
198 if (ent) { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
199 snprintf(serv, servlen, "%s", ent->s_name); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
200 } else |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
201 snprintf(serv, servlen, "%d", ntohs(sin->sin_port)); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
202 } |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
203 |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
204 return 0; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj«Ó
rbultje
parents:
5516
diff
changeset
|
205 } |
5638
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
206 |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
207 const char *ff_gai_strerror(int ecode) |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
208 { |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
209 switch(ecode) { |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
210 case EAI_FAIL : return "A non-recoverable error occurred"; |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
211 case EAI_FAMILY : return "The address family was not recognized or the address length was invalid for the specified family"; |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
212 case EAI_NONAME : return "The name does not resolve for the supplied parameters"; |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
213 } |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
214 |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
215 return "Unknown error"; |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
216 } |
5516
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
217 #endif |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
218 |
2050
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
219 /* resolve host with also IP address parsing */ |
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
220 int resolve_host(struct in_addr *sin_addr, const char *hostname) |
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
221 { |
2052 | 222 |
2050
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
223 if (!inet_aton(hostname, sin_addr)) { |
5515
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
224 #if HAVE_GETADDRINFO |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
225 struct addrinfo *ai, *cur; |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
226 struct addrinfo hints; |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
227 memset(&hints, 0, sizeof(hints)); |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
228 hints.ai_family = AF_INET; |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
229 if (getaddrinfo(hostname, NULL, &hints, &ai)) |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
230 return -1; |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
231 /* getaddrinfo returns a linked list of addrinfo structs. |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
232 * Even if we set ai_family = AF_INET above, make sure |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
233 * that the returned one actually is of the correct type. */ |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
234 for (cur = ai; cur; cur = cur->ai_next) { |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
235 if (cur->ai_family == AF_INET) { |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
236 *sin_addr = ((struct sockaddr_in *)cur->ai_addr)->sin_addr; |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
237 freeaddrinfo(ai); |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
238 return 0; |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
239 } |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
240 } |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
241 freeaddrinfo(ai); |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
242 return -1; |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
243 #else |
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
244 struct hostent *hp; |
2052 | 245 hp = gethostbyname(hostname); |
246 if (!hp) | |
247 return -1; | |
3723
81726233f9b3
use h_addr_list[0] instead of h_addr as this is the posix hostent field name
aurel
parents:
3722
diff
changeset
|
248 memcpy(sin_addr, hp->h_addr_list[0], sizeof(struct in_addr)); |
5515
fa3115c9b043
Use getaddrinfo(), if available, in resolve_host(). Patch by Martin
rbultje
parents:
5505
diff
changeset
|
249 #endif |
2050
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
250 } |
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
251 return 0; |
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
252 } |
2057
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
253 |
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
254 int ff_socket_nonblock(int socket, int enable) |
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
255 { |
4206 | 256 #if HAVE_WINSOCK2_H |
2085 | 257 return ioctlsocket(socket, FIONBIO, &enable); |
258 #else | |
2057
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
259 if (enable) |
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
260 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK); |
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
261 else |
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
262 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK); |
2085 | 263 #endif |
2057
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
264 } |
2050
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
265 #endif /* CONFIG_NETWORK */ |
1797 | 266 |
4206 | 267 #if CONFIG_FFSERVER |
268 #if !HAVE_POLL_H | |
1797 | 269 int poll(struct pollfd *fds, nfds_t numfds, int timeout) |
270 { | |
271 fd_set read_set; | |
272 fd_set write_set; | |
273 fd_set exception_set; | |
274 nfds_t i; | |
275 int n; | |
276 int rc; | |
277 | |
4206 | 278 #if HAVE_WINSOCK2_H |
2092 | 279 if (numfds >= FD_SETSIZE) { |
280 errno = EINVAL; | |
281 return -1; | |
282 } | |
2093 | 283 #endif |
2092 | 284 |
1797 | 285 FD_ZERO(&read_set); |
286 FD_ZERO(&write_set); | |
287 FD_ZERO(&exception_set); | |
288 | |
289 n = -1; | |
290 for(i = 0; i < numfds; i++) { | |
291 if (fds[i].fd < 0) | |
292 continue; | |
4206 | 293 #if !HAVE_WINSOCK2_H |
2093 | 294 if (fds[i].fd >= FD_SETSIZE) { |
295 errno = EINVAL; | |
296 return -1; | |
297 } | |
298 #endif | |
1797 | 299 |
300 if (fds[i].events & POLLIN) FD_SET(fds[i].fd, &read_set); | |
301 if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set); | |
302 if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set); | |
303 | |
304 if (fds[i].fd > n) | |
305 n = fds[i].fd; | |
306 }; | |
307 | |
308 if (n == -1) | |
309 /* Hey!? Nothing to poll, in fact!!! */ | |
310 return 0; | |
311 | |
312 if (timeout < 0) | |
313 rc = select(n+1, &read_set, &write_set, &exception_set, NULL); | |
314 else { | |
315 struct timeval tv; | |
316 | |
317 tv.tv_sec = timeout / 1000; | |
318 tv.tv_usec = 1000 * (timeout % 1000); | |
319 rc = select(n+1, &read_set, &write_set, &exception_set, &tv); | |
320 }; | |
321 | |
322 if (rc < 0) | |
323 return rc; | |
324 | |
325 for(i = 0; i < (nfds_t) n; i++) { | |
326 fds[i].revents = 0; | |
327 | |
328 if (FD_ISSET(fds[i].fd, &read_set)) fds[i].revents |= POLLIN; | |
329 if (FD_ISSET(fds[i].fd, &write_set)) fds[i].revents |= POLLOUT; | |
330 if (FD_ISSET(fds[i].fd, &exception_set)) fds[i].revents |= POLLERR; | |
331 }; | |
332 | |
333 return rc; | |
334 } | |
3039 | 335 #endif /* HAVE_POLL_H */ |
1799
0dc3a767943d
Make sure we don't try to emulate poll() when it's there if --disable-ffserver... 10l
mmu_man
parents:
1798
diff
changeset
|
336 #endif /* CONFIG_FFSERVER */ |
1797 | 337 |