| 10 | ) |
| 11 | |
| 12 | func createRequestData(version, command uint8, ip net.IP, port uint16) []byte { |
| 13 | // set the command |
| 14 | b := []byte{version, command, 0} |
| 15 | |
| 16 | // append the ip |
| 17 | if len(ip) == net.IPv4len { |
| 18 | b = append(b, 1) |
| 19 | b = append(b, ip.To4()...) |
| 20 | } else { |
| 21 | b = append(b, 4) |
| 22 | b = append(b, ip.To16()...) |
| 23 | } |
| 24 | |
| 25 | // append the port |
| 26 | p := []byte{0, 0} |
| 27 | binary.BigEndian.PutUint16(p, port) |
| 28 | b = append(b, p...) |
| 29 | |
| 30 | return b |
| 31 | } |
| 32 | |
| 33 | func createRequest(t *testing.T, version, command uint8, ipStr string, port uint16, shouldFail bool) *Request { |
| 34 | ip := net.ParseIP(ipStr) |