📦 NikithShetty / Virtual-wifi

📄 WlanUtils.cs · 60 lines
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
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using VirtualRouter.Wlan.WinAPI;

namespace VirtualRouter.Wlan
{
    public static class WlanUtils
    {
        [DebuggerStepThrough]
        public static void Throw_On_Win32_Error(uint retCode)
        {
            if (retCode != 0) // 0 = ERROR_SUCCESS
            {
                throw new Win32Exception((int)retCode);
            }
        }

        public static string ConvertToString(this DOT11_MAC_ADDRESS mac)
        {
            var sb = new StringBuilder();

            sb.Append(mac.one.ConvertToHexString());
            sb.Append(":");
            sb.Append(mac.two.ConvertToHexString());
            sb.Append(":");
            sb.Append(mac.three.ConvertToHexString());
            sb.Append(":");
            sb.Append(mac.four.ConvertToHexString());
            sb.Append(":");
            sb.Append(mac.five.ConvertToHexString());
            sb.Append(":");
            sb.Append(mac.six.ConvertToHexString());

            return sb.ToString();
        }

        public static string ConvertToString(this DOT11_SSID ssid)
        {
            return ssid.ucSSID;
        }

        public static string ConvertToHexString(this byte value)
        {
            return Convert.ToString(value, 0x10).PadLeft(2, '0');
        }

        public static DOT11_SSID ConvertStringToDOT11_SSID(string ssid)
        {
            return new DOT11_SSID()
            {
                 ucSSID = ssid,
                uSSIDLength = ssid.Length
            };
        }
    }
}