FIXME: make ffserver work with IPv6 */ resolve host with also IP address parsing */
| 317 | /* FIXME: make ffserver work with IPv6 */ |
| 318 | /* resolve host with also IP address parsing */ |
| 319 | static int resolve_host(struct in_addr *sin_addr, const char *hostname) |
| 320 | { |
| 321 | |
| 322 | if (!ff_inet_aton(hostname, sin_addr)) { |
| 323 | #if HAVE_GETADDRINFO |
| 324 | struct addrinfo *ai, *cur; |
| 325 | struct addrinfo hints; |
| 326 | memset(&hints, 0, sizeof(hints)); |
| 327 | hints.ai_family = AF_INET; |
| 328 | if (getaddrinfo(hostname, NULL, &hints, &ai)) |
| 329 | return -1; |
| 330 | /* getaddrinfo returns a linked list of addrinfo structs. |
| 331 | * Even if we set ai_family = AF_INET above, make sure |
| 332 | * that the returned one actually is of the correct type. */ |
| 333 | for (cur = ai; cur; cur = cur->ai_next) { |
| 334 | if (cur->ai_family == AF_INET) { |
| 335 | *sin_addr = ((struct sockaddr_in *)cur->ai_addr)->sin_addr; |
| 336 | freeaddrinfo(ai); |
| 337 | return 0; |
| 338 | } |
| 339 | } |
| 340 | freeaddrinfo(ai); |
| 341 | return -1; |
| 342 | #else |
| 343 | struct hostent *hp; |
| 344 | hp = gethostbyname(hostname); |
| 345 | if (!hp) |
| 346 | return -1; |
| 347 | memcpy(sin_addr, hp->h_addr_list[0], sizeof(struct in_addr)); |
| 348 | #endif |
| 349 | } |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static char *ctime1(char *buf2) |
| 354 | { |
no test coverage detected