void inet6print(const char *container, struct in6_addr *in6, int port, const char *proto, int numeric) { struct servent *sp = 0; char line[80], *cp; int width; if (container) xo_open_container(container); sprintf(line, "%.*s.", Wflag ? 39 : (Aflag && !numeric) ? 12 : 16, inet6name(in6)); cp = strchr(line, '\0'); if (!numeric && port) GETSERVBYPORT6(port, proto, sp); if (sp || port == 0) sprintf(cp, "%.15s", sp ? sp->s_name : "*"); else sprintf(cp, "%d", ntohs((u_short)port)); width = Wflag ? 45 : Aflag ? 18 : 22; xo_emit("{d:target/%-*.*s} ", width, width, line); int alen = cp - line - 1, plen = strlen(cp) - 1; xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen, plen, cp); if (container) xo_close_container(container); }
static void sctp_print_address(union sctp_sockstore *address, int port, int num_port) { struct servent *sp = 0; char line[80], *cp; int width; switch (address->sa.sa_family) { #ifdef INET case AF_INET: sprintf(line, "%.*s.", Wflag ? 39 : 16, inetname(&address->sin.sin_addr)); break; #endif #ifdef INET6 case AF_INET6: sprintf(line, "%.*s.", Wflag ? 39 : 16, inet6name(&address->sin6.sin6_addr)); break; #endif default: sprintf(line, "%.*s.", Wflag ? 39 : 16, ""); break; } cp = strchr(line, '\0'); if (!num_port && port) sp = getservbyport((int)port, "sctp"); if (sp || port == 0) sprintf(cp, "%.15s ", sp ? sp->s_name : "*"); else sprintf(cp, "%d ", ntohs((u_short)port)); width = Wflag ? 45 : 22; printf("%-*.*s ", width, width, line); }
void inet6print(struct in6_addr *in6, int port, char *proto) { #define GETSERVBYPORT6(port, proto, ret) do { \ if (strcmp((proto), "tcp6") == 0) \ (ret) = getservbyport((int)(port), "tcp"); \ else if (strcmp((proto), "udp6") == 0) \ (ret) = getservbyport((int)(port), "udp"); \ else \ (ret) = getservbyport((int)(port), (proto)); \ } while (0) struct servent *sp = 0; char line[80], *cp; int width; int len = sizeof line; width = Aflag ? 12 : 16; if (vflag && width < strlen(inet6name(in6))) width = strlen(inet6name(in6)); snprintf(line, len, "%.*s.", width, inet6name(in6)); len -= strlen(line); if (len <= 0) goto bail; cp = strchr(line, '\0'); if (!nflag && port) GETSERVBYPORT6(port, proto, sp); if (sp || port == 0) snprintf(cp, len, "%.8s", sp ? sp->s_name : "*"); else snprintf(cp, len, "%d", ntohs((u_short)port)); width = Aflag ? 18 : 22; if (vflag && width < strlen(line)) width = strlen(line); bail: printf(" %-*.*s", width, width, line); }
void inet6print(unsigned char *in6, int port, const char *proto, int local) { #define GETSERVBYPORT6(port, proto, ret) do { \ if (strcmp((proto), "tcp6") == 0) \ (ret) = getservbyport((int)(port), "tcp"); \ else if (strcmp((proto), "udp6") == 0) \ (ret) = getservbyport((int)(port), "udp"); \ else \ (ret) = getservbyport((int)(port), (proto)); \ } while (0) struct servent *sp = NULL; char line[80], *cp; unsigned width = 27-9; int len = sizeof line; if (vflag && width < strlen(inet6name(in6))) width = strlen(inet6name(in6)); snprintf(line, len, "%.*s.", width, inet6name(in6)); len -= strlen(line); if (len <= 0) goto bail; cp = strchr(line, '\0'); if (!nflag && port && local) GETSERVBYPORT6(htons(port), proto, sp); if (sp || port == 0) snprintf(cp, len, vflag ? "%s" : "%.8s", sp ? sp->s_name : "*"); else snprintf(cp, len, "%d", port); width = 27; if (vflag && width < strlen(line)) width = strlen(line); bail: printf(" %-*.*s", width, width, line); }
static void inet6print(struct in6_addr *in6, int port, char *proto, field_def *fld) { struct servent *sp = 0; tb_start(); tbprintf("%s", inet6name(in6)); if (!nflag && port) sp = getservbyport(port, proto); if (sp || port == 0) tbprintf(":%s", sp ? sp->s_name : "*"); else tbprintf(":%d", ntohs((u_short)port)); print_fld_tb(fld); }
/* * Pretty print an Internet address (net address + port). * If the nflag was specified, use numbers instead of names. */ void inet6print(struct in6_addr *in, u_short port, const char *proto) { struct servent *sp = 0; char line[80], *cp; int width; sprintf(line, "%.*s.", 22, inet6name(in)); cp = strchr(line, '\0'); if (!nflag && port) sp = getservbyport(htons(port), proto); if (sp || port == 0) sprintf(cp, "%.8s", sp ? sp->s_name : "*"); else sprintf(cp, "%d", port); width = 28; printf(" %-*.*s", width, width, line); }
void inet6print(struct in6_addr *in6, int port, const char *proto, int numeric) { struct servent *sp = 0; char line[80], *cp; int width; sprintf(line, "%.*s.", Wflag ? 39 : (Aflag && !numeric) ? 12 : 16, inet6name(in6)); cp = strchr(line, '\0'); if (!numeric && port) GETSERVBYPORT6(port, proto, sp); if (sp || port == 0) sprintf(cp, "%.15s", sp ? sp->s_name : "*"); else sprintf(cp, "%d", ntohs((u_short)port)); width = Wflag ? 45 : Aflag ? 18 : 22; printf("%-*.*s ", width, width, line); }
static void sctp_print_address(const char *container, union sctp_sockstore *address, int port, int num_port) { struct servent *sp = 0; char line[80], *cp; int width; if (container) xo_open_container(container); switch (address->sa.sa_family) { #ifdef INET case AF_INET: sprintf(line, "%.*s.", Wflag ? 39 : 16, inetname(&address->sin.sin_addr)); break; #endif #ifdef INET6 case AF_INET6: sprintf(line, "%.*s.", Wflag ? 39 : 16, inet6name(&address->sin6.sin6_addr)); break; #endif default: sprintf(line, "%.*s.", Wflag ? 39 : 16, ""); break; } cp = strchr(line, '\0'); if (!num_port && port) sp = getservbyport((int)port, "sctp"); if (sp || port == 0) sprintf(cp, "%.15s ", sp ? sp->s_name : "*"); else sprintf(cp, "%d ", ntohs((u_short)port)); width = Wflag ? 45 : 22; xo_emit("{d:target/%-*.*s} ", width, width, line); int alen = cp - line - 1, plen = strlen(cp) - 1; xo_emit("{e:address/%*.*s}{e:port/%*.*s}", alen, alen, line, plen, plen, cp); if (container) xo_close_container(container); }