| 10 | ) |
| 11 | |
| 12 | func TestIPToHex(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | ip string |
| 16 | expected uint32 |
| 17 | }{ |
| 18 | { |
| 19 | name: "10.0.0.1", |
| 20 | ip: "10.0.0.1", |
| 21 | expected: 0x0a000001, |
| 22 | }, |
| 23 | { |
| 24 | name: "192.168.1.100", |
| 25 | ip: "192.168.1.100", |
| 26 | expected: 0xc0a80164, |
| 27 | }, |
| 28 | { |
| 29 | name: "0.0.0.0", |
| 30 | ip: "0.0.0.0", |
| 31 | expected: 0x00000000, |
| 32 | }, |
| 33 | { |
| 34 | name: "255.255.255.255", |
| 35 | ip: "255.255.255.255", |
| 36 | expected: 0xffffffff, |
| 37 | }, |
| 38 | { |
| 39 | name: "127.0.0.1", |
| 40 | ip: "127.0.0.1", |
| 41 | expected: 0x7f000001, |
| 42 | }, |
| 43 | { |
| 44 | name: "172.16.0.1", |
| 45 | ip: "172.16.0.1", |
| 46 | expected: 0xac100001, |
| 47 | }, |
| 48 | } |
| 49 | |
| 50 | for _, tt := range tests { |
| 51 | t.Run(tt.name, func(t *testing.T) { |
| 52 | ip := net.ParseIP(tt.ip) |
| 53 | if ip == nil { |
| 54 | t.Fatalf("failed to parse IP: %s", tt.ip) |
| 55 | } |
| 56 | result := ipToHex(ip) |
| 57 | if result != tt.expected { |
| 58 | t.Errorf("ipToHex(%s) = 0x%08x, want 0x%08x", tt.ip, result, tt.expected) |
| 59 | } |
| 60 | }) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func TestIPToHexOnlyHexOutput(t *testing.T) { |
| 65 | // SECURITY TEST: Verify that output only contains hex digits |