main.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2018-present the CoreDHCP Authors. All rights reserved
  2. // This source code is licensed under the MIT license found in the
  3. // LICENSE file in the root directory of this source tree.
  4. package main
  5. /*
  6. * Sample DHCPv6 client to test on the local interface
  7. */
  8. import (
  9. "flag"
  10. "net"
  11. "github.com/coredhcp/coredhcp/logger"
  12. "github.com/insomniacslk/dhcp/dhcpv6"
  13. "github.com/insomniacslk/dhcp/dhcpv6/client6"
  14. "github.com/insomniacslk/dhcp/iana"
  15. )
  16. var log = logger.GetLogger("main")
  17. func main() {
  18. flag.Parse()
  19. var macString string
  20. if len(flag.Args()) > 0 {
  21. macString = flag.Arg(0)
  22. } else {
  23. macString = "00:11:22:33:44:55"
  24. }
  25. c := client6.NewClient()
  26. c.LocalAddr = &net.UDPAddr{
  27. IP: net.ParseIP("::1"),
  28. Port: 546,
  29. }
  30. c.RemoteAddr = &net.UDPAddr{
  31. IP: net.ParseIP("::1"),
  32. Port: 547,
  33. }
  34. log.Printf("%+v", c)
  35. mac, err := net.ParseMAC(macString)
  36. if err != nil {
  37. log.Fatal(err)
  38. }
  39. duid := dhcpv6.DUIDLLT{
  40. HWType: iana.HWTypeEthernet,
  41. Time: dhcpv6.GetTime(),
  42. LinkLayerAddr: mac,
  43. }
  44. conv, err := c.Exchange("lo", dhcpv6.WithClientID(&duid))
  45. for _, p := range conv {
  46. log.Print(p.Summary())
  47. }
  48. if err != nil {
  49. log.Fatal(err)
  50. }
  51. }