Compare our IP parser against inet_pton
This commit is contained in:
parent
9ae8b4b8d5
commit
21d6536a13
12
test/ip.cpp
12
test/ip.cpp
@ -4,6 +4,7 @@
|
|||||||
#include "../debug.hpp"
|
#include "../debug.hpp"
|
||||||
#include "../types.hpp"
|
#include "../types.hpp"
|
||||||
|
|
||||||
|
#include <arpa/inet.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
|
||||||
@ -21,8 +22,15 @@ main (int argc, char **argv) {
|
|||||||
{ "127.0.0.1", { 127, 0, 0, 1 } }
|
{ "127.0.0.1", { 127, 0, 0, 1 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
for (unsigned int i = 0; i < elems (data); ++i)
|
for (unsigned int i = 0; i < elems (data); ++i) {
|
||||||
check_hard (ipv4::ip::parse (data[i].str) == data[i].ip);
|
ipv4::ip parsed (ipv4::ip::parse (data[i].str));
|
||||||
|
check_hard (parsed == data[i].ip);
|
||||||
|
|
||||||
|
uint32_t mine = *(uint32_t*)(parsed.m_octets),
|
||||||
|
theirs;
|
||||||
|
check_hard (inet_pton (AF_INET, data[i].str, &theirs) == 1);
|
||||||
|
check_hard (theirs == mine);
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user