OLD | NEW |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build darwin dragonfly freebsd linux netbsd openbsd windows | 5 // +build darwin dragonfly freebsd linux netbsd openbsd windows |
6 | 6 |
7 package net | 7 package net |
8 | 8 |
9 import ( | 9 import ( |
10 "syscall" | 10 "syscall" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // DialIP connects to the remote address raddr on the network protocol | 182 // DialIP connects to the remote address raddr on the network protocol |
183 // netProto, which must be "ip", "ip4", or "ip6" followed by a colon | 183 // netProto, which must be "ip", "ip4", or "ip6" followed by a colon |
184 // and a protocol number or name. | 184 // and a protocol number or name. |
185 func DialIP(netProto string, laddr, raddr *IPAddr) (*IPConn, error) { | 185 func DialIP(netProto string, laddr, raddr *IPAddr) (*IPConn, error) { |
186 return dialIP(netProto, laddr, raddr, noDeadline) | 186 return dialIP(netProto, laddr, raddr, noDeadline) |
187 } | 187 } |
188 | 188 |
189 func dialIP(netProto string, laddr, raddr *IPAddr, deadline time.Time) (*IPConn,
error) { | 189 func dialIP(netProto string, laddr, raddr *IPAddr, deadline time.Time) (*IPConn,
error) { |
190 net, proto, err := parseNetwork(netProto) | 190 net, proto, err := parseNetwork(netProto) |
191 if err != nil { | 191 if err != nil { |
192 » » return nil, err | 192 » » return nil, &OpError{Op: "dial", Net: netProto, Addr: raddr, Err
: err} |
193 } | 193 } |
194 switch net { | 194 switch net { |
195 case "ip", "ip4", "ip6": | 195 case "ip", "ip4", "ip6": |
196 default: | 196 default: |
197 » » return nil, UnknownNetworkError(netProto) | 197 » » return nil, &OpError{Op: "dial", Net: netProto, Addr: raddr, Err
: UnknownNetworkError(netProto)} |
198 } | 198 } |
199 if raddr == nil { | 199 if raddr == nil { |
200 » » return nil, &OpError{"dial", netProto, nil, errMissingAddress} | 200 » » return nil, &OpError{Op: "dial", Net: netProto, Addr: nil, Err:
errMissingAddress} |
201 } | 201 } |
202 fd, err := internetSocket(net, laddr, raddr, deadline, syscall.SOCK_RAW,
proto, "dial", sockaddrToIP) | 202 fd, err := internetSocket(net, laddr, raddr, deadline, syscall.SOCK_RAW,
proto, "dial", sockaddrToIP) |
203 if err != nil { | 203 if err != nil { |
204 » » return nil, err | 204 » » return nil, &OpError{Op: "dial", Net: netProto, Addr: raddr, Err
: err} |
205 } | 205 } |
206 return newIPConn(fd), nil | 206 return newIPConn(fd), nil |
207 } | 207 } |
208 | 208 |
209 // ListenIP listens for incoming IP packets addressed to the local | 209 // ListenIP listens for incoming IP packets addressed to the local |
210 // address laddr. The returned connection's ReadFrom and WriteTo | 210 // address laddr. The returned connection's ReadFrom and WriteTo |
211 // methods can be used to receive and send IP packets with per-packet | 211 // methods can be used to receive and send IP packets with per-packet |
212 // addressing. | 212 // addressing. |
213 func ListenIP(netProto string, laddr *IPAddr) (*IPConn, error) { | 213 func ListenIP(netProto string, laddr *IPAddr) (*IPConn, error) { |
214 net, proto, err := parseNetwork(netProto) | 214 net, proto, err := parseNetwork(netProto) |
215 if err != nil { | 215 if err != nil { |
216 » » return nil, err | 216 » » return nil, &OpError{Op: "dial", Net: netProto, Addr: laddr, Err
: err} |
217 } | 217 } |
218 switch net { | 218 switch net { |
219 case "ip", "ip4", "ip6": | 219 case "ip", "ip4", "ip6": |
220 default: | 220 default: |
221 » » return nil, UnknownNetworkError(netProto) | 221 » » return nil, &OpError{Op: "listen", Net: netProto, Addr: laddr, E
rr: UnknownNetworkError(netProto)} |
222 } | 222 } |
223 fd, err := internetSocket(net, laddr, nil, noDeadline, syscall.SOCK_RAW,
proto, "listen", sockaddrToIP) | 223 fd, err := internetSocket(net, laddr, nil, noDeadline, syscall.SOCK_RAW,
proto, "listen", sockaddrToIP) |
224 if err != nil { | 224 if err != nil { |
225 » » return nil, err | 225 » » return nil, &OpError{Op: "listen", Net: netProto, Addr: laddr, E
rr: err} |
226 } | 226 } |
227 return newIPConn(fd), nil | 227 return newIPConn(fd), nil |
228 } | 228 } |
OLD | NEW |