-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cpp
45 lines (36 loc) · 983 Bytes
/
utils.cpp
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
#include "pch.h"
#include "stdafx.h"
#include "utils.h"
CString MACAddr2CString(const MAC_Address& addr) {
CString strAddr, strTmp;
for (int i = 0; i < 6; i++) {
strTmp.Format(_T("%02X"), addr.bytes[i]);
strAddr += strTmp + _T("-");
}
strAddr.Delete(strAddr.GetLength() - 1);
return strAddr;
}
CString IPAddr2CString(const IP_Address& addr) {
CString strAddr, strTmp;
for (int i = 0; i < 3; i++) {
strTmp.Format(_T("%d"), addr.bytes[i]);
strAddr += strTmp + _T(".");
}
strTmp.Format(_T("%d"), addr.bytes[3]);
strAddr += strTmp;
return strAddr;
}
CString IPv6Addr2CString(const IPv6_Address& addr) {
CString strAddr, strTmp;
for (int i = 0; i < 7; i++) {
strTmp.Format(_T("%02X"), addr.bytes[2*i]);
strAddr += strTmp;
strTmp.Format(_T("%02X"), addr.bytes[2 * i + 1]);
strAddr += strTmp + _T(":");
}
strTmp.Format(_T("%02X"), addr.bytes[14]);
strAddr += strTmp;
strTmp.Format(_T("%02X"), addr.bytes[15]);
strAddr += strTmp;
return strAddr;
}