mavtables  0.2.1
MAVLink router and firewall.
UnixSyscalls.hpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2018 Michael R. Shannon <mrshannon.aerospace@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 #ifndef UNIXSYSCALLS_HPP_
19 #define UNIXSYSCALLS_HPP_
20 
21 
22 #include <fcntl.h> // open, fnctl
23 #include <netinet/in.h> // sockaddr_in
24 #include <sys/ioctl.h> // ioctl
25 #include <sys/poll.h> // poll
26 #include <sys/socket.h> // socket, bind, sendto, recvfrom
27 #include <sys/stat.h> // fstat
28 #include <sys/types.h> // socklen_t type on old BSD systems
29 #include <termios.h> // terminal control
30 #include <unistd.h> // read, write, close
31 
32 #include "config.hpp"
33 
34 
35 /** A thin wrapper around Unix system calls.
36  *
37  * The purpose of this is to allow system calls to be mocked during testing.
38  *
39  * See the following man pages for documentation:
40  * * [man 2 bind](http://man7.org/linux/man-pages/man2/bind.2.html)
41  * * [man 2 close](http://man7.org/linux/man-pages/man2/close.2.html)
42  * * [man 2 socket](http://man7.org/linux/man-pages/man2/socket.2.html)
43  * * [man 2 ioctl](http://man7.org/linux/man-pages/man2/ioctl.2.html)
44  * * [man 7 ip](http://man7.org/linux/man-pages/man7/ip.7.html)
45  * * [man 2 open](http://man7.org/linux/man-pages/man2/open.2.html)
46  * * [man 2 poll](http://man7.org/linux/man-pages/man2/poll.2.html)
47  * * [man 2 read](http://man7.org/linux/man-pages/man2/read.2.html)
48  * * [man 2 recvfrom](http://man7.org/linux/man-pages/man2/recv.2.html)
49  * * [man 2 sendto](http://man7.org/linux/man-pages/man2/send.2.html)
50  * * [man 2 termios](http://man7.org/linux/man-pages/man3/termios.3.html)
51  * * [man 2 write](http://man7.org/linux/man-pages/man2/write.2.html)
52  *
53  */
55 {
56  public:
57  TEST_VIRTUAL ~UnixSyscalls() = default;
58  TEST_VIRTUAL int bind(
59  int sockfd, const struct sockaddr *addr, socklen_t addrlen);
60  TEST_VIRTUAL int close(int fd);
61  TEST_VIRTUAL int ioctl(int fd, unsigned long request, void *argp);
62  TEST_VIRTUAL int open(const char *pathname, int flags);
63  TEST_VIRTUAL int poll(struct pollfd *fds, nfds_t nfds, int timeout);
64  TEST_VIRTUAL ssize_t read(int fd, void *buf, size_t count);
65  TEST_VIRTUAL ssize_t recvfrom(
66  int sockfd, void *buf, size_t len, int flags,
67  struct sockaddr *src_addr, socklen_t *addrlen);
68  TEST_VIRTUAL ssize_t sendto(
69  int sockfd, const void *buf, size_t len, int flags,
70  const struct sockaddr *dest_addr, socklen_t addrlen);
71  TEST_VIRTUAL int socket(int domain, int type, int protocol);
72  TEST_VIRTUAL int tcgetattr(int fd, struct termios *termios_p);
73  TEST_VIRTUAL int tcsetattr(
74  int fd, int optional_actions, const struct termios *termios_p);
75  TEST_VIRTUAL ssize_t write(int fd, const void *buf, size_t count);
76 };
77 
78 
79 #endif // UNIXSYSCALLS_HPP_
TEST_VIRTUAL ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
TEST_VIRTUAL ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
TEST_VIRTUAL ssize_t write(int fd, const void *buf, size_t count)
TEST_VIRTUAL int open(const char *pathname, int flags)
TEST_VIRTUAL int socket(int domain, int type, int protocol)
TEST_VIRTUAL int tcsetattr(int fd, int optional_actions, const struct termios *termios_p)
TEST_VIRTUAL int close(int fd)
TEST_VIRTUAL int poll(struct pollfd *fds, nfds_t nfds, int timeout)
TEST_VIRTUAL ssize_t read(int fd, void *buf, size_t count)
TEST_VIRTUAL int tcgetattr(int fd, struct termios *termios_p)
TEST_VIRTUAL int ioctl(int fd, unsigned long request, void *argp)
TEST_VIRTUAL int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
TEST_VIRTUAL ~UnixSyscalls()=default