1
2
3
4
5 package ipv4
6
7 import (
8 "net"
9 "runtime"
10
11 "golang.org/x/net/internal/socket"
12 )
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 type Message = socket.Message
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 func (c *payloadHandler) ReadBatch(ms []Message, flags int) (int, error) {
75 if !c.ok() {
76 return 0, errInvalidConn
77 }
78 switch runtime.GOOS {
79 case "linux":
80 n, err := c.RecvMsgs([]socket.Message(ms), flags)
81 if err != nil {
82 err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
83 }
84 return n, err
85 default:
86 n := 1
87 err := c.RecvMsg(&ms[0], flags)
88 if err != nil {
89 n = 0
90 err = &net.OpError{Op: "read", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
91 }
92 if compatFreeBSD32 && ms[0].NN > 0 {
93 adjustFreeBSD32(&ms[0])
94 }
95 return n, err
96 }
97 }
98
99
100
101
102
103
104
105
106
107
108 func (c *payloadHandler) WriteBatch(ms []Message, flags int) (int, error) {
109 if !c.ok() {
110 return 0, errInvalidConn
111 }
112 switch runtime.GOOS {
113 case "linux":
114 n, err := c.SendMsgs([]socket.Message(ms), flags)
115 if err != nil {
116 err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
117 }
118 return n, err
119 default:
120 n := 1
121 err := c.SendMsg(&ms[0], flags)
122 if err != nil {
123 n = 0
124 err = &net.OpError{Op: "write", Net: c.PacketConn.LocalAddr().Network(), Source: c.PacketConn.LocalAddr(), Err: err}
125 }
126 return n, err
127 }
128 }
129
130
131
132
133
134
135
136
137
138
139
140 func (c *packetHandler) ReadBatch(ms []Message, flags int) (int, error) {
141 if !c.ok() {
142 return 0, errInvalidConn
143 }
144 switch runtime.GOOS {
145 case "linux":
146 n, err := c.RecvMsgs([]socket.Message(ms), flags)
147 if err != nil {
148 err = &net.OpError{Op: "read", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
149 }
150 return n, err
151 default:
152 n := 1
153 err := c.RecvMsg(&ms[0], flags)
154 if err != nil {
155 n = 0
156 err = &net.OpError{Op: "read", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
157 }
158 if compatFreeBSD32 && ms[0].NN > 0 {
159 adjustFreeBSD32(&ms[0])
160 }
161 return n, err
162 }
163 }
164
165
166
167
168
169
170
171
172
173
174 func (c *packetHandler) WriteBatch(ms []Message, flags int) (int, error) {
175 if !c.ok() {
176 return 0, errInvalidConn
177 }
178 switch runtime.GOOS {
179 case "linux":
180 n, err := c.SendMsgs([]socket.Message(ms), flags)
181 if err != nil {
182 err = &net.OpError{Op: "write", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
183 }
184 return n, err
185 default:
186 n := 1
187 err := c.SendMsg(&ms[0], flags)
188 if err != nil {
189 n = 0
190 err = &net.OpError{Op: "write", Net: c.IPConn.LocalAddr().Network(), Source: c.IPConn.LocalAddr(), Err: err}
191 }
192 return n, err
193 }
194 }
195
View as plain text