Skip to content

Use libimobiledevice idevice_connection_get_fd #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions src/webinspector.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,21 @@ struct wi_private {
// CONNECT
//

// based on libimobiledevice/src/idevice.h
enum connection_type {
CONNECTION_USBMUXD = 1
};
struct idevice_connection_private {
char *udid; // added in v1.1.6
enum connection_type type;
void *data;
void *ssl_data;
};

wi_status idevice_connection_get_fd(idevice_connection_t connection,
wi_status idevice_connection_get_fd_wrapper(idevice_connection_t connection,
int *to_fd) {
if (!connection || !to_fd) {
return WI_ERROR;
}
idevice_connection_private *c = (
(sizeof(*connection) == sizeof(idevice_connection_private)) ?
(idevice_connection_private *) connection : NULL);
if (!c || c->type != CONNECTION_USBMUXD || c->data <= 0 || c->ssl_data) {
perror("Invalid idevice_connection struct. Please verify that "
__FILE__ "'s idevice_connection_private matches your version of"
" libimbiledevice/src/idevice.h");

int fd;
idevice_error_t err = idevice_connection_get_fd(connection, &fd);
if (err < 0) {
return WI_ERROR;
}
int fd = (int)(long)c->data;

struct stat fd_stat;
if (fstat(fd, &fd_stat) < 0 || !S_ISSOCK(fd_stat.st_mode)) {
perror("idevice_connection fd is not a socket?");
return WI_ERROR;
}

*to_fd = fd;
return WI_SUCCESS;
}
Expand Down Expand Up @@ -134,7 +118,7 @@ int wi_connect(const char *device_id, char **to_device_id,
}

// extract the connection fd
if (idevice_connection_get_fd(connection, &fd)) {
if (idevice_connection_get_fd_wrapper(connection, &fd)) {
perror("Unable to get connection file descriptor.");
goto leave_cleanup;
}
Expand Down