Mercurial > libavformat.hg
annotate os_support.c @ 6099:ed24da0b0cee libavformat
bgr/rgb444 for nut
author | michael |
---|---|
date | Sun, 06 Jun 2010 11:43:53 +0000 |
parents | 3126d2588595 |
children | f0263543b617 |
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 |
5767 | 25 #define _DARWIN_C_SOURCE |
3722
68749aaea50f
ensure we get explicit definition of various _XOPEN_SOURCE functions we use
aurel
parents:
3039
diff
changeset
|
26 |
443
afbe3a5aae02
libavformat/os_support.c HAVE_LOCALTIME_R patch by ("Steven M. Schultz" <sms at 2BSD dot COM>)
michael
parents:
230
diff
changeset
|
27 #include "config.h" |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
28 #include "avformat.h" |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
29 #include <unistd.h> |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
30 #include <fcntl.h> |
3732 | 31 #include <sys/time.h> |
2773 | 32 #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
|
33 |
4206 | 34 #if CONFIG_NETWORK |
35 #if !HAVE_POLL_H | |
36 #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
|
37 #include <winsock2.h> |
4206 | 38 #elif HAVE_SYS_SELECT_H |
1797 | 39 #include <sys/select.h> |
40 #endif | |
1798
d1e61f4d02cd
MinGW patch by <koyama AT infocity DOT co DOT jp>, reworked. Removed placeholder for winsock.
mmu_man
parents:
1797
diff
changeset
|
41 #endif |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
42 |
2050
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
43 #include "network.h" |
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
44 |
4206 | 45 #if !HAVE_INET_ATON |
1511
6d9dd5b5e764
MinGW compilation fix, inet_aton and #includes depend on networking support.
diego
parents:
1506
diff
changeset
|
46 #include <stdlib.h> |
6d9dd5b5e764
MinGW compilation fix, inet_aton and #includes depend on networking support.
diego
parents:
1506
diff
changeset
|
47 #include <strings.h> |
6d9dd5b5e764
MinGW compilation fix, inet_aton and #includes depend on networking support.
diego
parents:
1506
diff
changeset
|
48 |
5766
a292ef47e2f9
Localize the #define _SVID_SOURCE needed for inet_aton() to os_support.c
conrad
parents:
5730
diff
changeset
|
49 int ff_inet_aton (const char * str, struct in_addr * add) |
1506 | 50 { |
51 unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0; | |
52 | |
2271 | 53 if (sscanf(str, "%d.%d.%d.%d", &add1, &add2, &add3, &add4) != 4) |
54 return 0; | |
1506 | 55 |
2269
dfccc156e185
fix emulated inet_aton so that it fails for invalid addresses
benoit
parents:
2267
diff
changeset
|
56 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
|
57 |
5505
166bc62c1d57
Currently, the replacement which is used if inet_aton isn't available,
rbultje
parents:
4206
diff
changeset
|
58 add->s_addr = htonl((add1 << 24) + (add2 << 16) + (add3 << 8) + add4); |
1506 | 59 |
60 return 1; | |
61 } | |
5766
a292ef47e2f9
Localize the #define _SVID_SOURCE needed for inet_aton() to os_support.c
conrad
parents:
5730
diff
changeset
|
62 #else |
a292ef47e2f9
Localize the #define _SVID_SOURCE needed for inet_aton() to os_support.c
conrad
parents:
5730
diff
changeset
|
63 int ff_inet_aton (const char * str, struct in_addr * add) |
a292ef47e2f9
Localize the #define _SVID_SOURCE needed for inet_aton() to os_support.c
conrad
parents:
5730
diff
changeset
|
64 { |
a292ef47e2f9
Localize the #define _SVID_SOURCE needed for inet_aton() to os_support.c
conrad
parents:
5730
diff
changeset
|
65 return inet_aton(str, add); |
a292ef47e2f9
Localize the #define _SVID_SOURCE needed for inet_aton() to os_support.c
conrad
parents:
5730
diff
changeset
|
66 } |
4206 | 67 #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
|
68 |
5516
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
69 #if !HAVE_GETADDRINFO |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
70 int ff_getaddrinfo(const char *node, const char *service, |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
71 const struct addrinfo *hints, struct addrinfo **res) |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
72 { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
73 struct hostent *h = NULL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
74 struct addrinfo *ai; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
75 struct sockaddr_in *sin; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
76 |
5588
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
77 #if HAVE_WINSOCK2_H |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
78 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
|
79 const struct addrinfo *hints, |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
80 struct addrinfo **res); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
81 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
|
82 win_getaddrinfo = GetProcAddress(ws2mod, "getaddrinfo"); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
83 if (win_getaddrinfo) |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
84 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
|
85 #endif |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
86 |
5730
de3bbecc27ad
Make our getaddrinfo implementation initialize "struct addrinfo" return
reimar
parents:
5638
diff
changeset
|
87 *res = NULL; |
5516
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
88 sin = av_mallocz(sizeof(struct sockaddr_in)); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
89 if (!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 sin->sin_family = AF_INET; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
92 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
93 if (node) { |
5766
a292ef47e2f9
Localize the #define _SVID_SOURCE needed for inet_aton() to os_support.c
conrad
parents:
5730
diff
changeset
|
94 if (!ff_inet_aton(node, &sin->sin_addr)) { |
5516
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
95 if (hints && (hints->ai_flags & AI_NUMERICHOST)) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
96 av_free(sin); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
97 return EAI_FAIL; |
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 h = gethostbyname(node); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
100 if (!h) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
101 av_free(sin); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
102 return EAI_FAIL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
103 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
104 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
|
105 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
106 } else { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
107 if (hints && (hints->ai_flags & AI_PASSIVE)) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
108 sin->sin_addr.s_addr = INADDR_ANY; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
109 } else |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
110 sin->sin_addr.s_addr = INADDR_LOOPBACK; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
111 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
112 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
113 /* Note: getaddrinfo allows service to be a string, which |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
114 * should be looked up using getservbyname. */ |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
115 if (service) |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
116 sin->sin_port = htons(atoi(service)); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
117 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
118 ai = av_mallocz(sizeof(struct addrinfo)); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
119 if (!ai) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
120 av_free(sin); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
121 return EAI_FAIL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
122 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
123 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
124 *res = ai; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
125 ai->ai_family = AF_INET; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
126 ai->ai_socktype = hints ? hints->ai_socktype : 0; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
127 switch (ai->ai_socktype) { |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
128 case SOCK_STREAM: ai->ai_protocol = IPPROTO_TCP; break; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
129 case SOCK_DGRAM: ai->ai_protocol = IPPROTO_UDP; break; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
130 default: ai->ai_protocol = 0; break; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
131 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
132 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
133 ai->ai_addr = (struct sockaddr *)sin; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
134 ai->ai_addrlen = sizeof(struct sockaddr_in); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
135 if (hints && (hints->ai_flags & AI_CANONNAME)) |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
136 ai->ai_canonname = h ? av_strdup(h->h_name) : NULL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
137 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
138 ai->ai_next = NULL; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
139 return 0; |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
140 } |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
141 |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
142 void ff_freeaddrinfo(struct addrinfo *res) |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
143 { |
5588
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
144 #if HAVE_WINSOCK2_H |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
145 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
|
146 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
|
147 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
|
148 GetProcAddress(ws2mod, "freeaddrinfo"); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
149 if (win_freeaddrinfo) { |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
150 win_freeaddrinfo(res); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
151 return; |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
152 } |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
153 #endif |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
154 |
5516
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
155 av_free(res->ai_canonname); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
156 av_free(res->ai_addr); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
157 av_free(res); |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
158 } |
5520
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
159 |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
160 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
|
161 char *host, int hostlen, |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
162 char *serv, int servlen, int flags) |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
163 { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
164 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
|
165 |
5588
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
166 #if HAVE_WINSOCK2_H |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
167 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
|
168 char *host, DWORD hostlen, |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
169 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
|
170 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
|
171 win_getnameinfo = GetProcAddress(ws2mod, "getnameinfo"); |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
172 if (win_getnameinfo) |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
173 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
|
174 #endif |
866c497d9abd
Load the proper getaddrinfo functions from ws2_32.dll, if they're present.
ramiro
parents:
5520
diff
changeset
|
175 |
5520
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
176 if (sa->sa_family != AF_INET) |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
177 return EAI_FAMILY; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
178 if (!host && !serv) |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
179 return EAI_NONAME; |
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 (host && hostlen > 0) { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
182 struct hostent *ent = NULL; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
183 uint32_t a; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
184 if (!(flags & NI_NUMERICHOST)) |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
185 ent = gethostbyaddr((const char *)&sin->sin_addr, |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
186 sizeof(sin->sin_addr), AF_INET); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
187 |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
188 if (ent) { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
189 snprintf(host, hostlen, "%s", ent->h_name); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
190 } else if (flags & NI_NAMERQD) { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
191 return EAI_NONAME; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
192 } else { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
193 a = ntohl(sin->sin_addr.s_addr); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
194 snprintf(host, hostlen, "%d.%d.%d.%d", |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
195 ((a >> 24) & 0xff), ((a >> 16) & 0xff), |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
196 ((a >> 8) & 0xff), ( a & 0xff)); |
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 } |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
199 |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
200 if (serv && servlen > 0) { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
201 struct servent *ent = NULL; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
202 if (!(flags & NI_NUMERICSERV)) |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
203 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
|
204 |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
205 if (ent) { |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
206 snprintf(serv, servlen, "%s", ent->s_name); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
207 } else |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
208 snprintf(serv, servlen, "%d", ntohs(sin->sin_port)); |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
209 } |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
210 |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
211 return 0; |
8797851aeedb
Provide a fallback for getnameinfo() also. Patch by Martin Storsj
rbultje
parents:
5516
diff
changeset
|
212 } |
5638
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 const char *ff_gai_strerror(int ecode) |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
215 { |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
216 switch(ecode) { |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
217 case EAI_FAIL : return "A non-recoverable error occurred"; |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
218 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
|
219 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
|
220 } |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
221 |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
222 return "Unknown error"; |
a3e321e7ca38
Implement gai_strerror() for systems lacking such functionality. Patch
rbultje
parents:
5588
diff
changeset
|
223 } |
5516
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
224 #endif |
afe4a96b6832
Provide fallback implementations of getaddrinfo() and freeaddrinfo().
rbultje
parents:
5515
diff
changeset
|
225 |
2057
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
226 int ff_socket_nonblock(int socket, int enable) |
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
227 { |
4206 | 228 #if HAVE_WINSOCK2_H |
2085 | 229 return ioctlsocket(socket, FIONBIO, &enable); |
230 #else | |
2057
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
231 if (enable) |
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
232 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
|
233 else |
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
234 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK); |
2085 | 235 #endif |
2057
857fbfeb2fa0
implement ff_socket_nonblock and use it in networking code
alex
parents:
2052
diff
changeset
|
236 } |
2050
612d19cb9550
move resolve_host from tcp.c to os_support.c as it is used widely
alex
parents:
2025
diff
changeset
|
237 #endif /* CONFIG_NETWORK */ |
1797 | 238 |
4206 | 239 #if CONFIG_FFSERVER |
240 #if !HAVE_POLL_H | |
1797 | 241 int poll(struct pollfd *fds, nfds_t numfds, int timeout) |
242 { | |
243 fd_set read_set; | |
244 fd_set write_set; | |
245 fd_set exception_set; | |
246 nfds_t i; | |
247 int n; | |
248 int rc; | |
249 | |
4206 | 250 #if HAVE_WINSOCK2_H |
2092 | 251 if (numfds >= FD_SETSIZE) { |
252 errno = EINVAL; | |
253 return -1; | |
254 } | |
2093 | 255 #endif |
2092 | 256 |
1797 | 257 FD_ZERO(&read_set); |
258 FD_ZERO(&write_set); | |
259 FD_ZERO(&exception_set); | |
260 | |
261 n = -1; | |
262 for(i = 0; i < numfds; i++) { | |
263 if (fds[i].fd < 0) | |
264 continue; | |
4206 | 265 #if !HAVE_WINSOCK2_H |
2093 | 266 if (fds[i].fd >= FD_SETSIZE) { |
267 errno = EINVAL; | |
268 return -1; | |
269 } | |
270 #endif | |
1797 | 271 |
272 if (fds[i].events & POLLIN) FD_SET(fds[i].fd, &read_set); | |
273 if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set); | |
274 if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set); | |
275 | |
276 if (fds[i].fd > n) | |
277 n = fds[i].fd; | |
278 }; | |
279 | |
280 if (n == -1) | |
281 /* Hey!? Nothing to poll, in fact!!! */ | |
282 return 0; | |
283 | |
284 if (timeout < 0) | |
285 rc = select(n+1, &read_set, &write_set, &exception_set, NULL); | |
286 else { | |
287 struct timeval tv; | |
288 | |
289 tv.tv_sec = timeout / 1000; | |
290 tv.tv_usec = 1000 * (timeout % 1000); | |
291 rc = select(n+1, &read_set, &write_set, &exception_set, &tv); | |
292 }; | |
293 | |
294 if (rc < 0) | |
295 return rc; | |
296 | |
297 for(i = 0; i < (nfds_t) n; i++) { | |
298 fds[i].revents = 0; | |
299 | |
300 if (FD_ISSET(fds[i].fd, &read_set)) fds[i].revents |= POLLIN; | |
301 if (FD_ISSET(fds[i].fd, &write_set)) fds[i].revents |= POLLOUT; | |
302 if (FD_ISSET(fds[i].fd, &exception_set)) fds[i].revents |= POLLERR; | |
303 }; | |
304 | |
305 return rc; | |
306 } | |
3039 | 307 #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
|
308 #endif /* CONFIG_FFSERVER */ |
1797 | 309 |