summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-10-11 01:25:13 +0300
committerGravatar Nikias Bassen2021-10-12 03:17:07 +0300
commitfa8bfb65c70edd4d2617fbbf970302beb9a4ced2 (patch)
tree08bf90044dcda6073368e7f62d3f629984e1bb90
parentb3d35fbcf7a1ac669c2e80fbd58920941a5d4c0c (diff)
downloadlibimobiledevice-fa8bfb65c70edd4d2617fbbf970302beb9a4ced2.tar.gz
libimobiledevice-fa8bfb65c70edd4d2617fbbf970302beb9a4ced2.tar.bz2
idevice: Add IDEVICE_E_CONNREFUSED and have idevice_connect() return meaningful error codes
This allows clients to properly detect that a connection to the requested port failed because it is not open on the device, instead of just returning an "unknown error"
-rw-r--r--include/libimobiledevice/libimobiledevice.h1
-rw-r--r--src/idevice.c19
2 files changed, 18 insertions, 2 deletions
diff --git a/include/libimobiledevice/libimobiledevice.h b/include/libimobiledevice/libimobiledevice.h
index e0aa518..40edd71 100644
--- a/include/libimobiledevice/libimobiledevice.h
+++ b/include/libimobiledevice/libimobiledevice.h
@@ -42,6 +42,7 @@ typedef enum {
IDEVICE_E_UNKNOWN_ERROR = -2,
IDEVICE_E_NO_DEVICE = -3,
IDEVICE_E_NOT_ENOUGH_DATA = -4,
+ IDEVICE_E_CONNREFUSED = -5,
IDEVICE_E_SSL_ERROR = -6,
IDEVICE_E_TIMEOUT = -7
} idevice_error_t;
diff --git a/src/idevice.c b/src/idevice.c
index 6a03c5e..04189d6 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -447,7 +447,15 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t
if (device->conn_type == CONNECTION_USBMUXD) {
int sfd = usbmuxd_connect(device->mux_id, port);
if (sfd < 0) {
- debug_info("ERROR: Connecting to usbmuxd failed: %d (%s)", sfd, strerror(-sfd));
+ debug_info("ERROR: Connecting to usbmux device failed: %d (%s)", sfd, strerror(-sfd));
+ switch (-sfd) {
+ case ECONNREFUSED:
+ return IDEVICE_E_CONNREFUSED;
+ case ENODEV:
+ return IDEVICE_E_NO_DEVICE;
+ default:
+ break;
+ }
return IDEVICE_E_UNKNOWN_ERROR;
}
idevice_connection_t new_connection = (idevice_connection_t)malloc(sizeof(struct idevice_connection_private));
@@ -494,7 +502,14 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t
int sfd = socket_connect_addr(saddr, port);
if (sfd < 0) {
- debug_info("ERROR: Connecting to network device failed: %d (%s)", errno, strerror(errno));
+ int result = errno;
+ debug_info("ERROR: Connecting to network device failed: %d (%s)", result, strerror(result));
+ switch (result) {
+ case ECONNREFUSED:
+ return IDEVICE_E_CONNREFUSED;
+ default:
+ break;
+ }
return IDEVICE_E_NO_DEVICE;
}