LOCAL_C_INCLUDES := \
$(call include-path-for, libhardware_legacy)/hardware_legacy \
bionic/libc/dns/include \
- external/libcxx/include \
external/mdnsresponder/mDNSShared \
system/netd/include \
libnetutils \
libnl \
libsysutils \
+ libutils \
LOCAL_STATIC_LIBRARIES := \
libpcap \
#define LOG_TAG "InterfaceController"
#include <cutils/log.h>
+#include <utils/file.h>
#include "InterfaceController.h"
#include "RouteController.h"
return -1;
}
asprintf(&path, "%s/%s/%s", ipv6_proc_path, interface, setting);
- int success = writeFile(path, value, strlen(value));
+ bool success = android::WriteStringToFile(value, path);
free(path);
return success;
}
return -1;
}
asprintf(&path, "%s/%s/mtu", sys_net_path, interface);
- int success = writeFile(path, mtu, strlen(mtu));
+ bool success = android::WriteStringToFile(mtu, path);
free(path);
return success;
}
return res;
}
-int writeFile(const char *path, const char *value, int size) {
- int fd = open(path, O_WRONLY | O_CLOEXEC);
- if (fd < 0) {
- ALOGE("Failed to open %s: %s", path, strerror(errno));
- return -1;
- }
-
- if (write(fd, value, size) != size) {
- ALOGE("Failed to write %s: %s", path, strerror(errno));
- close(fd);
- return -1;
- }
- close(fd);
- return 0;
-}
-
-int readFile(const char *path, char *buf, int *sizep)
-{
- int fd = open(path, O_RDONLY | O_CLOEXEC);
- int size;
-
- if (fd < 0) {
- ALOGE("Failed to open %s: %s", path, strerror(errno));
- return -1;
- }
-
- size = read(fd, buf, *sizep);
- if (size < 0) {
- ALOGE("Failed to write %s: %s", path, strerror(errno));
- close(fd);
- return -1;
- }
- *sizep = size;
- close(fd);
- return 0;
-}
-
/*
* Check an interface name for plausibility. This should e.g. help against
* directory traversal.
int execIptables(IptablesTarget target, ...);
int execIptablesSilently(IptablesTarget target, ...);
-int writeFile(const char *path, const char *value, int size);
-int readFile(const char *path, char *buf, int *sizep);
bool isIfaceName(const char *name);
int parsePrefix(const char *prefix, uint8_t *family, void *address, int size, uint8_t *prefixlen);
#define LOG_TAG "TetherController"
#include <cutils/log.h>
#include <cutils/properties.h>
+#include <utils/file.h>
#include "Fwmark.h"
#include "NetdConstants.h"
return 0;
}
- int fd = open("/proc/sys/net/ipv4/ip_forward", O_WRONLY | O_CLOEXEC);
- if (fd < 0) {
- ALOGE("Failed to open ip_forward (%s)", strerror(errno));
- return -1;
- }
-
- if (write(fd, (enable ? "1" : "0"), 1) != 1) {
+ if (!android::WriteStringToFile(enable ? "1" : "0", "/proc/sys/net/ipv4/ip_forward")) {
ALOGE("Failed to write ip_forward (%s)", strerror(errno));
- close(fd);
return -1;
}
- close(fd);
+
return 0;
}
bool TetherController::getIpFwdEnabled() {
- int fd = open("/proc/sys/net/ipv4/ip_forward", O_RDONLY | O_CLOEXEC);
-
- if (fd < 0) {
- ALOGE("Failed to open ip_forward (%s)", strerror(errno));
- return false;
- }
-
- char enabled;
- if (read(fd, &enabled, 1) != 1) {
+ std::string enabled;
+ if (!android::ReadFileToString("/proc/sys/net/ipv4/ip_forward", &enabled)) {
ALOGE("Failed to read ip_forward (%s)", strerror(errno));
- close(fd);
return -1;
}
- close(fd);
- return (enabled == '1' ? true : false);
+ return (enabled == "1" ? true : false);
}
#define TETHER_START_CONST_ARG 8