Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/Fuzzilli/Modules/NetworkSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fileprivate protocol MessageHandler {
/// A connection to a network peer that speaks the above protocol.
fileprivate class Connection {
/// The file descriptor on POSIX or SOCKET handle on Windows of the socket.
let socket: libsocket.socket_t
let socket: libsocket.libsocket_t

/// The UUID of the remote end.
let localId: UUID
Expand Down Expand Up @@ -78,7 +78,7 @@ fileprivate class Connection {
/// Pending outgoing data. Must only be accessed on this connection's dispatch queue.
private var sendQueue: [Data] = []

init?(socket: libsocket.socket_t, localId: UUID, handler: MessageHandler) {
init?(socket: libsocket.libsocket_t, localId: UUID, handler: MessageHandler) {
self.socket = socket
self.localId = localId
self.handler = handler
Expand Down Expand Up @@ -331,7 +331,7 @@ public class NetworkParent: DistributedFuzzingParentNode {
unowned let fuzzer: Fuzzer

/// File descriptor or SOCKET handle of the server socket.
private var serverFd: libsocket.socket_t = INVALID_SOCKET
private var serverFd: libsocket.libsocket_t = INVALID_SOCKET

/// Address and port on which to listen for connections.
private let address: String
Expand All @@ -346,7 +346,7 @@ public class NetworkParent: DistributedFuzzingParentNode {
private var serverQueue: DispatchQueue? = nil

/// Active workers indexed by the socket used to communicate with them.
private var clientsBySocket = [libsocket.socket_t: Client]()
private var clientsBySocket = [libsocket.libsocket_t: Client]()

/// Active workers indexed by their id.
private var clientsById = [UUID: Client]()
Expand Down Expand Up @@ -445,7 +445,7 @@ public class NetworkParent: DistributedFuzzingParentNode {
onChildDisconnectedCallback = callback
}

private func handleNewConnection(_ socket: libsocket.socket_t) {
private func handleNewConnection(_ socket: libsocket.libsocket_t) {
guard socket > 0 else {
return logger.error("Failed to accept client connection")
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/libsocket/include/libsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ typedef __typeof__(_Generic((size_t)0, \
unsigned char : (char)0)) ssize_t;
#endif
#else
typedef int socket_t;
typedef int libsocket_t;
#define INVALID_SOCKET (-1)
#endif

socket_t socket_listen(const char* address, uint16_t port);
socket_t socket_accept(socket_t socket);
socket_t socket_connect(const char* address, uint16_t port);
libsocket_t socket_listen(const char* address, uint16_t port);
libsocket_t socket_accept(libsocket_t socket);
libsocket_t socket_connect(const char* address, uint16_t port);

ssize_t socket_send(socket_t socket, const uint8_t* data, size_t length);
ssize_t socket_recv(socket_t socket, uint8_t* buffer, size_t length);
ssize_t socket_send(libsocket_t socket, const uint8_t* data, size_t length);
ssize_t socket_recv(libsocket_t socket, uint8_t* buffer, size_t length);

int socket_shutdown(socket_t socket);
int socket_close(socket_t socket);
int socket_shutdown(libsocket_t socket);
int socket_close(libsocket_t socket);

#endif
20 changes: 10 additions & 10 deletions Sources/libsocket/socket-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <string.h>
#include <unistd.h>

socket_t socket_listen(const char* address, uint16_t port) {
socket_t fd = socket(AF_INET, SOCK_STREAM, 0);
libsocket_t socket_listen(const char* address, uint16_t port) {
libsocket_t fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0) {
return INVALID_SOCKET;
}
Expand Down Expand Up @@ -54,8 +54,8 @@ socket_t socket_listen(const char* address, uint16_t port) {
return fd;
}

socket_t socket_accept(socket_t fd) {
socket_t client_fd = accept(fd, NULL, 0);
libsocket_t socket_accept(libsocket_t fd) {
libsocket_t client_fd = accept(fd, NULL, 0);
if (client_fd < 0) {
return INVALID_SOCKET;
}
Expand All @@ -78,7 +78,7 @@ socket_t socket_accept(socket_t fd) {
return client_fd;
}

socket_t socket_connect(const char* address, uint16_t port) {
libsocket_t socket_connect(const char* address, uint16_t port) {
struct addrinfo hint;
memset(&hint, 0, sizeof(hint));
hint.ai_family = AF_UNSPEC;
Expand All @@ -93,7 +93,7 @@ socket_t socket_connect(const char* address, uint16_t port) {
return INVALID_SOCKET;
}

socket_t fd;
libsocket_t fd;
struct addrinfo* addr;
for (addr = result; addr != NULL; addr = addr->ai_next) {
fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
Expand Down Expand Up @@ -133,7 +133,7 @@ socket_t socket_connect(const char* address, uint16_t port) {
return fd;
}

ssize_t socket_send(socket_t fd, const uint8_t* data, size_t length) {
ssize_t socket_send(libsocket_t fd, const uint8_t* data, size_t length) {
ssize_t remaining = length;
while (remaining > 0) {
#ifdef __APPLE__
Expand All @@ -154,15 +154,15 @@ ssize_t socket_send(socket_t fd, const uint8_t* data, size_t length) {
return length;
}

ssize_t socket_recv(socket_t fd, uint8_t* data, size_t length) {
ssize_t socket_recv(libsocket_t fd, uint8_t* data, size_t length) {
return read(fd, data, length);
}

int socket_shutdown(socket_t socket) {
int socket_shutdown(libsocket_t socket) {
return shutdown(socket, SHUT_RDWR);
}

int socket_close(socket_t fd) {
int socket_close(libsocket_t fd) {
return close(fd);
}

Expand Down
Loading