38 #elif HAVE_SYS_SELECT_H 39 #include <sys/select.h> 50 unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0;
52 if (sscanf(str,
"%d.%d.%d.%d", &add1, &add2, &add3, &add4) != 4)
55 if (!add1 || (add1 | add2 | add3 | add4) > 255)
58 add->s_addr = htonl((add1 << 24) + (add2 << 16) + (add3 << 8) + add4);
65 return inet_aton(str, add);
73 struct hostent *h =
NULL;
75 struct sockaddr_in *sin;
78 int (WSAAPI *win_getaddrinfo)(
const char *node,
const char *service,
81 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
84 return win_getaddrinfo(node, service, hints, res);
91 sin->sin_family = AF_INET;
99 h = gethostbyname(node);
104 memcpy(&sin->sin_addr, h->h_addr_list[0],
sizeof(
struct in_addr));
108 sin->sin_addr.s_addr = INADDR_ANY;
116 sin->sin_port = htons(atoi(service));
139 ai->
ai_addr = (
struct sockaddr *)sin;
152 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
153 win_freeaddrinfo = (
void (WSAAPI *)(
struct addrinfo *res))
155 if (win_freeaddrinfo) {
156 win_freeaddrinfo(res);
167 char *host,
int hostlen,
168 char *serv,
int servlen,
int flags)
170 const struct sockaddr_in *sin = (
const struct sockaddr_in *)sa;
173 int (WSAAPI *win_getnameinfo)(
const struct sockaddr *sa, socklen_t salen,
174 char *host, DWORD hostlen,
175 char *serv, DWORD servlen,
int flags);
176 HMODULE ws2mod = GetModuleHandle(
"ws2_32.dll");
179 return win_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
182 if (sa->sa_family != AF_INET)
187 if (host && hostlen > 0) {
188 struct hostent *ent =
NULL;
191 ent = gethostbyaddr((
const char *)&sin->sin_addr,
192 sizeof(sin->sin_addr), AF_INET);
195 snprintf(host, hostlen,
"%s", ent->h_name);
199 a = ntohl(sin->sin_addr.s_addr);
200 snprintf(host, hostlen,
"%d.%d.%d.%d",
201 ((a >> 24) & 0xff), ((a >> 16) & 0xff),
202 ((a >> 8) & 0xff), (a & 0xff));
206 if (serv && servlen > 0) {
209 snprintf(serv, servlen,
"%d", ntohs(sin->sin_port));
216 #if !HAVE_GETADDRINFO || HAVE_WINSOCK2_H 221 return "Temporary failure in name resolution";
223 return "Invalid flags for ai_flags";
225 return "A non-recoverable error occurred";
227 return "The address family was not recognized or the address " 228 "length was invalid for the specified family";
230 return "Memory allocation failure";
231 #if EAI_NODATA != EAI_NONAME 233 return "No address associated with hostname";
236 return "The name does not resolve for the supplied parameters";
238 return "servname not supported for ai_socktype";
240 return "ai_socktype not supported";
243 return "Unknown error";
250 u_long param = enable;
251 return ioctlsocket(socket, FIONBIO, ¶m);
254 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
256 return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);
261 int ff_poll(
struct pollfd *fds, nfds_t numfds,
int timeout)
265 fd_set exception_set;
271 if (numfds >= FD_SETSIZE) {
279 FD_ZERO(&exception_set);
282 for (i = 0; i < numfds; i++) {
286 if (fds[i].fd >= FD_SETSIZE) {
292 if (fds[i].events & POLLIN)
293 FD_SET(fds[i].fd, &read_set);
294 if (fds[i].events & POLLOUT)
295 FD_SET(fds[i].fd, &write_set);
296 if (fds[i].events & POLLERR)
297 FD_SET(fds[i].fd, &exception_set);
308 rc = select(n, &read_set, &write_set, &exception_set,
NULL);
311 tv.tv_sec = timeout / 1000;
312 tv.tv_usec = 1000 * (timeout % 1000);
313 rc = select(n, &read_set, &write_set, &exception_set, &tv);
319 for (i = 0; i < numfds; i++) {
322 if (FD_ISSET(fds[i].fd, &read_set))
323 fds[i].revents |= POLLIN;
324 if (FD_ISSET(fds[i].fd, &write_set))
325 fds[i].revents |= POLLOUT;
326 if (FD_ISSET(fds[i].fd, &exception_set))
327 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.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
const char * ff_gai_strerror(int ecode)
void ff_freeaddrinfo(struct addrinfo *res)
int ff_inet_aton(const char *str, struct in_addr *add)
int ff_socket_nonblock(int socket, int enable)
char * av_strdup(const char *s)
Duplicate the string s.
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
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 ...