24 #define _DEFAULT_SOURCE
39 #elif HAVE_SYS_SELECT_H
40 #include <sys/select.h>
51 unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0;
53 if (sscanf(str,
"%d.%d.%d.%d", &add1, &add2, &add3, &add4) != 4)
56 if (!add1 || (add1 | add2 | add3 | add4) > 255)
59 add->s_addr = htonl((add1 << 24) + (add2 << 16) + (add3 << 8) + add4);
66 return inet_aton(str, add);
74 struct hostent *
h =
NULL;
76 struct sockaddr_in *sin;
79 int (WSAAPI *win_getaddrinfo)(
const char *node,
const char *service,
82 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
85 return win_getaddrinfo(node, service, hints, res);
92 sin->sin_family = AF_INET;
100 h = gethostbyname(node);
105 memcpy(&sin->sin_addr, h->h_addr_list[0],
sizeof(
struct in_addr));
109 sin->sin_addr.s_addr = INADDR_ANY;
117 sin->sin_port = htons(atoi(service));
140 ai->
ai_addr = (
struct sockaddr *)sin;
153 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
154 win_freeaddrinfo = (
void (WSAAPI *)(
struct addrinfo *res))
156 if (win_freeaddrinfo) {
157 win_freeaddrinfo(res);
168 char *host,
int hostlen,
169 char *serv,
int servlen,
int flags)
171 const struct sockaddr_in *sin = (
const struct sockaddr_in *)sa;
174 int (WSAAPI *win_getnameinfo)(
const struct sockaddr *sa, socklen_t salen,
175 char *host,
DWORD hostlen,
177 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
180 return win_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
183 if (sa->sa_family != AF_INET)
188 if (host && hostlen > 0) {
189 struct hostent *ent =
NULL;
192 ent = gethostbyaddr((
const char *)&sin->sin_addr,
193 sizeof(sin->sin_addr), AF_INET);
196 snprintf(host, hostlen,
"%s", ent->h_name);
200 a = ntohl(sin->sin_addr.s_addr);
201 snprintf(host, hostlen,
"%d.%d.%d.%d",
202 ((a >> 24) & 0xff), ((a >> 16) & 0xff),
203 ((a >> 8) & 0xff), (a & 0xff));
207 if (serv && servlen > 0) {
210 snprintf(serv, servlen,
"%d", ntohs(sin->sin_port));
217 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
222 return "Temporary failure in name resolution";
224 return "Invalid flags for ai_flags";
226 return "A non-recoverable error occurred";
228 return "The address family was not recognized or the address "
229 "length was invalid for the specified family";
231 return "Memory allocation failure";
232 #if EAI_NODATA != EAI_NONAME
234 return "No address associated with hostname";
237 return "The name does not resolve for the supplied parameters";
239 return "servname not supported for ai_socktype";
241 return "ai_socktype not supported";
244 return "Unknown error";
251 u_long param = enable;
252 return ioctlsocket(socket, FIONBIO, ¶m);
255 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
257 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);
262 int ff_poll(
struct pollfd *fds, nfds_t numfds,
int timeout)
266 fd_set exception_set;
272 if (numfds >= FD_SETSIZE) {
280 FD_ZERO(&exception_set);
283 for (i = 0; i < numfds; i++) {
287 if (fds[i].fd >= FD_SETSIZE) {
293 if (fds[i].events & POLLIN)
294 FD_SET(fds[i].fd, &read_set);
295 if (fds[i].events & POLLOUT)
296 FD_SET(fds[i].fd, &write_set);
297 if (fds[i].events & POLLERR)
298 FD_SET(fds[i].fd, &exception_set);
309 rc = select(n, &read_set, &write_set, &exception_set,
NULL);
312 tv.tv_sec = timeout / 1000;
313 tv.tv_usec = 1000 * (timeout % 1000);
314 rc = select(n, &read_set, &write_set, &exception_set, &tv);
320 for (i = 0; i < numfds; i++) {
323 if (FD_ISSET(fds[i].fd, &read_set))
324 fds[i].revents |= POLLIN;
325 if (FD_ISSET(fds[i].fd, &write_set))
326 fds[i].revents |= POLLOUT;
327 if (FD_ISSET(fds[i].fd, &exception_set))
328 fds[i].revents |= POLLERR;
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int ff_getnameinfo(const struct sockaddr *sa, int salen, char *host, int hostlen, char *serv, int servlen, int flags)
miscellaneous OS support macros and functions.
const char * ff_gai_strerror(int ecode)
void ff_freeaddrinfo(struct addrinfo *res)
int ff_inet_aton(const char *str, struct in_addr *add)
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
int ff_socket_nonblock(int socket, int enable)
char * av_strdup(const char *s)
Duplicate a string.
struct addrinfo * ai_next
int ff_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
struct sockaddr * ai_addr