@@ -21,6 +21,8 @@ var rawConnectionConfig = &raw.Config{
21
21
22
22
// NewRawUDPConn returns a UDP connection bound to the interface and port
23
23
// given based on a raw packet socket. All packets are broadcasted.
24
+ //
25
+ // The interface can be completely unconfigured.
24
26
func NewRawUDPConn (iface string , port int , vlans ... uint16 ) (net.PacketConn , error ) {
25
27
ifc , err := net .InterfaceByName (iface )
26
28
if err != nil {
@@ -34,6 +36,7 @@ func NewRawUDPConn(iface string, port int, vlans ...uint16) (net.PacketConn, err
34
36
etherType = etherIPv4Proto
35
37
}
36
38
39
+ // Create a bidirectional raw socket on ifc with etherType as the filter
37
40
rawConn , err := raw .ListenPacket (ifc , etherType , rawConnectionConfig )
38
41
if err != nil {
39
42
return nil , err
@@ -66,12 +69,12 @@ func NewBroadcastUDPConn(rawPacketConn net.PacketConn, boundAddr *net.UDPAddr, v
66
69
67
70
// ReadFrom implements net.PacketConn.ReadFrom.
68
71
//
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.
71
74
//
72
75
// Any matching packets are returned via the given buffer.
73
76
func (upc * BroadcastRawUDPConn ) ReadFrom (b []byte ) (int , net.Addr , error ) {
74
- ethHdrLen := ethHdrMinimum
77
+ ethHdrLen := ethHdrBaseLen
75
78
if len (upc .VLANs ) > 0 {
76
79
ethHdrLen += len (upc .VLANs ) * vlanTagLen
77
80
}
0 commit comments