func TypeToEtherType(pkttype packet.Type) EtherType {
    if pkttype == packet.VLAN {
        return VLAN
    }
    for e, t := range ethertype_to_type_map {
        if t == pkttype {
            return e
        }
    }
    return None
}
Convert the Type to the corresponding EtherType.
package eth
import "fmt"
import "net"
import "github.com/ghedo/go.pkt/packet"
type Packet struct {
    DstAddr     net.HardwareAddr `string:"dst"`
    SrcAddr     net.HardwareAddr `string:"src"`
    Type        EtherType
    Length      uint16           `cmp:"skip"`
    pkt_payload packet.Packet    `cmp:"skip" string:"skip"`
}
type EtherType uint16
const (
    None EtherType = 0x0000
    ARP            = 0x0806
    IPv4           = 0x0800
    IPv6           = 0x86dd
    LLC            = 0x0001   
    LLDP           = 0x088cc
    QinQ           = 0x88a8
    TRILL          = 0x22f3
    VLAN           = 0x8100
    WoL            = 0x0842
)
func Make() *Packet {
    return &Packet{
        DstAddr: make([]byte, 6),
        SrcAddr: make([]byte, 6),
        Length:  14,
    }
}
func (p *Packet) Equals(other packet.Packet) bool {
    return packet.Compare(p, other)
}
func (p *Packet) Answers(other packet.Packet) bool {
    if other == nil || other.GetType() != packet.Eth {
        return false
    }
    if p.Type != other.(*Packet).Type {
        return false
    }
    if p.Payload() != nil {
        return p.Payload().Answers(other.Payload())
    }
    return true
}
func (p *Packet) GetType() packet.Type {
    return packet.Eth
}
func (p *Packet) GetLength() uint16 {
    if p.pkt_payload != nil {
        return p.pkt_payload.GetLength() + 14
    }
    return 14
}
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
}
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) Payload() packet.Packet {
    return p.pkt_payload
}
func (p *Packet) GuessPayloadType() packet.Type {
    return EtherTypeToType(p.Type)
}
func (p *Packet) SetPayload(pl packet.Packet) error {
    p.pkt_payload = pl
    p.Type        = TypeToEtherType(pl.GetType())
    if p.Type < 0x0600 {
        p.Length = p.GetLength()
    }
    return nil
}
func (p *Packet) InitChecksum(csum uint32) {
}
func (p *Packet) String() string {
    return packet.Stringify(p)
}
var ethertype_to_type_map = map[EtherType]packet.Type{
    None:  packet.None,
    ARP:   packet.ARP,
    IPv4:  packet.IPv4,
    IPv6:  packet.IPv6,
    LLC:   packet.LLC,
    LLDP:  packet.LLDP,
    VLAN:  packet.VLAN,
    QinQ:  packet.VLAN,
    TRILL: packet.TRILL,
    WoL:   packet.WoL,
}
func EtherTypeToType(ethertype EtherType) packet.Type {
    for e, t := range ethertype_to_type_map {
        if e == ethertype {
            return t
        }
    }
    return packet.Raw
}