本文整理汇总了Golang中github.com/d2g/dhcp4.Packet.StripOptions方法的典型用法代码示例。如果您正苦于以下问题:Golang Packet.StripOptions方法的具体用法?Golang Packet.StripOptions怎么用?Golang Packet.StripOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/d2g/dhcp4.Packet
的用法示例。
在下文中一共展示了Packet.StripOptions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}