Exemple #1
0
func (p *Packet) Pack(buf *packet.Buffer) error {
	tci := uint16(p.Priority)<<13 | p.VLAN
	if p.DropEligible {
		tci |= 0x10
	}

	buf.WriteN(tci)
	buf.WriteN(p.Type)

	return nil
}
Exemple #2
0
func (p *Packet) Pack(buf *packet.Buffer) error {
	buf.Write(p.DstAddr)
	buf.Write(p.SrcAddr)

	if p.Type != LLC {
		buf.WriteN(p.Type)
	} else {
		buf.WriteN(p.Length)
	}

	return nil
}
Exemple #3
0
func (p *Packet) Pack(buf *packet.Buffer) error {
	buf.WriteN(p.Type)
	buf.WriteN(p.AddrType)
	buf.WriteN(p.AddrLen)
	buf.WriteN(p.SrcAddr)

	for i := 0; i < 8-int(p.AddrLen); i++ {
		buf.WriteN(uint8(0x00))
	}

	buf.WriteN(p.EtherType)

	return nil
}
Exemple #4
0
func (p *Packet) Pack(buf *packet.Buffer) error {
	buf.WriteN(p.HWType)
	buf.WriteN(p.ProtoType)

	buf.WriteN(p.HWAddrLen)
	buf.WriteN(p.ProtoAddrLen)

	buf.WriteN(p.Operation)

	buf.Write(p.HWSrcAddr[len(p.HWSrcAddr)-int(p.HWAddrLen):])
	buf.Write(p.ProtoSrcAddr[len(p.ProtoSrcAddr)-int(p.ProtoAddrLen):])

	buf.Write(p.HWDstAddr[len(p.HWDstAddr)-int(p.HWAddrLen):])
	buf.Write(p.ProtoDstAddr[len(p.ProtoDstAddr)-int(p.ProtoAddrLen):])

	return nil
}
Exemple #5
0
func (p *Packet) Pack(buf *packet.Buffer) error {
	buf.WriteN(p.DSAP)
	buf.WriteN(p.SSAP)

	if p.Control&0x1 == 0 || p.Control&0x3 == 0x1 {
		buf.WriteN(p.Control)
	} else {
		buf.WriteN(uint8(p.Control))
	}

	return nil
}
Exemple #6
0
func (p *Packet) Pack(buf *packet.Buffer) error {
	buf.WriteN(byte(p.Type))
	buf.WriteN(byte(p.Code))
	buf.WriteN(uint16(0x00))
	buf.WriteN(p.Body)

	if p.csum_seed != 0 {
		p.Checksum = ipv4.CalculateChecksum(buf.LayerBytes(), p.csum_seed)
		buf.PutUint16N(2, p.Checksum)
	}

	return nil
}
Exemple #7
0
func (p *Packet) Pack(buf *packet.Buffer) error {
	buf.WriteN(p.SrcPort)
	buf.WriteN(p.DstPort)
	buf.WriteN(p.Length)

	if p.csum_seed != 0 {
		p.Checksum =
			ipv4.CalculateChecksum(buf.LayerBytes(), p.csum_seed)
	}

	buf.WriteN(p.Checksum)

	return nil
}
Exemple #8
0
func (p *Packet) Pack(buf *packet.Buffer) error {
	buf.WriteN(p.OUI)
	buf.WriteN(p.Type)

	return nil
}
Exemple #9
0
func (p *Packet) Pack(buf *packet.Buffer) error {
	buf.WriteN((p.Version << 4) | p.IHL)
	buf.WriteN(p.TOS)
	buf.WriteN(p.Length)
	buf.WriteN(p.Id)
	buf.WriteN((uint16(p.Flags) << 13) | p.FragOff)
	buf.WriteN(p.TTL)
	buf.WriteN(p.Protocol)
	buf.WriteN(uint16(0x00))
	buf.Write(p.SrcAddr.To4())
	buf.Write(p.DstAddr.To4())

	p.checksum(buf.LayerBytes()[:20])
	buf.PutUint16N(10, p.Checksum)

	return nil
}
Exemple #10
0
func (p *Packet) Pack(buf *packet.Buffer) error {
	buf.WriteN(p.SrcPort)
	buf.WriteN(p.DstPort)
	buf.WriteN(p.Seq)
	buf.WriteN(p.Ack)

	flags := uint16(p.DataOff) << 12

	if p.Flags&Fin != 0 {
		flags |= 0x0001
	}

	if p.Flags&Syn != 0 {
		flags |= 0x0002
	}

	if p.Flags&Rst != 0 {
		flags |= 0x0004
	}

	if p.Flags&PSH != 0 {
		flags |= 0x0008
	}

	if p.Flags&Ack != 0 {
		flags |= 0x0010
	}

	if p.Flags&Urg != 0 {
		flags |= 0x0020
	}

	if p.Flags&ECE != 0 {
		flags |= 0x0040
	}

	if p.Flags&Cwr != 0 {
		flags |= 0x0080
	}

	if p.Flags&NS != 0 {
		flags |= 0x0100
	}

	buf.WriteN(flags)

	buf.WriteN(p.WindowSize)
	buf.WriteN(uint16(0x0000))
	buf.WriteN(p.Urgent)

	for _, opt := range p.Options {
		buf.WriteN(opt.Type)
		buf.WriteN(opt.Len)
		buf.WriteN(opt.Data)
	}

	if p.csum_seed != 0 {
		p.Checksum =
			ipv4.CalculateChecksum(buf.LayerBytes(), p.csum_seed)
	}

	buf.PutUint16N(16, p.Checksum)

	/* add padding */
	for buf.LayerLen() < int(p.DataOff)*4 {
		buf.WriteN(uint8(0x00))
	}

	return nil
}
Exemple #11
0
func (p *Packet) Pack(buf *packet.Buffer) error {
	buf.WriteN(uint8(p.Version<<4 | (p.Class >> 4)))
	buf.WriteN(p.Class<<4 | uint8(p.Label>>16))
	buf.WriteN(uint16(p.Label))

	buf.WriteN(p.Length)
	buf.WriteN(p.NextHdr)
	buf.WriteN(p.HopLimit)

	buf.Write(p.SrcAddr.To16())
	buf.Write(p.DstAddr.To16())

	return nil
}
Exemple #12
-1
func (p *Packet) Pack(buf *packet.Buffer) error {
	buf.WriteN(byte(p.Type))
	buf.WriteN(byte(p.Code))
	buf.WriteN(uint16(0x0000))
	buf.WriteN(p.Id)
	buf.WriteN(p.Seq)

	p.Checksum = ipv4.CalculateChecksum(buf.LayerBytes(), 0)
	buf.PutUint16N(2, p.Checksum)

	return nil
}