#include // for inet_pton static int is_ipv4_prefix(const char *host, size_t *prefix_len) { size_t i = 0; while (host[i] && ((host[i] >= '0' && host[i] <= '9') || host[i] == '.')) i++; if (i == 0) return 0; char buf[32]; if (i >= sizeof(buf)) // too long to be valid IPv4 return 0; memcpy(buf, host, i); buf[i] = '\0'; struct in_addr addr; if (inet_pton(AF_INET, buf, &addr) == 1) { *prefix_len = i; return 1; } return 0; }