1
0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-11-23 00:52:00 +01:00

Add proof of concept for CIDR validator

This commit is contained in:
Pavel Odintsov 2015-02-14 20:49:32 +03:00
parent 6c67dd103f
commit 2d9a6ecbba

24
tests/test_cidr.cpp Normal file

@ -0,0 +1,24 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <string>
#include <arpa/inet.h>
#include <iostream>
uint32_t convert_ip_as_string_to_uint(std::string ip) {
struct in_addr ip_addr;
inet_aton(ip.c_str(), &ip_addr);
// in network byte order
return ip_addr.s_addr;
}
int main() {
std::cout<<"network byte order"<<std::endl;
std::cout<<"10.10.10.200/24\tnetwork byte order:"<<convert_ip_as_string_to_uint("10.10.10.200")<<" host byte order:"<<ntohl(convert_ip_as_string_to_uint("10.10.10.200"))<<std::endl;
std::cout<<"10.10.10.0/24\tnetwork byte order:" <<convert_ip_as_string_to_uint("10.10.10.0")<<" host byte order:"<<ntohl(convert_ip_as_string_to_uint("10.10.10.0"))<<std::endl;
}