-
Notifications
You must be signed in to change notification settings - Fork 2
/
socket_windows.go
54 lines (43 loc) · 857 Bytes
/
socket_windows.go
1
2
3
4
5
6
7
8
9
10
11
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
package wpaclient
import (
"fmt"
"net"
)
var socketType = "UDP"
func localSocket(i int) string {
return ""
}
func dial(addr string) (*socket, error) {
if addr == "" {
addr = "127.0.0.1:9878"
}
remote, err := net.ResolveUDPAddr("udp", addr)
if err != nil {
return nil, fmt.Errorf("could not resolve udp address: %w", err)
}
c, err := net.DialUDP("udp",
&net.UDPAddr{},
remote,
)
if err != nil {
return nil, fmt.Errorf("dial failed: %w", err)
}
return &socket{c: c}, nil
}
func (s *Socket) close() error {
return s.c.close()
}
func testServerConn() (*net.UDPConn, func(), error) {
addr, err := net.ResolveUDPAddr("udp", "127.0.0.1:0")
if err != nil {
return nil, nil, err
}
con, err := net.ListenUDP("udp", addr)
if err != nil {
return nil, func() {}, err
}
fn := func() {
con.Close()
}
return con, fn, nil
}