mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 02:58:20 +00:00
GH-340: Improve IPv4/IPv6 regexes, extraction, and validity functions
* is_valid_ip() is now implemented as a BIF instead of in base/utils/addrs * The IPv4 and IPv6 regular expressions provided by base/utils/addrs have been improved/corrected (previously they could possibly match some invalid IPv4 decimals, or various "zero compressed" IPv6 strings with too many hextets) * extract_ip_addresses() should give better results as a result of the above two points
This commit is contained in:
parent
9421ee0293
commit
7144661930
8 changed files with 200 additions and 106 deletions
29
src/IPAddr.h
29
src/IPAddr.h
|
@ -68,7 +68,7 @@ public:
|
|||
*/
|
||||
IPAddr(const std::string& s)
|
||||
{
|
||||
Init(s);
|
||||
Init(s.data());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -366,6 +366,29 @@ public:
|
|||
|
||||
unsigned int MemoryAllocation() const { return padded_sizeof(*this); }
|
||||
|
||||
/**
|
||||
* Converts an IPv4 or IPv6 string into a network address structure
|
||||
* (IPv6 or v4-to-v6-mapping in network bytes order).
|
||||
*
|
||||
* @param s the IPv4 or IPv6 string to convert (ASCII, NUL-terminated).
|
||||
*
|
||||
* @param result buffer that the caller supplies to store the result.
|
||||
*
|
||||
* @return whether the conversion was successful.
|
||||
*/
|
||||
static bool ConvertString(const char* s, in6_addr* result);
|
||||
|
||||
/**
|
||||
* @param s the IPv4 or IPv6 string to convert (ASCII, NUL-terminated).
|
||||
*
|
||||
* @return whether the string is a valid IP address
|
||||
*/
|
||||
static bool IsValid(const char* s)
|
||||
{
|
||||
in6_addr tmp;
|
||||
return ConvertString(s, &tmp);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class IPPrefix;
|
||||
|
||||
|
@ -373,9 +396,9 @@ private:
|
|||
* Initializes an address instance from a string representation.
|
||||
*
|
||||
* @param s String containing an IP address as either a dotted IPv4
|
||||
* address or a hex IPv6 address.
|
||||
* address or a hex IPv6 address (ASCII, NUL-terminated).
|
||||
*/
|
||||
void Init(const std::string& s);
|
||||
void Init(const char* s);
|
||||
|
||||
in6_addr in6; // IPv6 or v4-to-v6-mapped address
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue