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); }
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); }
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); }