-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathudpsocket.go
61 lines (46 loc) · 1.28 KB
/
udpsocket.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
55
56
57
58
59
60
61
package protocol
import (
"net"
"strconv"
"github.com/vulncheck-oss/go-exploit/output"
)
func UDPConnect(host string, port int) (*net.UDPConn, bool) {
target := host + ":" + strconv.Itoa(port)
output.PrintfFrameworkStatus("Connecting to %s", target)
udpAddr, err := net.ResolveUDPAddr("udp", target)
if err != nil {
output.PrintFrameworkError("ResolveUDPAddr failed: " + err.Error())
return nil, false
}
conn, err := net.DialUDP("udp", nil, udpAddr)
if err != nil {
output.PrintFrameworkError("Connection failed: " + err.Error())
return nil, false
}
return conn, true
}
func UDPWrite(conn *net.UDPConn, data []byte) bool {
written, err := conn.Write(data)
if err != nil {
output.PrintFrameworkError("Server write failed: " + err.Error())
return false
}
if written != len(data) {
output.PrintFrameworkError("Failed to write all data")
return false
}
return true
}
func UDPReadAmount(conn *net.UDPConn, amount int) ([]byte, bool) {
reply := make([]byte, amount)
count, err := conn.Read(reply)
if err != nil {
output.PrintFrameworkError("Failed to read from the socket: " + err.Error())
return nil, false
}
if count != amount {
output.PrintFrameworkError("Failed to read specified amount from the socket")
return nil, false
}
return reply, true
}