Untitled

C++ Detected boxlabs 17 Views Size: 544 bytes Posted on: Sep 15, 25 @ 6:08 PM
  1. 1#include <arpa/inet.h> // for inet_pton
  2. 2
  3. 3static int is_ipv4_prefix(const char *host, size_t *prefix_len)
  4. 4{
  5. 5 size_t i = 0;
  6. 6 while (host[i] && ((host[i] >= '0' && host[i] <= '9') || host[i] == '.'))
  7. 7 i++;
  8. 8 if (i == 0)
  9. 9 return 0;
  10. 10 char buf[32];
  11. 11 if (i >= sizeof(buf)) // too long to be valid IPv4
  12. 12 return 0;
  13. 13 memcpy(buf, host, i);
  14. 14 buf[i] = '\0';
  15. 15 struct in_addr addr;
  16. 16 if (inet_pton(AF_INET, buf, &addr) == 1) {
  17. 17 *prefix_len = i;
  18. 18 return 1;
  19. 19 }
  20. 20 return 0;
  21. 21}

Raw Paste

Comments 0
Login to post a comment.
  • No comments yet. Be the first.
Login to post a comment. Login or Register
We use cookies. To comply with GDPR in the EU and the UK we have to show you these.

We use cookies and similar technologies to keep this website functional (including spam protection via Google reCAPTCHA), and — with your consent — to measure usage and show ads. See Privacy.