func (p *Packet) Unpack(buf *packet.Buffer) error { var versclass uint8 buf.ReadN(&versclass) p.Version = versclass >> 4 p.Class = uint8((binary.BigEndian.Uint16(buf.LayerBytes()[0:2]) >> 4) & 0x00FF) p.Label = binary.BigEndian.Uint32(buf.LayerBytes()[0:4]) & 0x000FFFFF buf.Next(3) buf.ReadN(&p.Length) buf.ReadN(&p.NextHdr) buf.ReadN(&p.HopLimit) p.SrcAddr = net.IP(buf.Next(16)) p.DstAddr = net.IP(buf.Next(16)) /* TODO: Options */ return nil }
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 }
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 }
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 }
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 }
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 }