-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIPV4.hpp
47 lines (40 loc) · 987 Bytes
/
IPV4.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <iostream>
#include <cmath>
struct UsableHost
{
uint8_t* startHost;
uint8_t* endHost;
};
class IPV4
{
private:
static bool isDot(char c);
static uint8_t* stos(const std::string& str);
static uint8_t* inverse(const uint8_t* addr);
uint8_t* ip;
public:
void setIp(const std::string& ipAddr);
void setSubnet(const std::string& subnetAddr);
private:
uint8_t* subnet;
uint8_t* networkId;
uint8_t* broadcastId;
void calculateNetworkId();
void calculateBroadcastId();
void calculateTotalHosts();
UsableHost hostsId;
uint numberOfHosts;
public:
IPV4();
IPV4(const std::string& ipAddr, const std::string& subnetAddr);
uint8_t* getIp();
uint8_t* getSubnet();
uint8_t* getNetworkId();
uint8_t* getBroadcastId();
UsableHost getHostsId();
uint getNumberOfHosts();
uint getUsableNumberOfHosts() const;
void update();
static std::string to_string(uint8_t *addr);
};