本文整理匯總了Golang中github.com/d2g/dhcp4.Packet.AddOption方法的典型用法代碼示例。如果您正苦於以下問題:Golang Packet.AddOption方法的具體用法?Golang Packet.AddOption怎麽用?Golang Packet.AddOption使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/d2g/dhcp4.Packet
的用法示例。
在下文中一共展示了Packet.AddOption方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setOptions
// setOptions sets dhcp options on a dhcp packet
func (c *client) setOptions(p dhcp4.Packet) (dhcp4.Packet, error) {
defer trace.End(trace.Begin(""))
dirty := false
opts := p.ParseOptions()
// the current parameter request list
rl := opts[dhcp4.OptionParameterRequestList]
// figure out if there are any new parameters
for _, p := range c.params {
if bytes.IndexByte(rl, p) == -1 {
dirty = true
rl = append(rl, p)
}
}
opts[dhcp4.OptionParameterRequestList] = rl
if _, ok := opts[dhcp4.OptionClientIdentifier]; !ok {
b, err := c.id.MarshalBinary()
if err != nil {
return p, err
}
opts[dhcp4.OptionClientIdentifier] = b
dirty = true
}
// finally reset the options on the packet, if necessary
if dirty {
// strip out all options, and add them back in with the new changed options;
// this is the only way currently to delete/modify a packet option
p.StripOptions()
// have to copy since values in opts (of type []byte) are still pointing into p
var newp dhcp4.Packet
newp = make([]byte, len(p))
copy(newp, p)
log.Debugf("opts=%#v", opts)
for o, v := range opts {
newp.AddOption(o, v)
}
p = newp
}
return p, nil
}
示例2: appendOptions
func (c *client) appendOptions(p *dhcp4.Packet, id ID) (*dhcp4.Packet, error) {
p.AddOption(
dhcp4.OptionParameterRequestList,
[]byte{
byte(dhcp4.OptionSubnetMask),
byte(dhcp4.OptionRouter),
byte(dhcp4.OptionDomainNameServer),
},
)
b, err := id.MarshalBinary()
if err != nil {
return nil, err
}
p.AddOption(dhcp4.OptionClientIdentifier, b)
return p, nil
}