|
4 | 4 | "encoding/json"
|
5 | 5 | "fmt"
|
6 | 6 | "io"
|
| 7 | + "net" |
7 | 8 | "strconv"
|
8 | 9 |
|
9 | 10 | "github.com/danielpaulus/go-ios/ios/http"
|
@@ -139,25 +140,39 @@ func (r RsdHandshakeResponse) GetPort(service string) int {
|
139 | 140 | return 0
|
140 | 141 | }
|
141 | 142 |
|
142 |
| -// NewWithAddr creates a new RsdService with the given address and port 58783 using a HTTP2 based XPC connection. |
143 |
| -func NewWithAddr(addr string, d DeviceEntry) (RsdService, error) { |
144 |
| - return NewWithAddrPort(addr, port, d) |
| 143 | +// NewWithAddrPort creates a new RsdService with the given address and port 58783 using a HTTP2 based XPC connection, |
| 144 | +// connecting to an operating system level TUN device. |
| 145 | +func NewWithAddrPort(addr string, port int) (RsdService, error) { |
| 146 | + conn, err := connectTUN(addr, port) |
| 147 | + if err != nil { |
| 148 | + return RsdService{}, fmt.Errorf("NewWithAddrPort: failed to connect to device: %w", err) |
| 149 | + } |
| 150 | + return newRsdServiceFromTcpConn(conn) |
| 151 | +} |
| 152 | + |
| 153 | +// NewWithAddrDevice creates a new RsdService with the given address and port 58783 using a HTTP2 based XPC connection. |
| 154 | +func NewWithAddrDevice(addr string, d DeviceEntry) (RsdService, error) { |
| 155 | + return NewWithAddrPortDevice(addr, port, d) |
145 | 156 | }
|
146 | 157 |
|
147 |
| -// NewWithAddrPort creates a new RsdService with the given address and port using a HTTP2 based XPC connection. |
148 |
| -func NewWithAddrPort(addr string, port int, d DeviceEntry) (RsdService, error) { |
| 158 | +// NewWithAddrPortDevice creates a new RsdService with the given address and port using a HTTP2 based XPC connection. |
| 159 | +func NewWithAddrPortDevice(addr string, port int, d DeviceEntry) (RsdService, error) { |
149 | 160 | conn, err := ConnectTUNDevice(addr, port, d)
|
150 | 161 | if err != nil {
|
151 |
| - return RsdService{}, fmt.Errorf("NewWithAddrPort: failed to connect to device: %w", err) |
| 162 | + return RsdService{}, fmt.Errorf("NewWithAddrPortTUNDevice: failed to connect to device: %w", err) |
152 | 163 | }
|
| 164 | + return newRsdServiceFromTcpConn(conn) |
| 165 | +} |
| 166 | + |
| 167 | +func newRsdServiceFromTcpConn(conn *net.TCPConn) (RsdService, error) { |
153 | 168 | h, err := http.NewHttpConnection(conn)
|
154 | 169 | if err != nil {
|
155 |
| - return RsdService{}, fmt.Errorf("NewWithAddrPort: failed to connect to http2: %w", err) |
| 170 | + return RsdService{}, fmt.Errorf("newRsdServiceFromTcpConn: failed to connect to http2: %w", err) |
156 | 171 | }
|
157 | 172 |
|
158 | 173 | x, err := CreateXpcConnection(h)
|
159 | 174 | if err != nil {
|
160 |
| - return RsdService{}, fmt.Errorf("NewWithAddrPort: failed to create xpc connection: %w", err) |
| 175 | + return RsdService{}, fmt.Errorf("newRsdServiceFromTcpConn: failed to create xpc connection: %w", err) |
161 | 176 | }
|
162 | 177 |
|
163 | 178 | return RsdService{
|
|
0 commit comments