Skip to content

Commit 769ee96

Browse files
committed
🏪 conn: add separate pktinfo struct
1 parent 1c0a6ff commit 769ee96

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

conn/cmsg.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import "net/netip"
66
const SocketControlMessageBufferSize = socketControlMessageBufferSize
77

88
// SocketControlMessage contains information that can be parsed from or put into socket control messages.
9+
//
10+
// Fields of [Pktinfo] are manually embedded to avoid wasting space.
911
type SocketControlMessage struct {
10-
// PktinfoAddr is the IP address of the network interface the packet was received from.
12+
// PktinfoAddr is the IP address of the network interface the packet was received on, or to send the packet from.
1113
PktinfoAddr netip.Addr
1214

13-
// PktinfoIfindex is the index of the network interface the packet was received from.
15+
// PktinfoIfindex is the index of the network interface the packet was received on, or to send the packet from.
1416
PktinfoIfindex uint32
1517

1618
// SegmentSize is the UDP GRO/GSO segment size.
@@ -29,3 +31,16 @@ func ParseSocketControlMessage(cmsg []byte) (m SocketControlMessage, err error)
2931
func (m SocketControlMessage) AppendTo(b []byte) []byte {
3032
return m.appendTo(b)
3133
}
34+
35+
// Pktinfo represents packet information as specified in RFC 3542.
36+
//
37+
// For received packets, it contains the destination IP address and the arriving interface index.
38+
//
39+
// For outgoing packets, it can specify the source IP address and the outgoing interface index.
40+
type Pktinfo struct {
41+
// Addr is the IP address of the network interface the packet was received on, or to send the packet from.
42+
Addr netip.Addr
43+
44+
// Ifindex is the index of the network interface the packet was received on, or to send the packet from.
45+
Ifindex uint32
46+
}

0 commit comments

Comments
 (0)