forked from networkupstools/nut
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request networkupstools#2518 from jimklimov/issue-2512
Fix `nut-scanner` IPv6 support
- Loading branch information
Showing
13 changed files
with
473 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
Copyright (C) 1999 Russell Kroll <[email protected]> | ||
Copyright (C) 2012 Arnaud Quette <[email protected]> | ||
Copyright (C) 2020-2024 Jim Klimov <[email protected]> | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
@@ -217,10 +218,22 @@ static void clean_exit(void) | |
|
||
int main(int argc, char **argv) | ||
{ | ||
int i; | ||
int i = 0; | ||
uint16_t port; | ||
int varlist = 0, clientlist = 0, verbose = 0; | ||
const char *prog = xbasename(argv[0]); | ||
char *s = NULL; | ||
|
||
/* NOTE: Caller must `export NUT_DEBUG_LEVEL` to see debugs for upsc | ||
* and NUT methods called from it. This line aims to just initialize | ||
* the subsystem, and set initial timestamp. Debugging the client is | ||
* primarily of use to developers, so is not exposed via `-D` args. | ||
*/ | ||
s = getenv("NUT_DEBUG_LEVEL"); | ||
if (s && str_to_int(s, &i, 10) && i > 0) { | ||
nut_debug_level = i; | ||
} | ||
upsdebugx(1, "Starting NUT client: %s", prog); | ||
|
||
while ((i = getopt(argc, argv, "+hlLcV")) != -1) { | ||
|
||
|
@@ -267,6 +280,8 @@ int main(int argc, char **argv) | |
fatalx(EXIT_FAILURE, "Error: invalid UPS definition.\nRequired format: upsname[@hostname[:port]]"); | ||
} | ||
} | ||
upsdebugx(1, "upsname='%s' hostname='%s' port='%" PRIu16 "'", | ||
NUT_STRARG(upsname), NUT_STRARG(hostname), port); | ||
|
||
ups = xmalloc(sizeof(*ups)); | ||
|
||
|
@@ -275,18 +290,22 @@ int main(int argc, char **argv) | |
} | ||
|
||
if (varlist) { | ||
upsdebugx(1, "Calling list_upses()"); | ||
list_upses(verbose); | ||
exit(EXIT_SUCCESS); | ||
} | ||
|
||
if (clientlist) { | ||
upsdebugx(1, "Calling list_clients()"); | ||
list_clients(upsname); | ||
exit(EXIT_SUCCESS); | ||
} | ||
|
||
if (argc > 1) { | ||
upsdebugx(1, "Calling printvar(%s)", argv[1]); | ||
printvar(argv[1]); | ||
} else { | ||
upsdebugx(1, "Calling list_vars()"); | ||
list_vars(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
Copyright (C) | ||
2002 Russell Kroll <[email protected]> | ||
2008 Arjen de Korte <[email protected]> | ||
2020 - 2024 Jim Klimov <[email protected]> | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
|
@@ -1024,6 +1025,7 @@ int upscli_tryconnect(UPSCONN_t *ups, const char *host, uint16_t port, int flags | |
ups->fd = -1; | ||
|
||
if (!host) { | ||
upslogx(LOG_WARNING, "%s: Host not found: '%s'", __func__, NUT_STRARG(host)); | ||
ups->upserror = UPSCLI_ERR_NOSUCHHOST; | ||
return -1; | ||
} | ||
|
@@ -1049,6 +1051,7 @@ int upscli_tryconnect(UPSCONN_t *ups, const char *host, uint16_t port, int flags | |
case EAI_AGAIN: | ||
continue; | ||
case EAI_NONAME: | ||
upslogx(LOG_WARNING, "%s: Host not found: '%s'", __func__, NUT_STRARG(host)); | ||
ups->upserror = UPSCLI_ERR_NOSUCHHOST; | ||
return -1; | ||
case EAI_MEMORY: | ||
|
@@ -1207,7 +1210,7 @@ int upscli_tryconnect(UPSCONN_t *ups, const char *host, uint16_t port, int flags | |
} else if (tryssl && ret == 0) { | ||
if (certverify != 0) { | ||
upslogx(LOG_NOTICE, "Can not connect to NUT server %s in SSL and " | ||
"certificate is needed, disconnect", host); | ||
"certificate is needed, disconnect", host); | ||
upscli_disconnect(ups); | ||
return -1; | ||
} | ||
|
@@ -1686,7 +1689,21 @@ int upscli_splitaddr(const char *buf, char **hostname, uint16_t *port) | |
return -1; | ||
} | ||
|
||
s = strchr(tmp, '@'); | ||
|
||
/* someone passed a "@hostname" string? */ | ||
if (s) { | ||
fprintf(stderr, "upscli_splitaddr: wrong call? " | ||
"Got upsname@hostname[:port] string where " | ||
"only hostname[:port] was expected: %s\n", buf); | ||
/* let it pass, but probably fail later */ | ||
} | ||
|
||
if (*tmp == '[') { | ||
/* NOTE: Brackets are required for colon-separated IPv6 | ||
* addresses, to differentiate from a port number. For | ||
* example, `[1234:5678]:3493` would seem right. | ||
*/ | ||
if (strchr(tmp, ']') == NULL) { | ||
fprintf(stderr, "upscli_splitaddr: missing closing bracket in [domain literal]\n"); | ||
return -1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.