This may be a random question, but do any of you have a working code (preferably C or Lua, without regexes but with regexes works too) for: 1) checking if a given string is a valid IPv6 address, and 2) checking if this IPv6 address is in the range? It should handle both IPv4 and IPv6. It must handle edge cases (number of chunks being 8, numbers must be less than 65535 if I am correct, then there is some stuff regarding ":::", etc.). There seemed to be too many edge cases, but maybe I was wrong.
The range check should be in the form of "isIPInRange(ip, cidr)", e.g. isIPInRange("192.168.0.255", "192.168.0.0/24").
It is trivial for IPv4, but not so trivial for IPv6.
If you are wondering why I am not asking LLM this, that is because when (at the time) I did attempt, it failed spectacularly, plus hey, it is HN, someone may find it useful and the more eyes the better anyways (to spot bugs, issues, what have you).
replies(1):