DebugString prints the contents of a DHCP packet for human consumption.
()
| 105 | |
| 106 | // DebugString prints the contents of a DHCP packet for human consumption. |
| 107 | func (p *Packet) DebugString() string { |
| 108 | var b bytes.Buffer |
| 109 | bcast := "Unicast" |
| 110 | if p.Broadcast { |
| 111 | bcast = "Broadcast" |
| 112 | } |
| 113 | fmt.Fprintf(&b, `%s |
| 114 | %#v |
| 115 | %s |
| 116 | MAC: %s |
| 117 | ClientIP: %s |
| 118 | YourIP: %s |
| 119 | ServerIP: %s |
| 120 | RelayIP: %s |
| 121 | |
| 122 | BootServerName: %s |
| 123 | BootFilename: %s |
| 124 | |
| 125 | Options: |
| 126 | `, p.Type, p.TransactionID, bcast, p.HardwareAddr, p.ClientAddr, p.YourAddr, p.ServerAddr, p.RelayAddr, p.BootServerName, p.BootFilename) |
| 127 | |
| 128 | var opts []int |
| 129 | for n := range p.Options { |
| 130 | opts = append(opts, int(n)) |
| 131 | } |
| 132 | sort.Ints(opts) |
| 133 | for _, n := range opts { |
| 134 | fmt.Fprintf(&b, " %d: %#v\n", n, p.Options[Option(n)]) |
| 135 | } |
| 136 | return b.String() |
| 137 | } |
| 138 | |
| 139 | // Marshal returns the wire encoding of p. |
| 140 | func (p *Packet) Marshal() ([]byte, error) { |