diff --git a/protobuf.c b/protobuf.c index 09fc97cd5..2afa40997 100644 --- a/protobuf.c +++ b/protobuf.c @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -12,6 +13,7 @@ #include "log.h" #include "util.h" #include "string.h" +#include "sockets.h" #include "protobuf.h" #include "protobuf/inventory.pb-c.h" @@ -128,6 +130,8 @@ void cr_pb_init(void) */ #define PB_PKOBJ_LOCAL_SIZE 1024 +#define INET_ADDR_LEN 40 + struct pb_pr_field_s { void *data; int number; @@ -281,7 +285,23 @@ static size_t pb_show_prepare_field_context(const ProtobufCFieldDescriptor *fd, static int pb_show_pretty(pb_pr_field_t *field) { - pr_msg(field->fmt, *(long *)field->data); + switch (field->fmt[0]) { + case '%': + pr_msg(field->fmt, *(long *)field->data); + break; + case 'A': + { + char addr[INET_ADDR_LEN] = ""; + int family = (field->count == 1) ? AF_INET : AF_INET6; + + if (inet_ntop(family, (void *)field->data, addr, + INET_ADDR_LEN) == NULL) + pr_msg("failed to translate"); + else + pr_msg("%s", addr); + } + return 1; + } return 0; } diff --git a/sk-inet.c b/sk-inet.c index edcafc7f4..9b6fb3796 100644 --- a/sk-inet.c +++ b/sk-inet.c @@ -496,43 +496,5 @@ int inet_connect(int sk, struct inet_sk_info *ii) void show_inetsk(int fd, struct cr_options *o) { - InetSkEntry *ie; - int ret = 0; - - pr_img_head(CR_FD_INETSK); - - while (1) { - char src_addr[INET_ADDR_LEN] = ""; - char dst_addr[INET_ADDR_LEN] = ""; - - ret = pb_read_one_eof(fd, &ie, PB_INETSK); - if (ret <= 0) - goto out; - - if (inet_ntop(ie->family, (void *)ie->src_addr, src_addr, - INET_ADDR_LEN) == NULL) { - pr_perror("Failed to translate src address"); - } - - if (ie->state == TCP_ESTABLISHED) { - if (inet_ntop(ie->family, (void *)ie->dst_addr, dst_addr, - INET_ADDR_LEN) == NULL) { - pr_perror("Failed to translate dst address"); - } - } - - pr_msg("id %#x ino %#x family %s type %s proto %s state %s %s:%d <-> %s:%d flags 0x%2x\n", - ie->id, ie->ino, skfamily2s(ie->family), sktype2s(ie->type), skproto2s(ie->proto), - skstate2s(ie->state), src_addr, ie->src_port, dst_addr, ie->dst_port, ie->flags); - pr_msg("\t"), show_fown_cont(ie->fown), pr_msg("\n"); - show_socket_opts(ie->opts); - - inet_sk_entry__free_unpacked(ie, NULL); - } - -out: - if (ret) - pr_info("\n"); - pr_img_tail(CR_FD_INETSK); + pb_show_plain_pretty(fd, PB_INETSK, "1:%#x 2:%#x 3:%d 4:%d 5:%d 6:%d 7:%d 8:%d 9:%2x 11:A 12:A"); } -