Skip to content

Commit 951a15b

Browse files
committed
LocalIP: only print properties if detected in JSON results
1 parent f30501f commit 951a15b

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/modules/localip/localip.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -474,14 +474,20 @@ void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjs
474474
FF_LIST_FOR_EACH(FFLocalIpResult, ip, results)
475475
{
476476
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
477-
yyjson_mut_obj_add_bool(doc, obj, "defaultRoute", ip->defaultRoute);
478-
yyjson_mut_obj_add_strbuf(doc, obj, "ipv4", &ip->ipv4);
479-
yyjson_mut_obj_add_strbuf(doc, obj, "ipv6", &ip->ipv6);
480-
yyjson_mut_obj_add_strbuf(doc, obj, "mac", &ip->mac);
481477
yyjson_mut_obj_add_strbuf(doc, obj, "name", &ip->name);
482-
yyjson_mut_obj_add_int(doc, obj, "mtu", ip->mtu);
483-
yyjson_mut_obj_add_int(doc, obj, "speed", ip->speed);
484-
yyjson_mut_obj_add_strbuf(doc, obj, "flags", &ip->flags);
478+
yyjson_mut_obj_add_bool(doc, obj, "defaultRoute", ip->defaultRoute);
479+
if (options->showType & FF_LOCALIP_TYPE_IPV4_BIT)
480+
yyjson_mut_obj_add_strbuf(doc, obj, "ipv4", &ip->ipv4);
481+
if (options->showType & FF_LOCALIP_TYPE_IPV6_BIT)
482+
yyjson_mut_obj_add_strbuf(doc, obj, "ipv6", &ip->ipv6);
483+
if (options->showType & FF_LOCALIP_TYPE_MAC_BIT)
484+
yyjson_mut_obj_add_strbuf(doc, obj, "mac", &ip->mac);
485+
if (options->showType & FF_LOCALIP_TYPE_MTU_BIT)
486+
yyjson_mut_obj_add_int(doc, obj, "mtu", ip->mtu);
487+
if (options->showType & FF_LOCALIP_TYPE_SPEED_BIT)
488+
yyjson_mut_obj_add_int(doc, obj, "speed", ip->speed);
489+
if (options->showType & FF_LOCALIP_TYPE_FLAGS_BIT)
490+
yyjson_mut_obj_add_strbuf(doc, obj, "flags", &ip->flags);
485491
}
486492

487493
FF_LIST_FOR_EACH(FFLocalIpResult, ip, results)

0 commit comments

Comments
 (0)