addr_len = sizeof(addr_in);
memset(&addr_in, 0, sizeof(addr_in));
addr_in.sin_family = AF_INET;
- read_message(input_fd, static_cast<void*>(&addr_in.sin_port),
+ read_message(input_fd, &addr_in.sin_port,
sizeof(addr_in.sin_port));
- read_message(input_fd, static_cast<void*>(&addr_in.sin_addr.s_addr),
+ read_message(input_fd, &addr_in.sin_addr.s_addr,
sizeof(addr_in.sin_addr.s_addr));
break;
addr_len = sizeof addr_in6;
memset(&addr_in6, 0, sizeof(addr_in6));
addr_in6.sin6_family = AF_INET6;
- read_message(input_fd, static_cast<void*>(&addr_in6.sin6_port),
+ read_message(input_fd, &addr_in6.sin6_port,
sizeof(addr_in6.sin6_port));
- read_message(input_fd, static_cast<void*>(&addr_in6.sin6_addr.s6_addr),
+ read_message(input_fd, &addr_in6.sin6_addr.s6_addr,
sizeof(addr_in6.sin6_addr.s6_addr));
break;
}
// Obtain the socket
- int result = get_sock(sock_type, addr, addr_len);
+ const int result = get_sock(sock_type, addr, addr_len);
if (result >= 0) {
// Got the socket, send it to the client.
write_message(output_fd, "S", 1);
}
// ...and append the reason code to the error message
- int error = errno;
- write_message(output_fd, static_cast<void*>(&error), sizeof error);
+ const int error = errno;
+ write_message(output_fd, &error, sizeof(error));
}
}
// Get the socket and bind to it.
int
-get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len)
+get_sock(const int type, struct sockaddr* bind_addr, const socklen_t addr_len)
{
- int sock = socket(bind_addr->sa_family, type, 0);
+ const int sock = socket(bind_addr->sa_family, type, 0);
if (sock == -1) {
- return -1;
+ return (-1);
}
const int on = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) {
- return -2; // This is part of the binding process, so it's a bind error
+ // This is part of the binding process, so it's a bind error
+ return (-2);
}
if (bind_addr->sa_family == AF_INET6 &&
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {
- return -2; // This is part of the binding process, so it's a bind error
+ // This is part of the binding process, so it's a bind error
+ return (-2);
}
if (bind(sock, bind_addr, addr_len) == -1) {
- return -2;
+ return (-2);
}
- return sock;
+ return (sock);
}
// Main run loop.
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-#include <iostream>
-
#include "../sockcreator.h"
#include <util/unittests/fork.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
+
+#include <iostream>
#include <cstring>
#include <cerrno>
// IPv4 check
void addressFamilySpecificCheck(const sockaddr_in*, const int) {
-};
+}
// IPv6 check
void addressFamilySpecificCheck(const sockaddr_in6*, const int socknum) {
socklen_t len = sizeof(options);
EXPECT_EQ(0, getsockopt(socknum, IPPROTO_IPV6, IPV6_V6ONLY, &options, &len));
EXPECT_NE(0, options);
-};
+}
// Generic version of the socket test. It creates the socket and checks that
memset(&addr, 0, sizeof(addr));
setAddressFamilyFields(&addr);
sockaddr* addr_ptr = reinterpret_cast<sockaddr*>(&addr);
- int socket = get_sock(socket_type, addr_ptr, sizeof(addr));
+ const int socket = get_sock(socket_type, addr_ptr, sizeof(addr));
ASSERT_GE(socket, 0) << "Couldn't create socket: failed with " <<
"return code " << socket << " and error " << strerror(errno);
// -1: The simulated bind() call has failed
// -2: The simulated socket() call has failed
int
-get_sock_dummy(const int type, struct sockaddr *addr, const socklen_t)
-{
+get_sock_dummy(const int type, struct sockaddr* addr, const socklen_t) {
int result = 0;
int port = 0;
// Dummy send function - return data (the result of get_sock()) to the destination.
int
-send_fd_dummy(const int destination, const int what)
-{
+send_fd_dummy(const int destination, const int what) {
// Make sure it is 1 byte so we know the length. We do not use more during
// the test anyway. And even with the LS bute, we can distinguish between
// the different results.
// process sends data from the client to run() and the checker process
// reads the response and checks it against the expected response.
int input_fd = 0;
- pid_t input = provide_input(&input_fd, input_data, input_size);
+ const pid_t input = provide_input(&input_fd, input_data, input_size);
ASSERT_NE(-1, input) << "Couldn't start input feeder";
int output_fd = 0;
- pid_t output = check_output(&output_fd, output_data, output_size);
+ const pid_t output = check_output(&output_fd, output_data, output_size);
ASSERT_NE(-1, output) << "Couldn't start output checker";
// Run the body