* Construct an Internet address representation. * If numeric_addr has been supplied, give * numeric value, otherwise try for symbolic name. */
| 1466 | * numeric value, otherwise try for symbolic name. |
| 1467 | */ |
| 1468 | char * |
| 1469 | inetname(struct in_addr *inp) |
| 1470 | { |
| 1471 | char *cp; |
| 1472 | static char line[MAXHOSTNAMELEN]; |
| 1473 | #ifndef FSTACK |
| 1474 | struct hostent *hp; |
| 1475 | struct netent *np; |
| 1476 | #endif |
| 1477 | |
| 1478 | cp = 0; |
| 1479 | #ifndef FSTACK |
| 1480 | if (!numeric_addr && inp->s_addr != INADDR_ANY) { |
| 1481 | int net = inet_netof(*inp); |
| 1482 | int lna = inet_lnaof(*inp); |
| 1483 | |
| 1484 | if (lna == INADDR_ANY) { |
| 1485 | np = getnetbyaddr(net, AF_INET); |
| 1486 | if (np) |
| 1487 | cp = np->n_name; |
| 1488 | } |
| 1489 | if (cp == NULL) { |
| 1490 | hp = gethostbyaddr((char *)inp, sizeof (*inp), AF_INET); |
| 1491 | if (hp) { |
| 1492 | cp = hp->h_name; |
| 1493 | trimdomain(cp, strlen(cp)); |
| 1494 | } |
| 1495 | } |
| 1496 | } |
| 1497 | #endif |
| 1498 | if (inp->s_addr == INADDR_ANY) |
| 1499 | strcpy(line, "*"); |
| 1500 | else if (cp) { |
| 1501 | strlcpy(line, cp, sizeof(line)); |
| 1502 | } else { |
| 1503 | inp->s_addr = ntohl(inp->s_addr); |
| 1504 | #define C(x) ((u_int)((x) & 0xff)) |
| 1505 | snprintf(line, sizeof(line), "%u.%u.%u.%u", |
| 1506 | C(inp->s_addr >> 24), C(inp->s_addr >> 16), |
| 1507 | C(inp->s_addr >> 8), C(inp->s_addr)); |
| 1508 | } |
| 1509 | return (line); |
| 1510 | } |
| 1511 | #endif |
no test coverage detected