Esempio n. 1
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
}
Esempio n. 2
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
}
Esempio n. 3
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
}
Esempio n. 4
-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
}