mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-06 04:53:13 +02:00
Remove is_ip_valid() as we already have is_valid_ip(), and update
the doxygen docs a bit for that function.
This commit is contained in:
-15
@@ -2308,21 +2308,6 @@ char *url_getfilename(const char *url)
|
||||
return raw_strdup("-");
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks whether given string contains a valid IP address.
|
||||
*/
|
||||
int is_ip_valid(const char *ip)
|
||||
{
|
||||
char scratch[64];
|
||||
if (BadPtr(ip))
|
||||
return 0;
|
||||
if (inet_pton(AF_INET, ip, scratch) == 1)
|
||||
return 1;
|
||||
if (inet_pton(AF_INET6, ip, scratch) == 1)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/access-waccess
|
||||
// mode value Checks file for
|
||||
|
||||
@@ -349,7 +349,7 @@ void dowebirc(Client *client, const char *ip, const char *host, const char *opti
|
||||
|
||||
/* STEP 1: Update client->local->ip
|
||||
inet_pton() returns 1 on success, 0 on bad input, -1 on bad AF */
|
||||
if (!is_ip_valid(ip))
|
||||
if (!is_valid_ip(ip))
|
||||
{
|
||||
/* then we have an invalid IP */
|
||||
exit_client(client, NULL, "Invalid IP address");
|
||||
|
||||
@@ -184,7 +184,7 @@ int websocket_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs)
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
if (!is_ip_valid(cep->value))
|
||||
if (!is_valid_ip(cep->value))
|
||||
{
|
||||
config_error("%s:%i: invalid IP address '%s' in listen::options::websocket::forward", cep->file->filename, cep->line_number, cep->value);
|
||||
errors++;
|
||||
@@ -696,7 +696,7 @@ int websocket_handshake_valid(Client *client)
|
||||
struct HTTPForwardedHeader *forwarded;
|
||||
forwarded = websocket_parse_forwarded_header(WSU(client)->forwarded);
|
||||
/* check header values */
|
||||
if (!is_ip_valid(forwarded->ip))
|
||||
if (!is_valid_ip(forwarded->ip))
|
||||
{
|
||||
unreal_log(ULOG_WARNING, "websocket", "INVALID_FORWARDED_IP", client, "Received invalid IP in Forwarded header from $ip", log_data_string("ip", client->ip));
|
||||
dead_socket(client, "Forwarded: invalid IP");
|
||||
|
||||
+11
-6
@@ -1036,18 +1036,23 @@ void process_clients(void)
|
||||
} while(&client->lclient_node != &unknown_list);
|
||||
}
|
||||
|
||||
/** Returns 4 if 'str' is a valid IPv4 address
|
||||
* and 6 if 'str' is a valid IPv6 IP address.
|
||||
* Zero (0) is returned in any other case (eg: hostname).
|
||||
/** Check if 'ip' is a valid IP address, and if so what type.
|
||||
* @param ip The IP address
|
||||
* @retval 4 Valid IPv4 address
|
||||
* @retval 6 Valid IPv6 address
|
||||
* @retval 0 Invalid IP address (eg: a hostname)
|
||||
*/
|
||||
int is_valid_ip(const char *str)
|
||||
int is_valid_ip(const char *ip)
|
||||
{
|
||||
char scratch[64];
|
||||
|
||||
if (inet_pton(AF_INET, str, scratch) == 1)
|
||||
if (BadPtr(ip))
|
||||
return 0;
|
||||
|
||||
if (inet_pton(AF_INET, ip, scratch) == 1)
|
||||
return 4; /* IPv4 */
|
||||
|
||||
if (inet_pton(AF_INET6, str, scratch) == 1)
|
||||
if (inet_pton(AF_INET6, ip, scratch) == 1)
|
||||
return 6; /* IPv6 */
|
||||
|
||||
return 0; /* not an IP address */
|
||||
|
||||
Reference in New Issue
Block a user