rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | diff --git a/system/netd/client/NetdClient.cpp b/system/netd/client/NetdClient.cpp |
| 2 | index 392b0af..36be012 100644 |
| 3 | --- a/system/netd/client/NetdClient.cpp |
| 4 | +++ b/system/netd/client/NetdClient.cpp |
| 5 | @@ -19,9 +19,15 @@ |
| 6 | #include <errno.h> |
| 7 | #include <sys/socket.h> |
| 8 | #include <unistd.h> |
| 9 | +#include <string.h> |
| 10 | |
| 11 | #include <atomic> |
| 12 | |
| 13 | +#define LOG_TAG "NetdClient" |
| 14 | +#include "log/log.h" |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | #include "Fwmark.h" |
| 19 | #include "FwmarkClient.h" |
| 20 | #include "FwmarkCommand.h" |
| 21 | @@ -181,11 +187,31 @@ extern "C" unsigned getNetworkForProcess() { |
| 22 | } |
| 23 | |
| 24 | extern "C" int setNetworkForSocket(unsigned netId, int socketFd) { |
| 25 | + int ret = 0; |
| 26 | + unsigned int get_mark = 0; |
| 27 | + |
| 28 | + |
| 29 | if (socketFd < 0) { |
| 30 | return -EBADF; |
| 31 | } |
| 32 | + #if 0 |
| 33 | FwmarkCommand command = {FwmarkCommand::SELECT_NETWORK, netId, 0}; |
| 34 | return FwmarkClient().send(&command, socketFd); |
| 35 | + #endif |
| 36 | + |
| 37 | + socklen_t fwmarkLen = sizeof(get_mark); |
| 38 | + printf("[setNetworkForSocket] netId[%d] socketFd[%d]", netId, socketFd); |
| 39 | + |
| 40 | + if (setsockopt(socketFd, SOL_SOCKET, SO_MARK, &netId, |
| 41 | + sizeof(netId)) == -1) { |
| 42 | + ALOGE("setNetworkForSocket SO_MARK(%s)", strerror(errno)); |
| 43 | + return -errno; |
| 44 | + } |
| 45 | + |
| 46 | + ret = getsockopt(socketFd, SOL_SOCKET, SO_MARK, &get_mark, &fwmarkLen); |
| 47 | + ALOGE("setNetworkForSocket get_mark(%d)", get_mark); |
| 48 | + |
| 49 | + return ret; |
| 50 | } |
| 51 | |
| 52 | extern "C" int setNetworkForProcess(unsigned netId) { |