summaryrefslogtreecommitdiffhomepage
path: root/examples/client6/main.go
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2019-01-28 10:47:25 +0000
committerinsomniac <insomniacslk@users.noreply.github.com>2019-01-28 11:21:18 +0000
commit89df4777a1687cf4d796afc91b30fa0beee7506d (patch)
tree43976d43185df5bf610104c2f1466e309dcb28e0 /examples/client6/main.go
parent51ac989e85d13beda9cb304fb85e0aff18e9cd98 (diff)
Created examples directory and adjusted README
Diffstat (limited to 'examples/client6/main.go')
-rw-r--r--examples/client6/main.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/client6/main.go b/examples/client6/main.go
new file mode 100644
index 0000000..41cf692
--- /dev/null
+++ b/examples/client6/main.go
@@ -0,0 +1,42 @@
+package main
+
+import (
+ "flag"
+ "log"
+
+ "github.com/insomniacslk/dhcp/dhcpv6/client6"
+)
+
+var (
+ iface = flag.String("i", "eth0", "Interface to configure via DHCPv6")
+)
+
+func main() {
+ flag.Parse()
+ log.Printf("Starting DHCPv6 client on interface %s", *iface)
+
+ // NewClient sets up a new DHCPv6 client with default values
+ // for read and write timeouts, for destination address and listening
+ // address
+ client := client6.NewClient()
+
+ // Exchange runs a Solicit-Advertise-Request-Reply transaction on the
+ // specified network interface, and returns a list of DHCPv6 packets
+ // (a "conversation") and an error if any. Notice that Exchange may
+ // return a non-empty packet list even if there is an error. This is
+ // intended, because the transaction may fail at any point, and we
+ // still want to know what packets were exchanged until then.
+ // A default Solicit packet will be used during the "conversation",
+ // which can be manipulated by using modifiers.
+ conversation, err := client.Exchange(*iface)
+
+ // Summary() prints a verbose representation of the exchanged packets.
+ for _, packet := range conversation {
+ log.Print(packet.Summary())
+ }
+ // error handling is done *after* printing, so we still print the
+ // exchanged packets if any, as explained above.
+ if err != nil {
+ log.Fatal(err)
+ }
+}