}
}
+static void
+print_ip(ProtobufCBinaryData *ip, const char *label) {
+ char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")];
+ if (ip->len == 4 || ip->len == 16) {
+ if (inet_ntop(ip->len == 4 ? AF_INET : AF_INET6, ip->data, buf,
+ sizeof(buf)) != NULL)
+ {
+ printf(" %s: \"%s\"\n", label, buf);
+ }
+ }
+}
+
static void
print_yaml(dns_dtdata_t *dt) {
Dnstap__Dnstap *frame = dt->frame;
if (m->has_query_address) {
ProtobufCBinaryData *ip = &m->query_address;
- char buf[100];
- (void)inet_ntop(ip->len == 4 ? AF_INET : AF_INET6, ip->data,
- buf, sizeof(buf));
- printf(" query_address: \"%s\"\n", buf);
+ print_ip(ip, "query_address");
}
if (m->has_response_address) {
ProtobufCBinaryData *ip = &m->response_address;
- char buf[100];
- (void)inet_ntop(ip->len == 4 ? AF_INET : AF_INET6, ip->data,
- buf, sizeof(buf));
- printf(" response_address: \"%s\"\n", buf);
+ print_ip(ip, "response_address");
}
if (m->has_query_port) {