func (this *Option121ClasslessStaticRoute) Construct(routes []Route) error {
	buf := make([]byte, 256)
	idx := 0
	for _, route := range routes {
		if 5+significantBytes(route.Mask)+idx >= len(buf) {
			return dherrors.Opt121TooLong
		}
		buf[idx] = route.Mask
		util.ConvertUint32To4byte(route.Dest, buf[idx+1:idx+5])
		util.ConvertUint32To4byte(route.Gw, buf[idx+1+significantBytes(route.Mask):idx+5+significantBytes(route.Mask)])
		idx += 5 + significantBytes(route.Mask)
	}

	buf = buf[:idx]
	this.rawOpt.Construct(this.GetNum(), byte(len(buf)))
	copy(this.rawOpt.GetValue(), buf)
	return nil
}
func (typ *TypeListUint32) Construct(optNum byte, value []uint32) error {
	if len(value) == 0 {
		return errors.New(fmt.Sprintf("Option %d has invalid null length", optNum))
	}
	typ.rawOpt.Construct(optNum, byte(len(value)*LEN_OPT_U_INT32))
	optData := typ.rawOpt.GetValue()
	for i, v := range value {
		util.ConvertUint32To4byte(v, optData[i*LEN_OPT_U_INT32:(i+1)*LEN_OPT_U_INT32])
	}
	return nil
}
Пример #3
0
func (dp DhcpPacket) SetGiAddr(ip uint32) {
	util.ConvertUint32To4byte(ip, dp.Raw[24:28])
}
Пример #4
0
func (dp DhcpPacket) SetNextServerIp(ip uint32) {
	util.ConvertUint32To4byte(ip, dp.Raw[20:24])
}
Пример #5
0
func (dp DhcpPacket) SetYourIp(ip uint32) {
	util.ConvertUint32To4byte(ip, dp.Raw[16:20])
}
Пример #6
0
func (dp DhcpPacket) SetClientIp(ip uint32) {
	util.ConvertUint32To4byte(ip, dp.Raw[12:16])
}
Пример #7
0
func (tuint32 *TypeUint32) Construct(numOpt byte, number uint32) {
	tuint32.rawOpt.Construct(numOpt, LEN_OPT_U_INT32)
	util.ConvertUint32To4byte(number, tuint32.GetValue())
}