Skip to content

Commit

Permalink
Minor changes for extern
Browse files Browse the repository at this point in the history
and unique IP-addresses.
  • Loading branch information
gvanem committed Jan 29, 2025
1 parent 4ff2da9 commit 44ed966
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/net_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ static bool _client_is_unique (const mg_addr *addr, intptr_t service, unique_IP

if (addr->is_ip6 || /* check only IPv4 addresses */
*(uint32_t*) &addr->ip == 0) /* Ignore 0.0.0.0 */
return (true);
return (false);

for (ip = g_unique_ips; ip; ip = ip->next)
{
Expand Down Expand Up @@ -1361,13 +1361,12 @@ static void unique_ips_print (intptr_t service)

if (num > 0)
{
unique_IP *_ip, *start;
unique_IP *_ip, *start = calloc (sizeof(*start), num);

start = _ip = calloc (sizeof(*start), num);
if (!start)
return;

for (ip = g_unique_ips; ip; ip = ip->next, _ip++)
for (ip = g_unique_ips, _ip = start; ip; ip = ip->next, _ip++)
if (ip->service == service)
memcpy (_ip, ip, sizeof(*_ip));

Expand All @@ -1377,9 +1376,6 @@ static void unique_ips_print (intptr_t service)
{
ip_address ip_addr;

if (!client_is_extern(&_ip->addr))
continue;

mg_snprintf (ip_addr, sizeof(ip_addr), "%M", mg_print_ip, _ip->addr);
modeS_asprintf (&buf, "%s", ip_addr);

Expand All @@ -1396,6 +1392,11 @@ static void unique_ips_print (intptr_t service)

fprintf (Modes.log, "%*s", (int)indent, " ");
fputs_long_line (Modes.log, buf, indent);
if (Modes.debug & DEBUG_NET)
{
fprintf (stdout, "%*s", (int)indent, " ");
fputs_long_line (stdout, buf, indent);
}
free (buf);
Modes.log = save;
}
Expand Down Expand Up @@ -1567,13 +1568,13 @@ static size_t deny_list_num6 (void)

static bool client_is_extern (const mg_addr *addr)
{
uint32_t ip4;
const struct in_addr *ia;

if (addr->is_ip6)
return (IN6_IS_ADDR_LOOPBACK ((const IN6_ADDR*)&addr->ip) == false);

ip4 = ntohl (*(const uint32_t*) &addr->ip);
return (ip4 != INADDR_LOOPBACK); /* ip4 !== 127.0.0.1 */
ia = (const struct in_addr*) &addr->ip;
return (ia->s_net != 0 && ia->s_net != 127); /* not 0.0.0.0 and not 127.x.y.z */
}

static bool client_handler (mg_connection *c, intptr_t service, int ev)
Expand Down

0 comments on commit 44ed966

Please sign in to comment.