diff options
| -rw-r--r-- | .github/FUNDING.yml | 3 | ||||
| -rw-r--r-- | .github/workflows/build.yml | 14 | ||||
| -rw-r--r-- | Makefile.am | 1 | ||||
| -rw-r--r-- | NEWS | 11 | ||||
| -rw-r--r-- | README.md | 6 | ||||
| -rw-r--r-- | configure.ac | 4 | ||||
| -rw-r--r-- | include/usbmuxd-proto.h | 16 | ||||
| -rw-r--r-- | src/libusbmuxd.c | 27 | ||||
| -rw-r--r-- | tools/inetcat.c | 32 | ||||
| -rw-r--r-- | tools/iproxy.c | 40 |
10 files changed, 100 insertions, 54 deletions
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..e995b30 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +github: nikias +patreon: nikias +custom: ["https://www.paypal.me/NikiasBassen"] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 56248c5..199d0f8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,7 @@ name: build on: push: + pull_request: schedule: - cron: '0 0 1 * *' @@ -13,14 +14,14 @@ jobs: run: | echo "target_triplet=`gcc -dumpmachine`" >> $GITHUB_ENV - name: fetch libplist - uses: dawidd6/action-download-artifact@v3 + uses: dawidd6/action-download-artifact@v6 with: github_token: ${{secrets.GITHUB_TOKEN}} workflow: build.yml name: libplist-latest_${{env.target_triplet}} repo: libimobiledevice/libplist - name: fetch libimobiledevice-glue - uses: dawidd6/action-download-artifact@v3 + uses: dawidd6/action-download-artifact@v6 with: github_token: ${{secrets.GITHUB_TOKEN}} workflow: build.yml @@ -63,14 +64,14 @@ jobs: fi shell: bash - name: fetch libplist - uses: dawidd6/action-download-artifact@v3 + uses: dawidd6/action-download-artifact@v6 with: github_token: ${{secrets.GITHUB_TOKEN}} workflow: build.yml name: libplist-latest_macOS repo: libimobiledevice/libplist - name: fetch libimobiledevice-glue - uses: dawidd6/action-download-artifact@v3 + uses: dawidd6/action-download-artifact@v6 with: github_token: ${{secrets.GITHUB_TOKEN}} workflow: build.yml @@ -133,6 +134,7 @@ jobs: base-devel git mingw-w64-${{ matrix.arch }}-gcc + mingw-w64-${{ matrix.arch }}-pkg-config make libtool autoconf @@ -144,14 +146,14 @@ jobs: echo "target_triplet=`gcc -dumpmachine`" >> $GITHUB_ENV git config --global core.autocrlf false - name: fetch libplist - uses: dawidd6/action-download-artifact@v3 + uses: dawidd6/action-download-artifact@v6 with: github_token: ${{secrets.GITHUB_TOKEN}} workflow: build.yml name: libplist-latest_${{ matrix.arch }}-${{ env.dest }} repo: libimobiledevice/libplist - name: fetch libimobiledevice-glue - uses: dawidd6/action-download-artifact@v3 + uses: dawidd6/action-download-artifact@v6 with: github_token: ${{secrets.GITHUB_TOKEN}} workflow: build.yml diff --git a/Makefile.am b/Makefile.am index 5ca15d0..559d84c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,4 +7,5 @@ EXTRA_DIST = \ git-version-gen dist-hook: + @if ! git diff --quiet; then echo "Uncommitted changes present; not releasing"; exit 1; fi echo $(VERSION) > $(distdir)/.tarball-version @@ -1,3 +1,14 @@ +Version 2.1.1 +~~~~~~~~~~~~~ + +* Changes: + - tools: Fix potential issue with select() in case the network fd is higher than the usbmux fd + - Switch to better initializer strategy + - Fix compilation on MSVC + - iproxy: Make sure to print correct socket error messages + - inetcat: Make sure to report correct error messages + + Version 2.1.0 ~~~~~~~~~~~~~ @@ -258,8 +258,8 @@ Please make sure your contribution adheres to: ## Links * Homepage: https://libimobiledevice.org/ -* Repository: https://git.libimobiledevice.org/libusbmuxd.git -* Repository (Mirror): https://github.com/libimobiledevice/libusbmuxd.git +* Repository: https://github.com/libimobiledevice/libusbmuxd.git +* Repository (Mirror): https://git.libimobiledevice.org/libusbmuxd.git * Issue Tracker: https://github.com/libimobiledevice/libusbmuxd/issues * Mailing List: https://lists.libimobiledevice.org/mailman/listinfo/libimobiledevice-devel * Twitter: https://twitter.com/libimobiledev @@ -279,4 +279,4 @@ iPadOS, tvOS, watchOS, and macOS are trademarks of Apple Inc. This project is an independent software library and has not been authorized, sponsored, or otherwise approved by Apple Inc. -README Updated on: 2024-03-27 +README Updated on: 2024-10-22 diff --git a/configure.ac b/configure.ac index facf678..6a78d08 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ dnl libtool versioning # changes to the signature and the semantic) # ? :+1 : ? == just internal changes # CURRENT : REVISION : AGE -LIBUSBMUXD_SO_VERSION=7:0:0 +LIBUSBMUXD_SO_VERSION=7:1:0 AC_SUBST(LIBUSBMUXD_SO_VERSION) @@ -69,7 +69,7 @@ AC_TYPE_UINT32_T AC_TYPE_UINT8_T # Checks for library functions. -AC_CHECK_FUNCS([strcasecmp strdup strerror stpncpy sleep malloc realloc getifaddrs]) +AC_CHECK_FUNCS([strcasecmp strdup strerror stpncpy malloc realloc getifaddrs]) # Check for operating system AC_MSG_CHECKING([for platform-specific build settings]) diff --git a/include/usbmuxd-proto.h b/include/usbmuxd-proto.h index a2a731e..d004232 100644 --- a/include/usbmuxd-proto.h +++ b/include/usbmuxd-proto.h @@ -26,7 +26,7 @@ #include <stdint.h> #define USBMUXD_PROTOCOL_VERSION 0 -#if defined(WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) #define USBMUXD_SOCKET_PORT 27015 #else #define USBMUXD_SOCKET_FILE "/var/run/usbmuxd" @@ -57,28 +57,30 @@ enum usbmuxd_msgtype { MESSAGE_PLIST = 8, }; +#pragma pack(push, 1) + struct usbmuxd_header { uint32_t length; // length of message, including header uint32_t version; // protocol version uint32_t message; // message type uint32_t tag; // responses to this query will echo back this tag -} __attribute__((__packed__)); +}; struct usbmuxd_result_msg { struct usbmuxd_header header; uint32_t result; -} __attribute__((__packed__)); +}; struct usbmuxd_connect_request { struct usbmuxd_header header; uint32_t device_id; uint16_t port; // TCP port number uint16_t reserved; // set to zero -} __attribute__((__packed__)); +}; struct usbmuxd_listen_request { struct usbmuxd_header header; -} __attribute__((__packed__)); +}; struct usbmuxd_device_record { uint32_t device_id; @@ -86,7 +88,9 @@ struct usbmuxd_device_record { char serial_number[256]; uint16_t padding; uint32_t location; -} __attribute__((__packed__)); +}; + +#pragma pack(pop) #ifdef __cplusplus } diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c index 8329bef..6b7d220 100644 --- a/src/libusbmuxd.c +++ b/src/libusbmuxd.c @@ -51,16 +51,13 @@ #define ECONNREFUSED 107 #endif -#include <unistd.h> -#include <signal.h> - -#ifdef WIN32 +#ifdef _WIN32 #include <winsock2.h> #include <windows.h> -#ifndef HAVE_SLEEP #define sleep(x) Sleep(x*1000) -#endif #else +#include <unistd.h> +#include <signal.h> #include <sys/socket.h> #include <arpa/inet.h> #if defined(HAVE_PROGRAM_INVOCATION_SHORT_NAME) && !defined(HAVE_PROGRAM_INVOCATION_SHORT_NAME_ERRNO_H) @@ -93,8 +90,11 @@ static char* stpncpy(char *dst, const char *src, size_t len) } #endif +#ifdef _MSC_VER +#define strcasecmp _stricmp +#endif + #include <plist/plist.h> -#define PLIST_CLIENT_VERSION_STRING PACKAGE_STRING #define PLIST_LIBUSBMUX_VERSION 3 static char *bundle_id = NULL; @@ -115,6 +115,9 @@ static int libusbmuxd_debug = 0; #ifndef PACKAGE #define PACKAGE "libusbmuxd" #endif +#ifndef PACKAGE_NAME +#define PACKAGE_NAME PACKAGE +#endif #define LIBUSBMUXD_DEBUG(level, format, ...) if (level <= libusbmuxd_debug) fprintf(stderr, ("[" PACKAGE "] " format), __VA_ARGS__); fflush(stderr); #define LIBUSBMUXD_ERROR(format, ...) LIBUSBMUXD_DEBUG(0, format, __VA_ARGS__) @@ -164,7 +167,7 @@ static int connect_usbmuxd_socket() char *usbmuxd_socket_addr = getenv("USBMUXD_SOCKET_ADDRESS"); if (usbmuxd_socket_addr) { if (strncmp(usbmuxd_socket_addr, "UNIX:", 5) == 0) { -#if defined(WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) /* not supported, ignore */ #else if (usbmuxd_socket_addr[5] != '\0') { @@ -215,7 +218,7 @@ static int connect_usbmuxd_socket() } } } -#if defined(WIN32) || defined(__CYGWIN__) +#if defined(_WIN32) || defined(__CYGWIN__) res = socket_connect("127.0.0.1", USBMUXD_SOCKET_PORT); #else res = socket_connect_unix(USBMUXD_SOCKET_FILE); @@ -660,7 +663,7 @@ static void get_prog_name() if (pname) { prog_name = strdup(pname); } -#elif defined (WIN32) +#elif defined (_WIN32) TCHAR *_pname = malloc((MAX_PATH+1) * sizeof(TCHAR)); if (GetModuleFileName(NULL, _pname, MAX_PATH+1) > 0) { char* pname = NULL; @@ -721,6 +724,8 @@ static void get_prog_name() static plist_t create_plist_message(const char* message_type) { + char client_version[128]; + snprintf(client_version, 128, PACKAGE_NAME " %s", libusbmuxd_version()); if (!bundle_id) { get_bundle_id(); } @@ -731,7 +736,7 @@ static plist_t create_plist_message(const char* message_type) if (bundle_id) { plist_dict_set_item(plist, "BundleID", plist_new_string(bundle_id)); } - plist_dict_set_item(plist, "ClientVersionString", plist_new_string(PLIST_CLIENT_VERSION_STRING)); + plist_dict_set_item(plist, "ClientVersionString", plist_new_string(client_version)); plist_dict_set_item(plist, "MessageType", plist_new_string(message_type)); if (prog_name) { plist_dict_set_item(plist, "ProgName", plist_new_string(prog_name)); diff --git a/tools/inetcat.c b/tools/inetcat.c index f70215b..220a8a7 100644 --- a/tools/inetcat.c +++ b/tools/inetcat.c @@ -31,15 +31,18 @@ #include <stdlib.h> #include <stdint.h> #include <string.h> -#include <fcntl.h> #include <stddef.h> -#include <unistd.h> #include <errno.h> -#include <getopt.h> -#ifdef WIN32 + +#ifdef _WIN32 #include <winsock2.h> #include <windows.h> +#ifndef _MSC_VER +#include <unistd.h> +#endif #else +#include <fcntl.h> +#include <unistd.h> #include <sys/select.h> #include <sys/socket.h> #include <sys/un.h> @@ -47,14 +50,22 @@ #include <signal.h> #endif -#include "usbmuxd.h" +#ifdef _MSC_VER +#include <basetsd.h> +typedef SSIZE_T ssize_t; +#define STDIN_FILENO _fileno(stdin) +#define STDOUT_FILENO _fileno(stdout) +#endif + +#include <getopt.h> #include <libimobiledevice-glue/socket.h> +#include "usbmuxd.h" static int debug_level = 0; static size_t read_data_socket(int fd, uint8_t* buf, size_t bufsize) { -#ifdef WIN32 +#ifdef _WIN32 u_long bytesavailable = 0; if (fd == STDIN_FILENO) { bytesavailable = bufsize; @@ -140,7 +151,7 @@ int main(int argc, char **argv) print_usage(argc, argv, 0); return 0; case 'v': - printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION); + printf("%s %s\n", TOOL_NAME, libusbmuxd_version()); return 0; default: print_usage(argc, argv, 1); @@ -166,7 +177,7 @@ int main(int argc, char **argv) return -EINVAL; } -#ifndef WIN32 +#ifndef _WIN32 signal(SIGPIPE, SIG_IGN); #endif @@ -241,12 +252,15 @@ int main(int argc, char **argv) fprintf(stderr, "Failed to convert network address: %d (%s)\n", errno, strerror(errno)); } devfd = socket_connect_addr(saddr, device_port); + if (devfd < 0) { + devfd = -errno; + } } else if (dev->conn_type == CONNECTION_TYPE_USB) { devfd = usbmuxd_connect(dev->handle, device_port); } free(dev_list); if (devfd < 0) { - fprintf(stderr, "Error connecting to device: %s\n", strerror(errno)); + fprintf(stderr, "Error connecting to device: %s\n", strerror(-devfd)); return 1; } diff --git a/tools/iproxy.c b/tools/iproxy.c index 1bb9e77..d4c7d06 100644 --- a/tools/iproxy.c +++ b/tools/iproxy.c @@ -32,20 +32,22 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <fcntl.h> #include <stddef.h> -#include <unistd.h> #include <errno.h> -#include <getopt.h> -#ifdef WIN32 + +#ifdef _WIN32 #include <winsock2.h> #include <windows.h> typedef unsigned int socklen_t; #else +#include <fcntl.h> +#include <unistd.h> #include <sys/select.h> #include <sys/socket.h> #include <signal.h> #endif + +#include <getopt.h> #include <libimobiledevice-glue/socket.h> #include <libimobiledevice-glue/thread.h> #include "usbmuxd.h" @@ -156,6 +158,9 @@ static void *acceptor_thread(void *arg) } fprintf(stdout, "Requesting connection to NETWORK device %s (serial: %s), port %d\n", addrtxt, dev->udid, cdata->device_port); cdata->sfd = socket_connect_addr(saddr, cdata->device_port); + if (cdata->sfd < 0) { + cdata->sfd = -errno; + } } else if (dev->conn_type == CONNECTION_TYPE_USB) { fprintf(stdout, "Requesting connection to USB device handle %d (serial: %s), port %d\n", dev->handle, dev->udid, cdata->device_port); @@ -163,16 +168,17 @@ static void *acceptor_thread(void *arg) } free(dev_list); if (cdata->sfd < 0) { - fprintf(stderr, "Error connecting to device: %s\n", strerror(errno)); + fprintf(stderr, "Error connecting to device: %s\n", strerror(-cdata->sfd)); } else { fd_set fds; FD_ZERO(&fds); FD_SET(cdata->fd, &fds); FD_SET(cdata->sfd, &fds); + int maxfd = cdata->fd > cdata->sfd ? cdata->fd : cdata->sfd; while (1) { fd_set read_fds = fds; - int ret_sel = select(cdata->sfd+1, &read_fds, NULL, NULL, NULL); + int ret_sel = select(maxfd+1, &read_fds, NULL, NULL, NULL); if (ret_sel < 0) { perror("select"); break; @@ -300,7 +306,7 @@ int main(int argc, char **argv) print_usage(argc, argv, 0); return 0; case 'v': - printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION); + printf("%s %s\n", TOOL_NAME, libusbmuxd_version()); return 0; default: print_usage(argc, argv, 1); @@ -331,7 +337,7 @@ int main(int argc, char **argv) fprintf(stderr, "Invalid listen port specified in argument '%s'!\n", argv[0]); free(device_udid); free(source_addr); - return -EINVAL; + return EINVAL; } endp = NULL; device_port[0] = (uint16_t)strtol(argv[1], &endp, 10); @@ -339,7 +345,7 @@ int main(int argc, char **argv) fprintf(stderr, "Invalid device port specified in argument '%s'!\n", argv[1]); free(device_udid); free(source_addr); - return -EINVAL; + return EINVAL; } num_pairs = 1; } else { @@ -351,14 +357,14 @@ int main(int argc, char **argv) fprintf(stderr, "Invalid listen port specified in argument '%s'!\n", argv[i]); free(device_udid); free(source_addr); - return -EINVAL; + return EINVAL; } device_port[i] = (uint16_t)strtol(endp+1, &endp, 10); if (!device_port[i] || (*endp != '\0')) { fprintf(stderr, "Invalid device port specified in argument '%s'!\n", argv[i+1]); free(device_udid); free(source_addr); - return -EINVAL; + return EINVAL; } } num_pairs = argc; @@ -366,10 +372,10 @@ int main(int argc, char **argv) if (num_pairs > 16) { fprintf(stderr, "ERROR: Too many LOCAL:DEVICE port pairs. Maximum is 16.\n"); - return -1; + return 1; } -#ifndef WIN32 +#ifndef _WIN32 signal(SIGPIPE, SIG_IGN); #endif @@ -386,7 +392,7 @@ int main(int argc, char **argv) for (j = num_listen; j >= 0; j--) { socket_close(listen_sock[j].fd); } - return -errno; + return 1; } listen_sock[num_listen].index = i; num_listen++; @@ -400,7 +406,7 @@ int main(int argc, char **argv) for (j = num_listen; j >= 0; j--) { socket_close(listen_sock[j].fd); } - return -errno; + return 1; } listen_sock[num_listen].index = i; num_listen++; @@ -411,7 +417,7 @@ int main(int argc, char **argv) fd_set fds; FD_ZERO(&fds); for (i = 0; i < num_listen; i++) { -#ifdef WIN32 +#ifdef _WIN32 u_long l_yes = 1; ioctlsocket(listen_sock[i].fd, FIONBIO, &l_yes); #else @@ -445,7 +451,7 @@ int main(int argc, char **argv) socket_close(c_sock); fprintf(stderr, "ERROR: Out of memory\n"); free(device_udid); - return -1; + return 1; } cdata->fd = c_sock; cdata->sfd = -1; |
