* prints one port, symbolic or numeric */
| 867 | * prints one port, symbolic or numeric |
| 868 | */ |
| 869 | static void |
| 870 | print_port(struct buf_pr *bp, int proto, uint16_t port) |
| 871 | { |
| 872 | |
| 873 | if (proto == IPPROTO_ETHERTYPE) { |
| 874 | char const *s; |
| 875 | |
| 876 | if (g_co.do_resolv && (s = match_value(ether_types, port)) ) |
| 877 | bprintf(bp, "%s", s); |
| 878 | else |
| 879 | bprintf(bp, "0x%04x", port); |
| 880 | } else { |
| 881 | struct servent *se = NULL; |
| 882 | if (g_co.do_resolv) { |
| 883 | struct protoent *pe = getprotobynumber(proto); |
| 884 | |
| 885 | se = getservbyport(htons(port), pe ? pe->p_name : NULL); |
| 886 | } |
| 887 | if (se) |
| 888 | bprintf(bp, "%s", se->s_name); |
| 889 | else |
| 890 | bprintf(bp, "%d", port); |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | static struct _s_x _port_name[] = { |
| 895 | {"dst-port", O_IP_DSTPORT}, |
no test coverage detected