func (d *afpacket) Write(from ethernet.Frame) (err error) { copy(d.sockaddrLL.Addr[:6], []byte(from.Destination())) err = unix.Sendto(d.fd, []byte(from), 0, d.sockaddrLL) if err != nil { return } return }
func TestReadFrame(t *testing.T) { var ( ifce *net.Interface err error d Dev ) if ifce, err = net.InterfaceByName(*dev); err != nil { t.Fatalf("getting interface error: %v", err) } d, err = NewDev(ifce, nil) if err != nil { t.Fatal(err) } var to ethernet.Frame for i := 0; i < 16; i++ { err = d.Read(&to) t.Logf("got frame: from %v to %v (ethertype %v): % x\n", to.Source(), to.Destination(), to.Ethertype(), to.Payload()) if err != nil { t.Fatal(err) } } err = d.Close() if err != nil { t.Fatal(err) } for i := 0; i < 1024; i++ { err = d.Read(&to) if err != nil { break } } if err == nil { t.Fatal("closed Dev can still read") } }