Documentation ¶
Index ¶
- func IPAdd(start net.IP, add int) net.IP
- func IPInRange(start, stop, ip net.IP) bool
- func IPLess(a, b net.IP) bool
- func IPRange(start, stop net.IP) int
- func JoinIPs(ips []net.IP) (b []byte)
- func OptionsLeaseTime(d time.Duration) []byte
- type MessageType
- type OpCode
- type Option
- type OptionCode
- type Options
- type Packet
- func (p *Packet) AddOption(o OptionCode, value []byte)
- func (p Packet) Broadcast() bool
- func (p Packet) CHAddr() net.HardwareAddr
- func (p Packet) CIAddr() net.IP
- func (p Packet) Cookie() []byte
- func (p Packet) Flags() []byte
- func (p Packet) GIAddr() net.IP
- func (p Packet) HLen() byte
- func (p Packet) HType() byte
- func (p Packet) Hops() byte
- func (p Packet) OpCode() OpCode
- func (p Packet) Options() []byte
- func (p *Packet) PadToMinSize()
- func (p Packet) ParseOptions() Options
- func (p Packet) SIAddr() net.IP
- func (p Packet) Secs() []byte
- func (p Packet) SetBroadcast(broadcast bool)
- func (p Packet) SetCHAddr(a net.HardwareAddr)
- func (p Packet) SetCIAddr(ip net.IP)
- func (p Packet) SetCookie(cookie []byte)
- func (p Packet) SetFlags(flags []byte)
- func (p Packet) SetGIAddr(ip net.IP)
- func (p Packet) SetHType(hType byte)
- func (p Packet) SetHops(hops byte)
- func (p Packet) SetOpCode(c OpCode)
- func (p Packet) SetSIAddr(ip net.IP)
- func (p Packet) SetSecs(secs []byte)
- func (p Packet) SetXId(xId []byte)
- func (p Packet) SetYIAddr(ip net.IP)
- func (p *Packet) StripOptions()
- func (p Packet) XId() []byte
- func (p Packet) YIAddr() net.IP
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IPAdd ¶
IPAdd returns a copy of start + add. IPAdd(net.IP{192,168,1,1},30) returns net.IP{192.168.1.31}
func JoinIPs ¶
JoinIPs returns a byte slice of IP addresses, one immediately after the other This may be useful for creating multiple IP options such as OptionRouter.
func OptionsLeaseTime ¶
OptionsLeaseTime - converts a time.Duration to a 4 byte slice, compatible with OptionIPAddressLeaseTime.
Types ¶
type MessageType ¶
type MessageType byte // Option 53
const ( Discover MessageType = 1 // Broadcast Packet From Client - Can I have an IP? Offer MessageType = 2 // Broadcast From Server - Here's an IP Request MessageType = 3 // Broadcast From Client - I'll take that IP (Also start for renewals) Decline MessageType = 4 // Broadcast From Client - Sorry I can't use that IP ACK MessageType = 5 // From Server, Yes you can have that IP NAK MessageType = 6 // From Server, No you cannot have that IP Release MessageType = 7 // From Client, I don't need that IP anymore Inform MessageType = 8 // From Client, I have this IP and there's nothing you can do about it )
DHCP Message Type 53
type Option ¶
type Option struct { Code OptionCode Value []byte }
type OptionCode ¶
type OptionCode byte
const ( End OptionCode = 255 Pad OptionCode = 0 OptionSubnetMask OptionCode = 1 OptionTimeOffset OptionCode = 2 OptionRouter OptionCode = 3 OptionTimeServer OptionCode = 4 OptionNameServer OptionCode = 5 OptionDomainNameServer OptionCode = 6 OptionLogServer OptionCode = 7 OptionCookieServer OptionCode = 8 OptionLPRServer OptionCode = 9 OptionImpressServer OptionCode = 10 OptionResourceLocationServer OptionCode = 11 OptionHostName OptionCode = 12 OptionBootFileSize OptionCode = 13 OptionMeritDumpFile OptionCode = 14 OptionDomainName OptionCode = 15 OptionSwapServer OptionCode = 16 OptionRootPath OptionCode = 17 OptionExtensionsPath OptionCode = 18 // IP Layer Parameters per Host OptionIPForwardingEnableDisable OptionCode = 19 OptionNonLocalSourceRoutingEnableDisable OptionCode = 20 OptionPolicyFilter OptionCode = 21 OptionMaximumDatagramReassemblySize OptionCode = 22 OptionDefaultIPTimeToLive OptionCode = 23 OptionPathMTUAgingTimeout OptionCode = 24 OptionPathMTUPlateauTable OptionCode = 25 // IP Layer Parameters per Interface OptionInterfaceMTU OptionCode = 26 OptionAllSubnetsAreLocal OptionCode = 27 OptionBroadcastAddress OptionCode = 28 OptionPerformMaskDiscovery OptionCode = 29 OptionMaskSupplier OptionCode = 30 OptionPerformRouterDiscovery OptionCode = 31 OptionRouterSolicitationAddress OptionCode = 32 OptionStaticRoute OptionCode = 33 // Link Layer Parameters per Interface OptionTrailerEncapsulation OptionCode = 34 OptionARPCacheTimeout OptionCode = 35 OptionEthernetEncapsulation OptionCode = 36 // TCP Parameters OptionTCPDefaultTTL OptionCode = 37 OptionTCPKeepaliveInterval OptionCode = 38 OptionTCPKeepaliveGarbage OptionCode = 39 // Application and Service Parameters OptionNetworkInformationServiceDomain OptionCode = 40 OptionNetworkInformationServers OptionCode = 41 OptionNetworkTimeProtocolServers OptionCode = 42 OptionVendorSpecificInformation OptionCode = 43 OptionNetBIOSOverTCPIPNameServer OptionCode = 44 OptionNetBIOSOverTCPIPDatagramDistributionServer OptionCode = 45 OptionNetBIOSOverTCPIPNodeType OptionCode = 46 OptionNetBIOSOverTCPIPScope OptionCode = 47 OptionXWindowSystemFontServer OptionCode = 48 OptionXWindowSystemDisplayManager OptionCode = 49 OptionNetworkInformationServicePlusDomain OptionCode = 64 OptionNetworkInformationServicePlusServers OptionCode = 65 OptionMobileIPHomeAgent OptionCode = 68 OptionSimpleMailTransportProtocol OptionCode = 69 OptionPostOfficeProtocolServer OptionCode = 70 OptionNetworkNewsTransportProtocol OptionCode = 71 OptionDefaultWorldWideWebServer OptionCode = 72 OptionDefaultFingerServer OptionCode = 73 OptionDefaultInternetRelayChatServer OptionCode = 74 OptionStreetTalkServer OptionCode = 75 OptionStreetTalkDirectoryAssistance OptionCode = 76 // DHCP Extensions OptionRequestedIPAddress OptionCode = 50 OptionIPAddressLeaseTime OptionCode = 51 OptionOverload OptionCode = 52 OptionDHCPMessageType OptionCode = 53 OptionServerIdentifier OptionCode = 54 OptionParameterRequestList OptionCode = 55 OptionMessage OptionCode = 56 OptionMaximumDHCPMessageSize OptionCode = 57 OptionRenewalTimeValue OptionCode = 58 OptionRebindingTimeValue OptionCode = 59 OptionVendorClassIdentifier OptionCode = 60 OptionClientIdentifier OptionCode = 61 OptionTFTPServerName OptionCode = 66 OptionBootFileName OptionCode = 67 OptionUserClass OptionCode = 77 OptionClientArchitecture OptionCode = 93 OptionTZPOSIXString OptionCode = 100 OptionTZDatabaseString OptionCode = 101 OptionClasslessRouteFormat OptionCode = 121 )
DHCP Options
type Options ¶
type Options map[OptionCode][]byte
Map of DHCP options
func (Options) SelectOrder ¶
SelectOrder returns a slice of options ordered and selected by a byte array usually defined by OptionParameterRequestList. This result is expected to be used in ReplyPacket()'s []Option parameter.
func (Options) SelectOrderOrAll ¶
SelectOrderOrAll has same functionality as SelectOrder, except if the order param is nil, whereby all options are added (in arbitrary order).
type Packet ¶
type Packet []byte
A DHCP packet
func ReplyPacket ¶
func ReplyPacket(req Packet, mt MessageType, serverId, yIAddr net.IP, leaseDuration time.Duration, options []Option) Packet
ReplyPacket creates a reply packet that a Server would send to a client. It uses the req Packet param to copy across common/necessary fields to associate the reply the request.
func RequestPacket ¶
func RequestPacket(mt MessageType, chAddr net.HardwareAddr, cIAddr net.IP, xId []byte, broadcast bool, options []Option) Packet
Creates a request packet that a Client would send to a server.
func (*Packet) AddOption ¶
func (p *Packet) AddOption(o OptionCode, value []byte)
Appends a DHCP option to the end of a packet
func (Packet) CHAddr ¶
func (p Packet) CHAddr() net.HardwareAddr
func (*Packet) PadToMinSize ¶
func (p *Packet) PadToMinSize()
func (Packet) ParseOptions ¶
Parses the packet's options into an Options map
func (Packet) SetBroadcast ¶
func (Packet) SetCHAddr ¶
func (p Packet) SetCHAddr(a net.HardwareAddr)