-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created examples directory and adjusted README
- Loading branch information
1 parent
51ac989
commit 89df477
Showing
10 changed files
with
192 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
.*.swp | ||
examples/client6/client6 | ||
examples/client4/client4 | ||
examples/packetcrafting6/packetcrafting6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# DHCPv6 client | ||
|
||
A minimal DHCPv6 client can be implemented in a few lines of code, by using the default | ||
client parameters. The example in [main.go](./main.go) lets you specify the | ||
interface to send packets through, and defaults to `eth0`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# DHCPv6 packet crafting | ||
|
||
It is easy to parse, create and manipulate DHCPv6 packets. The `DHCPv6` | ||
interface is the central way to move packets around. Two concrete | ||
implementations, `DHCPv6Message` and `DHCPv6Relay` take care of the | ||
details. The example in [main.go](./main.go) shows how to craft a DHCP6 | ||
Solicit message with a custom DUID_LLT, encapsulate it in a Relay message, | ||
and print its details. | ||
|
||
|
||
The output (slightly modified for readability) is | ||
``` | ||
$ go run main.go | ||
2018/11/08 13:56:31 DHCPv6Relay | ||
messageType=RELAY-FORW | ||
hopcount=0 | ||
linkaddr=2001:db8::1 | ||
peeraddr=2001:db8::2 | ||
options=[OptRelayMsg{relaymsg=DHCPv6Message(messageType=SOLICIT transactionID=0x9e0242, 4 options)}] | ||
2018/11/08 13:56:31 [12 0 32 1 13 184 0 0 0 0 0 0 0 0 0 0 0 1 32 1 13 184 | ||
0 0 0 0 0 0 0 0 0 0 0 2 0 9 0 52 1 158 2 66 0 1 0 14 | ||
0 1 0 1 35 118 253 15 0 250 206 176 12 0 0 6 0 4 0 23 | ||
0 24 0 8 0 2 0 0 0 3 0 12 250 206 176 12 0 0 14 16 0 | ||
0 21 24] | ||
``` |
Oops, something went wrong.