Esempio n. 1
0
func (p *Packet) ChangeOtherTunnelId(tunnelId uint64) {
	p.OtherTunnelId = tunnelId
	data := utils.Uint64ToBytes(tunnelId)
	for i := OtherTunnelId_INDEX; i < OtherTunnelId_END; i++ {
		p.RawData[p.Start+i] = data[i-OtherTunnelId_INDEX]
	}
}
Esempio n. 2
0
func (p *Packet) genHeader() []byte {
	header := make([]byte, 96)
	dataLenBytes := utils.Int16ToBytes(len(p.RawData) - 96)
	copy(header[Length_INDEX:Length_END], dataLenBytes)

	tunnelIdBytes := utils.Uint64ToBytes(p.TunnelId)
	copy(header[TunnelId_INDEX:TunnelId_END], tunnelIdBytes)

	sessionIdBytes := utils.Uint32ToBytes(p.SessionId)
	copy(header[SessionId_INDEX:SessionId_END], sessionIdBytes)

	packetIdBytes := utils.Uint32ToBytes(p.Id)
	copy(header[Id_INDEX:Id_END], packetIdBytes)

	// 传输层协议类型
	header[ProtoType_INDEX] = p.ProtoType

	// 包类型
	header[PacketType_INDEX] = p.PacketType

	// other 长度
	header[OtherLen_INDEX] = byte(p.OtherLen)
	count := OtherLen_INDEX + 1
	if p.OtherLen != 0 && p.OtherLen == len(p.Dst) {
		dstBytes := []byte(p.Dst)
		copy(header[OtherLen_INDEX+1:OtherLen_INDEX+1+p.OtherLen], dstBytes)
		count += len(dstBytes)
	} else {
		//p.LOG.Println("error udppacket genHeader OtherLen not match len(Dst)")
		header[OtherLen_INDEX] = byte(0)
	}
	return header[:count]
}