Skip to content

Commit

Permalink
Add new convenience function fi_host_is_localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
chu11 committed Jan 13, 2017
1 parent 66467f4 commit e30837c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions common/miscutil/fi_hostlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,3 +841,38 @@ fi_host_is_valid (const char *addr, const char *port, uint16_t *portptr)

return (1);
}

/* Note that we do not do address resolution to map hypothetical
* situations (e.g. "foobar" resolves to "127.0.0.1"). We only
* hardcode and check for the known popular strings.
*
* The reason is that most of FreeIPMI supports mapping "localhost" to
* "inband" communication primarily for convenience. Programmers
* don't have to handle "inband" communication differenly than
* "outofband" cases. e.g. you can script/program with the hosts
* "node1,node2,node3,localhost,node4" and not have to program a
* special case for "inband" communication.
*
* If a user truly wants some funky host/string to resolve to
* "localhost", we suggest they use one of the known popular strings
* instead. We don't want to have to do host resolution checks for
* every host/IP ever input into FreeIPMI.
*/
int
fi_host_is_localhost (const char *host)
{
struct in6_addr in6;

assert (host);

/* Ordered by my assumption of most popular */
if (!strcasecmp (host, "localhost")
|| !strcmp (host, "127.0.0.1")
|| !strcasecmp (host, "ipv6-localhost")
|| !strcmp (host, "::1")
|| !strcasecmp (host, "ip6-localhost")
|| !strcmp (host, "0:0:0:0:0:0:0:1"))
return (1);

return (0);
}
6 changes: 6 additions & 0 deletions common/miscutil/fi_hostlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,10 @@ int fi_host_is_host_with_port (const char *host, char **addr, char **port);
*/
int fi_host_is_valid (const char *addr, const char *port, uint16_t *portptr);

/* Determine if hostname is a "localhost" or equivalent string,
* returns 1 for yes, 0 for no. No host resolution will be done, only
* string matching for common strings.
*/
int fi_host_is_localhost (const char *host);

#endif /* !_FI_HOSTLIST_H */

0 comments on commit e30837c

Please sign in to comment.