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) Unpack(buf *packet.Buffer) error { var versihl uint8 buf.ReadN(&versihl) p.Version = versihl >> 4 p.IHL = versihl & 0x0F buf.ReadN(&p.TOS) buf.ReadN(&p.Length) buf.ReadN(&p.Id) var flagsfrag uint16 buf.ReadN(&flagsfrag) p.Flags = Flags(flagsfrag >> 13) p.FragOff = flagsfrag & 0x1FFF buf.ReadN(&p.TTL) buf.ReadN(&p.Protocol) buf.ReadN(&p.Checksum) p.SrcAddr = net.IP(buf.Next(4)) p.DstAddr = net.IP(buf.Next(4)) /* TODO: Options */ return nil }
func (p *Packet) Unpack(buf *packet.Buffer) error { buf.ReadN(&p.Type) buf.ReadN(&p.AddrType) buf.ReadN(&p.AddrLen) p.SrcAddr = net.HardwareAddr(buf.Next(int(p.AddrLen))) buf.Next(8 - int(p.AddrLen)) buf.ReadN(&p.EtherType) return nil }
func (p *Packet) Unpack(buf *packet.Buffer) error { p.DstAddr = net.HardwareAddr(buf.Next(6)) p.SrcAddr = net.HardwareAddr(buf.Next(6)) buf.ReadN(&p.Type) if p.Type < 0x0600 { p.Length = uint16(p.Type) p.Type = LLC } return nil }
func (p *Packet) Unpack(buf *packet.Buffer) error { buf.ReadN(&p.HWType) buf.ReadN(&p.ProtoType) buf.ReadN(&p.HWAddrLen) buf.ReadN(&p.ProtoAddrLen) buf.ReadN(&p.Operation) p.HWSrcAddr = net.HardwareAddr(buf.Next(int(p.HWAddrLen))) p.ProtoSrcAddr = net.IP(buf.Next(int(p.ProtoAddrLen))) p.HWDstAddr = net.HardwareAddr(buf.Next(int(p.HWAddrLen))) p.ProtoDstAddr = net.IP(buf.Next(int(p.ProtoAddrLen))) return nil }
func (p *Packet) Unpack(buf *packet.Buffer) error { buf.ReadN(&p.SrcPort) buf.ReadN(&p.DstPort) buf.ReadN(&p.Seq) buf.ReadN(&p.Ack) var offns uint8 buf.ReadN(&offns) p.DataOff = offns >> 4 if offns&0x01 != 0 { p.Flags |= NS } var flags uint8 buf.ReadN(&flags) if flags&0x01 != 0 { p.Flags |= Fin } if flags&0x02 != 0 { p.Flags |= Syn } if flags&0x04 != 0 { p.Flags |= Rst } if flags&0x08 != 0 { p.Flags |= PSH } if flags&0x10 != 0 { p.Flags |= Ack } if flags&0x20 != 0 { p.Flags |= Urg } if flags&0x40 != 0 { p.Flags |= ECE } if flags&0x80 != 0 { p.Flags |= Cwr } buf.ReadN(&p.WindowSize) buf.ReadN(&p.Checksum) buf.ReadN(&p.Urgent) options: for buf.LayerLen() < int(p.DataOff)*4 { var opt_type OptType buf.ReadN(&opt_type) switch opt_type { case End: /* end of options */ break options case Nop: /* padding */ continue default: opt := Option{Type: opt_type} buf.ReadN(&opt.Len) opt.Data = buf.Next(int(opt.Len) - 2) p.Options = append(p.Options, opt) } } /* remove padding */ if buf.LayerLen() < int(p.DataOff)*4 { buf.Next(int(p.DataOff)*4 - buf.LayerLen()) } return nil }
func (p *Packet) Unpack(buf *packet.Buffer) error { p.Data = buf.Next(buf.Len()) return nil }