From c6d6f4002168c8459d7bc05d5f6420c6e2fde6a3 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Sat, 17 Oct 2020 11:11:15 +0100 Subject: [PATCH] Format Android protector C code --- cmd/ck-client/protector_android.go | 87 +++++++++++++++--------------- 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/cmd/ck-client/protector_android.go b/cmd/ck-client/protector_android.go index ca43bf4..639b98c 100644 --- a/cmd/ck-client/protector_android.go +++ b/cmd/ck-client/protector_android.go @@ -13,56 +13,53 @@ package main #include #include -#define ANCIL_FD_BUFFER(n) \ - struct { \ - struct cmsghdr h; \ - int fd[n]; \ - } +#define ANCIL_FD_BUFFER(n) \ + struct { \ + struct cmsghdr h; \ + int fd[n]; \ + } - int - ancil_send_fds_with_buffer(int sock, const int *fds, unsigned n_fds, void *buffer) - { - struct msghdr msghdr; - char nothing = '!'; - struct iovec nothing_ptr; - struct cmsghdr *cmsg; - int i; +int ancil_send_fds_with_buffer(int sock, const int *fds, unsigned n_fds, + void *buffer) { + struct msghdr msghdr; + char nothing = '!'; + struct iovec nothing_ptr; + struct cmsghdr *cmsg; + int i; - nothing_ptr.iov_base = ¬hing; - nothing_ptr.iov_len = 1; - msghdr.msg_name = NULL; - msghdr.msg_namelen = 0; - msghdr.msg_iov = ¬hing_ptr; - msghdr.msg_iovlen = 1; - msghdr.msg_flags = 0; - msghdr.msg_control = buffer; - msghdr.msg_controllen = sizeof(struct cmsghdr) + sizeof(int) * n_fds; - cmsg = CMSG_FIRSTHDR(&msghdr); - cmsg->cmsg_len = msghdr.msg_controllen; - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - for(i = 0; i < n_fds; i++) - ((int *)CMSG_DATA(cmsg))[i] = fds[i]; - return(sendmsg(sock, &msghdr, 0) >= 0 ? 0 : -1); - } + nothing_ptr.iov_base = ¬hing; + nothing_ptr.iov_len = 1; + msghdr.msg_name = NULL; + msghdr.msg_namelen = 0; + msghdr.msg_iov = ¬hing_ptr; + msghdr.msg_iovlen = 1; + msghdr.msg_flags = 0; + msghdr.msg_control = buffer; + msghdr.msg_controllen = sizeof(struct cmsghdr) + sizeof(int) * n_fds; + cmsg = CMSG_FIRSTHDR(&msghdr); + cmsg->cmsg_len = msghdr.msg_controllen; + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + for (i = 0; i < n_fds; i++) + ((int *)CMSG_DATA(cmsg))[i] = fds[i]; + return (sendmsg(sock, &msghdr, 0) >= 0 ? 0 : -1); +} - int - ancil_send_fd(int sock, int fd) - { - ANCIL_FD_BUFFER(1) buffer; +int ancil_send_fd(int sock, int fd) { + ANCIL_FD_BUFFER(1) buffer; - return(ancil_send_fds_with_buffer(sock, &fd, 1, &buffer)); - } + return (ancil_send_fds_with_buffer(sock, &fd, 1, &buffer)); +} - void - set_timeout(int sock) - { - struct timeval tv; - tv.tv_sec = 3; - tv.tv_usec = 0; - setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval)); - setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(struct timeval)); - } +void set_timeout(int sock) { + struct timeval tv; + tv.tv_sec = 3; + tv.tv_usec = 0; + setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, + sizeof(struct timeval)); + setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, + sizeof(struct timeval)); +} */ import "C"