|
@@ -1,6 +1,6 @@
|
|
-#include <android/log.h>
|
|
|
|
#include <errno.h>
|
|
#include <errno.h>
|
|
#include <netinet/in.h>
|
|
#include <netinet/in.h>
|
|
|
|
+#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <string.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/socket.h>
|
|
@@ -9,10 +9,6 @@
|
|
#include <sys/un.h>
|
|
#include <sys/un.h>
|
|
#include <unistd.h>
|
|
#include <unistd.h>
|
|
|
|
|
|
-#define LOG_TAG "hostage: pp"
|
|
|
|
-#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
|
|
|
-#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
|
|
|
|
-
|
|
|
|
#define CONTROLLEN CMSG_LEN(sizeof(int))
|
|
#define CONTROLLEN CMSG_LEN(sizeof(int))
|
|
|
|
|
|
#define UNIX_PATH "hostage"
|
|
#define UNIX_PATH "hostage"
|
|
@@ -22,7 +18,7 @@ int ipc_sock() {
|
|
struct sockaddr_un addr;
|
|
struct sockaddr_un addr;
|
|
|
|
|
|
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
|
|
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
|
|
- LOGE("Unable to create local socket: %d", errno);
|
|
|
|
|
|
+ perror("Unable to create local socket");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -32,7 +28,7 @@ int ipc_sock() {
|
|
|
|
|
|
if (connect(fd, (struct sockaddr*) &addr,
|
|
if (connect(fd, (struct sockaddr*) &addr,
|
|
sizeof(sa_family_t) + strlen(UNIX_PATH) + 1) == -1) {
|
|
sizeof(sa_family_t) + strlen(UNIX_PATH) + 1) == -1) {
|
|
- LOGE("Unable to connect local socket: %d", errno);
|
|
|
|
|
|
+ perror("Unable to connect local socket");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -45,7 +41,7 @@ int net_sock(int port) {
|
|
struct sockaddr_in addr;
|
|
struct sockaddr_in addr;
|
|
|
|
|
|
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
|
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
|
- LOGE("Unable to create net socket: %d", errno);
|
|
|
|
|
|
+ perror("Unable to create net socket");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -55,17 +51,17 @@ int net_sock(int port) {
|
|
addr.sin_port = htons(port);
|
|
addr.sin_port = htons(port);
|
|
|
|
|
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) == -1) {
|
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) == -1) {
|
|
- LOGE("Unable to set socket options: %d", errno);
|
|
|
|
|
|
+ perror("Unable to set socket options");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
|
|
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
|
|
- LOGE("Unable to bind net socket: %d", errno);
|
|
|
|
|
|
+ perror("Unable to bind net socket");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
if (listen(fd, 5) == -1) {
|
|
if (listen(fd, 5) == -1) {
|
|
- LOGE("Unable to listen net socket: %d", errno);
|
|
|
|
|
|
+ perror("Unable to listen net socket");
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -95,7 +91,7 @@ int send_fd(int fd, int fd_to_send) {
|
|
*(int *) CMSG_DATA(cmptr) = fd_to_send;
|
|
*(int *) CMSG_DATA(cmptr) = fd_to_send;
|
|
|
|
|
|
if (sendmsg(fd, &msg, 0) == -1) {
|
|
if (sendmsg(fd, &msg, 0) == -1) {
|
|
- LOGE("sendmsg failed: %d", errno);
|
|
|
|
|
|
+ perror("sendmsg failed");
|
|
}
|
|
}
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
@@ -117,18 +113,18 @@ int main(int argc, char *argv[]) {
|
|
close(ipc_fd);
|
|
close(ipc_fd);
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
- LOGD("ipc_fd: %d", ipc_fd);
|
|
|
|
|
|
+ printf("ipc_fd: %d\n", ipc_fd);
|
|
|
|
|
|
if ((net_fd = net_sock(port)) == -1) {
|
|
if ((net_fd = net_sock(port)) == -1) {
|
|
close(ipc_fd);
|
|
close(ipc_fd);
|
|
close(net_fd);
|
|
close(net_fd);
|
|
exit(EXIT_FAILURE);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|
|
- LOGD("net_fd: %d", net_fd);
|
|
|
|
|
|
+ printf("net_fd: %d\n", net_fd);
|
|
|
|
|
|
int status;
|
|
int status;
|
|
status = send_fd(ipc_fd, net_fd);
|
|
status = send_fd(ipc_fd, net_fd);
|
|
- LOGD("send_fd: %d", status);
|
|
|
|
|
|
+ printf("send_fd: %d\n", status);
|
|
|
|
|
|
close(ipc_fd);
|
|
close(ipc_fd);
|
|
close(net_fd);
|
|
close(net_fd);
|