@@ -21,6 +21,8 @@ var rawConnectionConfig = &raw.Config{
2121
2222// NewRawUDPConn returns a UDP connection bound to the interface and port
2323// given based on a raw packet socket. All packets are broadcasted.
24+ //
25+ // The interface can be completely unconfigured.
2426func NewRawUDPConn (iface string , port int , vlans ... uint16 ) (net.PacketConn , error ) {
2527 ifc , err := net .InterfaceByName (iface )
2628 if err != nil {
@@ -34,6 +36,7 @@ func NewRawUDPConn(iface string, port int, vlans ...uint16) (net.PacketConn, err
3436 etherType = etherIPv4Proto
3537 }
3638
39+ // Create a bidirectional raw socket on ifc with etherType as the filter
3740 rawConn , err := raw .ListenPacket (ifc , etherType , rawConnectionConfig )
3841 if err != nil {
3942 return nil , err
@@ -66,12 +69,12 @@ func NewBroadcastUDPConn(rawPacketConn net.PacketConn, boundAddr *net.UDPAddr, v
6669
6770// ReadFrom implements net.PacketConn.ReadFrom.
6871//
69- // ReadFrom reads raw Ethernet packets , parses the VLAN stack (if configured)
70- // and will try to match the IP+UDP destinations against upc.boundAddr.
72+ // ReadFrom reads raw Ethernet frames , parses and matches the VLAN stack (if configured),
73+ // and will try to match the remaining IP packet against upc.boundAddr.
7174//
7275// Any matching packets are returned via the given buffer.
7376func (upc * BroadcastRawUDPConn ) ReadFrom (b []byte ) (int , net.Addr , error ) {
74- ethHdrLen := ethHdrMinimum
77+ ethHdrLen := ethHdrBaseLen
7578 if len (upc .VLANs ) > 0 {
7679 ethHdrLen += len (upc .VLANs ) * vlanTagLen
7780 }
0 commit comments