| 320 | */ |
| 321 | |
| 322 | char * /* O - Host name */ |
| 323 | httpAddrLookup( |
| 324 | const http_addr_t *addr, /* I - Address to lookup */ |
| 325 | char *name, /* I - Host name buffer */ |
| 326 | int namelen) /* I - Size of name buffer */ |
| 327 | { |
| 328 | _cups_globals_t *cg = _cupsGlobals(); |
| 329 | /* Global data */ |
| 330 | |
| 331 | |
| 332 | DEBUG_printf(("httpAddrLookup(addr=%p, name=%p, namelen=%d)", (void *)addr, (void *)name, namelen)); |
| 333 | |
| 334 | /* |
| 335 | * Range check input... |
| 336 | */ |
| 337 | |
| 338 | if (!addr || !name || namelen <= 2) |
| 339 | { |
| 340 | if (name && namelen >= 1) |
| 341 | *name = '\0'; |
| 342 | |
| 343 | return (NULL); |
| 344 | } |
| 345 | |
| 346 | #ifdef AF_LOCAL |
| 347 | if (addr->addr.sa_family == AF_LOCAL) |
| 348 | { |
| 349 | strlcpy(name, addr->un.sun_path, (size_t)namelen); |
| 350 | return (name); |
| 351 | } |
| 352 | #endif /* AF_LOCAL */ |
| 353 | |
| 354 | /* |
| 355 | * Optimize lookups for localhost/loopback addresses... |
| 356 | */ |
| 357 | |
| 358 | if (httpAddrLocalhost(addr)) |
| 359 | { |
| 360 | strlcpy(name, "localhost", (size_t)namelen); |
| 361 | return (name); |
| 362 | } |
| 363 | |
| 364 | #ifdef HAVE_RES_INIT |
| 365 | /* |
| 366 | * STR #2920: Initialize resolver after failure in cups-polld |
| 367 | * |
| 368 | * If the previous lookup failed, re-initialize the resolver to prevent |
| 369 | * temporary network errors from persisting. This *should* be handled by |
| 370 | * the resolver libraries, but apparently the glibc folks do not agree. |
| 371 | * |
| 372 | * We set a flag at the end of this function if we encounter an error that |
| 373 | * requires reinitialization of the resolver functions. We then call |
| 374 | * res_init() if the flag is set on the next call here or in httpAddrLookup(). |
| 375 | */ |
| 376 | |
| 377 | if (cg->need_res_init) |
| 378 | { |
| 379 | res_init(); |
no test coverage detected