本文整理汇总了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
}