LocalIP: add option --localip-default-route-only

This commit is contained in:
李通洲 2023-07-17 18:32:13 +08:00
parent 1e57c4c088
commit f34d51b911
No known key found for this signature in database
GPG Key ID: 6E72B663408769DE
5 changed files with 33 additions and 2 deletions

View File

@ -24,6 +24,7 @@ Features:
* Add option `--size-ndigits` and `--size-max-prefix` (#494)
* Add option `--processing-timeout` to the timeout when waiting for child processes.
* Public IP module prints the IP location if `--publicip-url` is not set (PublicIP)
* Add option `--localip-default-route-only` (LocalIP)
Bugfixes:
* Fix possible hanging (TerminalFont, #493)

View File

@ -859,6 +859,11 @@
"title": "Show IPs with given name prefix only",
"type": "string"
},
"showDefaultRouteOnly": {
"title": "Show ips that are used for default routing only",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},

View File

@ -131,6 +131,7 @@ Module specific options:
--localip-show-mac <?value>: Show mac addresses in local ip module. Default is false
--localip-show-loop <?value>: Show loop back addresses (127.0.0.1) in local ip module. Default is false
--localip-name-prefix <str>: Show IPs with given name prefix only. Default is empty
--localip-default-route-only <?value>: Show ips that are used for default routing only. Default is false
--localip-compact <?value>: Show all IPs in one line. Default is false
--publicip-timeout: Time in milliseconds to wait for the public ip server to respond. Default is disabled (0)
--publicip-url: The URL of public IP detection server to be used.

View File

@ -80,10 +80,17 @@ void ffPrintLocalIp(FFLocalIpOptions* options)
{
ffPrintLogoAndKey(FF_LOCALIP_DISPLAY_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor);
bool flag = false;
FF_LIST_FOR_EACH(FFLocalIpResult, ip, results)
{
if ((void*) ip != (void*) results.data)
if (options->defaultRouteOnly && !ip->defaultRoute)
continue;
if (flag)
fputs(" - ", stdout);
else
flag = true;
printIp(ip, false);
}
putchar('\n');
@ -94,11 +101,14 @@ void ffPrintLocalIp(FFLocalIpOptions* options)
FF_LIST_FOR_EACH(FFLocalIpResult, ip, results)
{
if (options->defaultRouteOnly && !ip->defaultRoute)
continue;
formatKey(options, ip, &key);
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(key.chars, 0, NULL, &options->moduleArgs.keyColor);
printIp(ip, results.length > 1);
printIp(ip, !options->defaultRouteOnly);
putchar('\n');
}
else
@ -130,6 +140,7 @@ void ffInitLocalIpOptions(FFLocalIpOptions* options)
options->showType = FF_LOCALIP_TYPE_IPV4_BIT;
ffStrbufInit(&options->namePrefix);
options->defaultRouteOnly = false;
}
bool ffParseLocalIpCommandOptions(FFLocalIpOptions* options, const char* key, const char* value)
@ -190,6 +201,12 @@ bool ffParseLocalIpCommandOptions(FFLocalIpOptions* options, const char* key, co
return true;
}
if (ffStrEqualsIgnCase(subKey, "default-route-only"))
{
options->defaultRouteOnly = ffOptionParseBoolean(value);
return true;
}
return false;
}
@ -268,6 +285,12 @@ void ffParseLocalIpJsonObject(yyjson_val* module)
continue;
}
if (ffStrEqualsIgnCase(key, "defaultRouteOnly"))
{
options.defaultRouteOnly = yyjson_get_bool(val);
continue;
}
ffPrintError(FF_LOCALIP_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
}

View File

@ -22,4 +22,5 @@ typedef struct FFLocalIpOptions
FFLocalIpType showType;
FFstrbuf namePrefix;
bool defaultRouteOnly;
} FFLocalIpOptions;