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) {
208 struct servent *ent =
NULL;
209 #if HAVE_GETSERVBYPORT
211 ent = getservbyport(sin->sin_port, flags &
NI_DGRAM ?
"udp" :
"tcp");
215 snprintf(serv, servlen,
"%s", ent->s_name);
217 snprintf(serv, servlen,
"%d", ntohs(sin->sin_port));
224 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H
229 return "Temporary failure in name resolution";
231 return "Invalid flags for ai_flags";
233 return "A non-recoverable error occurred";
235 return "The address family was not recognized or the address "
236 "length was invalid for the specified family";
238 return "Memory allocation failure";
239 #if EAI_NODATA != EAI_NONAME
241 return "No address associated with hostname";
244 return "The name does not resolve for the supplied parameters";
246 return "servname not supported for ai_socktype";
248 return "ai_socktype not supported";
251 return "Unknown error";
258 u_long param = enable;
259 return ioctlsocket(socket, FIONBIO, ¶m);
262 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
264 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);
269 int ff_poll(
struct pollfd *fds, nfds_t numfds,
int timeout)
273 fd_set exception_set;
279 if (numfds >= FD_SETSIZE) {
287 FD_ZERO(&exception_set);
290 for (i = 0; i < numfds; i++) {
294 if (fds[i].fd >= FD_SETSIZE) {
300 if (fds[i].events & POLLIN)
301 FD_SET(fds[i].fd, &read_set);
302 if (fds[i].events & POLLOUT)
303 FD_SET(fds[i].fd, &write_set);
304 if (fds[i].events & POLLERR)
305 FD_SET(fds[i].fd, &exception_set);
316 rc = select(n, &read_set, &write_set, &exception_set,
NULL);
319 tv.tv_sec = timeout / 1000;
320 tv.tv_usec = 1000 * (timeout % 1000);
321 rc = select(n, &read_set, &write_set, &exception_set, &tv);
327 for (i = 0; i < numfds; i++) {
330 if (FD_ISSET(fds[i].fd, &read_set))
331 fds[i].revents |= POLLIN;
332 if (FD_ISSET(fds[i].fd, &write_set))
333 fds[i].revents |= POLLOUT;
334 if (FD_ISSET(fds[i].fd, &exception_set))
335 fds[i].revents |= POLLERR;
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 the string s.
struct addrinfo * ai_next
int ff_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res)
struct sockaddr * ai_addr
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...