aboutsummaryrefslogtreecommitdiff
path: root/cmd/example/main.go
blob: 383e490fef54699ecafc50d85a63a3729a953a2b (plain)
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
package main

import (
	"fmt"
	"iptcp/pkg/lnxconfig"
	"net/netip"
	"os"
)

func main() {
	if len(os.Args) != 2 {
		fmt.Printf("Usage:  %s <configFile>\n", os.Args[0])
		os.Exit(1)
	}
	fileName := os.Args[1]

	// Parse the file
	lnxConfig, err := lnxconfig.ParseConfig(fileName)
	if err != nil {
		panic(err)
	}

	// Demo:  print out the IP for each interface in this config
	for _, iface := range lnxConfig.Interfaces {
		prefixForm := netip.PrefixFrom(iface.AssignedIP, iface.AssignedPrefix.Bits())
		fmt.Printf("%s has IP %s\n", iface.Name, prefixForm.String())

		fmt.Printf(iface.UDPAddr.String() + "\n")
		fmt.Printf(iface.AssignedIP.String() + "\n")
	}
}