sys: add networking functions
Add networking related functions to the syscall wrapper.
Signed-off-by: Benjamin Fair <benjaminfair@google.com>
Change-Id: I0ccb4138963ce2a8c7bb6f6f3a556de1afcd0c08
diff --git a/internal/sys.cpp b/internal/sys.cpp
index db843ac..b4a1ffc 100644
--- a/internal/sys.cpp
+++ b/internal/sys.cpp
@@ -19,6 +19,7 @@
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
+#include <sys/sendfile.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -92,6 +93,35 @@
return ::poll(fds, nfds, timeout);
}
+int SysImpl::socket(int domain, int type, int protocol) const
+{
+ return ::socket(domain, type, protocol);
+}
+
+int SysImpl::connect(int sockfd, const struct sockaddr* addr,
+ socklen_t addrlen) const
+{
+ return ::connect(sockfd, addr, addrlen);
+}
+
+ssize_t SysImpl::sendfile(int out_fd, int in_fd, off_t* offset,
+ size_t count) const
+{
+ return ::sendfile(out_fd, in_fd, offset, count);
+}
+
+int SysImpl::getaddrinfo(const char* node, const char* service,
+ const struct addrinfo* hints,
+ struct addrinfo** res) const
+{
+ return ::getaddrinfo(node, service, hints, res);
+}
+
+void SysImpl::freeaddrinfo(struct addrinfo* res) const
+{
+ ::freeaddrinfo(res);
+}
+
SysImpl sys_impl;
} // namespace internal
diff --git a/internal/sys.hpp b/internal/sys.hpp
index 41fb46b..a399903 100644
--- a/internal/sys.hpp
+++ b/internal/sys.hpp
@@ -7,8 +7,11 @@
* other pieces.
*/
+#include <netdb.h>
#include <poll.h>
#include <sys/mman.h>
+#include <sys/socket.h>
+#include <sys/types.h>
#include <cinttypes>
#include <cstddef>
@@ -39,6 +42,15 @@
virtual int getpagesize() const = 0;
virtual int ioctl(int fd, unsigned long request, void* param) const = 0;
virtual int poll(struct pollfd* fds, nfds_t nfds, int timeout) const = 0;
+ virtual int socket(int domain, int type, int protocol) const = 0;
+ virtual int connect(int sockfd, const struct sockaddr* addr,
+ socklen_t addrlen) const = 0;
+ virtual ssize_t sendfile(int out_fd, int in_fd, off_t* offset,
+ size_t count) const = 0;
+ virtual int getaddrinfo(const char* node, const char* service,
+ const struct addrinfo* hints,
+ struct addrinfo** res) const = 0;
+ virtual void freeaddrinfo(struct addrinfo* res) const = 0;
virtual std::int64_t getSize(const char* pathname) const = 0;
};
@@ -63,6 +75,15 @@
int getpagesize() const override;
int ioctl(int fd, unsigned long request, void* param) const override;
int poll(struct pollfd* fds, nfds_t nfds, int timeout) const override;
+ int socket(int domain, int type, int protocol) const override;
+ int connect(int sockfd, const struct sockaddr* addr,
+ socklen_t addrlen) const override;
+ ssize_t sendfile(int out_fd, int in_fd, off_t* offset,
+ size_t count) const override;
+ int getaddrinfo(const char* node, const char* service,
+ const struct addrinfo* hints,
+ struct addrinfo** res) const override;
+ void freeaddrinfo(struct addrinfo* res) const override;
/* returns 0 on failure, or if the file is zero bytes. */
std::int64_t getSize(const char* pathname) const override;
};
diff --git a/tools/test/internal_sys_mock.hpp b/tools/test/internal_sys_mock.hpp
index ce37d91..97f95bf 100644
--- a/tools/test/internal_sys_mock.hpp
+++ b/tools/test/internal_sys_mock.hpp
@@ -26,6 +26,13 @@
MOCK_CONST_METHOD0(getpagesize, int());
MOCK_CONST_METHOD3(ioctl, int(int, unsigned long, void*));
MOCK_CONST_METHOD3(poll, int(struct pollfd*, nfds_t, int));
+ MOCK_CONST_METHOD3(socket, int(int, int, int));
+ MOCK_CONST_METHOD3(connect, int(int, const struct sockaddr*, socklen_t));
+ MOCK_CONST_METHOD4(sendfile, ssize_t(int, int, off_t*, size_t));
+ MOCK_CONST_METHOD4(getaddrinfo,
+ int(const char*, const char*, const struct addrinfo*,
+ struct addrinfo**));
+ MOCK_CONST_METHOD1(freeaddrinfo, void(struct addrinfo*));
MOCK_CONST_METHOD1(getSize, std::int64_t(const char*));
};