|
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" |
@@ -159,25 +160,39 @@ func (r RsdHandshakeResponse) GetServices() map[string]RsdServiceEntry { |
159 | 160 | return r.Services |
160 | 161 | } |
161 | 162 |
|
162 | | -// NewWithAddr creates a new RsdService with the given address and port 58783 using a HTTP2 based XPC connection. |
163 | | -func NewWithAddr(addr string, d DeviceEntry) (RsdService, error) { |
164 | | - return NewWithAddrPort(addr, port, d) |
| 163 | +// NewWithAddrPort creates a new RsdService with the given address and port 58783 using a HTTP2 based XPC connection, |
| 164 | +// connecting to an operating system level TUN device. |
| 165 | +func NewWithAddrPort(addr string, port int) (RsdService, error) { |
| 166 | + conn, err := connectTUN(addr, port) |
| 167 | + if err != nil { |
| 168 | + return RsdService{}, fmt.Errorf("NewWithAddrPort: failed to connect to device: %w", err) |
| 169 | + } |
| 170 | + return newRsdServiceFromTcpConn(conn) |
| 171 | +} |
| 172 | + |
| 173 | +// NewWithAddrDevice creates a new RsdService with the given address and port 58783 using a HTTP2 based XPC connection. |
| 174 | +func NewWithAddrDevice(addr string, d DeviceEntry) (RsdService, error) { |
| 175 | + return NewWithAddrPortDevice(addr, port, d) |
165 | 176 | } |
166 | 177 |
|
167 | | -// NewWithAddrPort creates a new RsdService with the given address and port using a HTTP2 based XPC connection. |
168 | | -func NewWithAddrPort(addr string, port int, d DeviceEntry) (RsdService, error) { |
| 178 | +// NewWithAddrPortDevice creates a new RsdService with the given address and port using a HTTP2 based XPC connection. |
| 179 | +func NewWithAddrPortDevice(addr string, port int, d DeviceEntry) (RsdService, error) { |
169 | 180 | conn, err := ConnectTUNDevice(addr, port, d) |
170 | 181 | if err != nil { |
171 | | - return RsdService{}, fmt.Errorf("NewWithAddrPort: failed to connect to device: %w", err) |
| 182 | + return RsdService{}, fmt.Errorf("NewWithAddrPortTUNDevice: failed to connect to device: %w", err) |
172 | 183 | } |
| 184 | + return newRsdServiceFromTcpConn(conn) |
| 185 | +} |
| 186 | + |
| 187 | +func newRsdServiceFromTcpConn(conn *net.TCPConn) (RsdService, error) { |
173 | 188 | h, err := http.NewHttpConnection(conn) |
174 | 189 | if err != nil { |
175 | | - return RsdService{}, fmt.Errorf("NewWithAddrPort: failed to connect to http2: %w", err) |
| 190 | + return RsdService{}, fmt.Errorf("newRsdServiceFromTcpConn: failed to connect to http2: %w", err) |
176 | 191 | } |
177 | 192 |
|
178 | 193 | x, err := CreateXpcConnection(h) |
179 | 194 | if err != nil { |
180 | | - return RsdService{}, fmt.Errorf("NewWithAddrPort: failed to create xpc connection: %w", err) |
| 195 | + return RsdService{}, fmt.Errorf("newRsdServiceFromTcpConn: failed to create xpc connection: %w", err) |
181 | 196 | } |
182 | 197 |
|
183 | 198 | return RsdService{ |
|
0 commit comments