20 #include <arpa/inet.h> 31 static uint32_t g_Options = 0;
34 void convert(std::string &out, T t)
55 IpAddress() : m_Type(IPv4), m_Ipv4(0), m_Ipv6(), m_bSet(false){};
56 IpAddress(
IpType type) : m_Type(type), m_Ipv4(0), m_Ipv6(), m_bSet(
false){};
58 : m_Type(IPv4), m_Ipv4(ipv4), m_Ipv6(), m_bSet(
true){};
59 IpAddress(uint8_t *ipv6) : m_Type(IPv6), m_Ipv4(0), m_Ipv6(), m_bSet(
true)
61 memcpy(m_Ipv6, ipv6, 16);
69 memset(m_Ipv6, 0, 16);
74 void setIp(uint8_t *ipv6)
77 memcpy(m_Ipv6, ipv6, 16);
89 inline void getIp(uint8_t *ipv6)
92 memcpy(ipv6, m_Ipv6, 16);
127 return (a.
getIp() == getIp());
137 if (getType() == IPv4)
138 return (a == getIp());
151 convert<uint32_t>(tmp, m_Ipv4 & 0xff);
154 convert<uint32_t>(tmp, (m_Ipv4 >> 8) & 0xff);
157 convert<uint32_t>(tmp, (m_Ipv4 >> 16) & 0xff);
160 convert<uint32_t>(tmp, (m_Ipv4 >> 24) & 0xff);
179 NetworkDevice() : name(
""), ipv4(), subnet(), gateway(), dns(){};
186 vector<IpAddress> dns;
196 dev.ipv4 = 0x0100007f;
200 m_Devices.push_back(dev);
202 dev.ipv4 = inet_addr(
"10.0.0.2");
204 dev.gateway = inet_addr(
"10.0.0.1");
205 dev.dns.push_back(inet_addr(
"10.0.0.10"));
206 dev.dns.push_back(inet_addr(
"10.0.0.11"));
207 dev.dns.push_back(inet_addr(
"10.0.0.12"));
208 dev.dns.push_back(inet_addr(
"10.0.0.13"));
209 m_Devices.push_back(dev);
212 dev.ipv4 = inet_addr(
"192.168.1.100");
214 dev.gateway = inet_addr(
"192.168.1.254");
215 dev.dns.push_back(inet_addr(
"192.168.1.254"));
216 m_Devices.push_back(dev);
228 vector<NetworkDevice> &getDevices()
236 vector<NetworkDevice> m_Devices;
242 int main(
int argc,
char *argv[])
245 for (
int arg = 1; arg < argc; arg++)
251 vector<Pedigree::NetworkDevice> devices =
252 Pedigree::Network::instance().getDevices();
253 for (vector<Pedigree::NetworkDevice>::iterator it = devices.begin();
254 it != devices.end(); ++it)
257 cout <<
"Device '" << dev.name <<
"':" << endl;
258 cout <<
"\tIPv4: " << dev.ipv4.
toString()
260 <<
", Gateway: " << dev.gateway.
toString() << endl;
261 cout <<
"\tDNS servers:";
262 for (vector<Pedigree::IpAddress>::iterator dns = dev.dns.begin();
263 dns != dev.dns.end(); ++dns)
264 cout <<
" " << (*dns).toString();
IpAddress & operator=(IpAddress a)
bool operator==(const Iterator< originalT, Struct, FunctionPrev, FunctionNext, T1 > &x1, const Iterator< originalT, Struct, FunctionPrev, FunctionNext, T2 > &x2)
void setIp(uint32_t ipv4)