* Pretty print an Internet address (net address + port). */
| 1418 | * Pretty print an Internet address (net address + port). |
| 1419 | */ |
| 1420 | static void |
| 1421 | inetprint(const char *container, struct in_addr *in, int port, |
| 1422 | const char *proto, int num_port, const int af1) |
| 1423 | { |
| 1424 | struct servent *sp = 0; |
| 1425 | char line[80], *cp; |
| 1426 | int width; |
| 1427 | size_t alen, plen; |
| 1428 | |
| 1429 | if (container) |
| 1430 | xo_open_container(container); |
| 1431 | |
| 1432 | if (Wflag) |
| 1433 | snprintf(line, sizeof(line), "%s.", inetname(in)); |
| 1434 | else |
| 1435 | snprintf(line, sizeof(line), "%.*s.", |
| 1436 | (Aflag && !num_port) ? 12 : 16, inetname(in)); |
| 1437 | alen = strlen(line); |
| 1438 | cp = line + alen; |
| 1439 | if (!num_port && port) |
| 1440 | sp = getservbyport((int)port, proto); |
| 1441 | if (sp || port == 0) |
| 1442 | snprintf(cp, sizeof(line) - alen, |
| 1443 | "%.15s ", sp ? sp->s_name : "*"); |
| 1444 | else |
| 1445 | snprintf(cp, sizeof(line) - alen, |
| 1446 | "%d ", ntohs((u_short)port)); |
| 1447 | width = (Aflag && !Wflag) ? 18 : |
| 1448 | ((!Wflag || af1 == AF_INET) ? 22 : 45); |
| 1449 | if (Wflag) |
| 1450 | xo_emit("{d:target/%-*s} ", width, line); |
| 1451 | else |
| 1452 | xo_emit("{d:target/%-*.*s} ", width, width, line); |
| 1453 | |
| 1454 | plen = strlen(cp) - 1; |
| 1455 | alen--; |
| 1456 | xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen, |
| 1457 | plen, cp); |
| 1458 | |
| 1459 | if (container) |
| 1460 | xo_close_container(container); |
| 1461 | } |
| 1462 | |
| 1463 | /* |
| 1464 | * Construct an Internet address representation. |
no test coverage detected