static struct iovec read_iov_in;
static int read_socket[2];
-static void macos_vmnet_read(void);
-static const char *str_vmnet_status(vmnet_return_t status);
+static const char *str_vmnet_status(vmnet_return_t status) {
+ switch(status) {
+ case VMNET_SUCCESS:
+ return "success";
+
+ case VMNET_FAILURE:
+ return "general failure (possibly not enough privileges)";
+
+ case VMNET_MEM_FAILURE:
+ return "memory allocation failure";
+
+ case VMNET_INVALID_ARGUMENT:
+ return "invalid argument specified";
+
+ case VMNET_SETUP_INCOMPLETE:
+ return "interface setup is not complete";
+
+ case VMNET_INVALID_ACCESS:
+ return "invalid access, permission denied";
+
+ case VMNET_PACKET_TOO_BIG:
+ return "packet size is larger than MTU";
+
+ case VMNET_BUFFER_EXHAUSTED:
+ return "buffers exhausted in kernel";
+
+ case VMNET_TOO_MANY_PACKETS:
+ return "packet count exceeds limit";
+
+ case VMNET_SHARING_SERVICE_BUSY:
+ return "conflict, sharing service is in use";
+
+ default:
+ return "unknown vmnet error";
+ }
+}
+
+static void macos_vmnet_read(void) {
+ if(if_status != VMNET_SUCCESS) {
+ return;
+ }
+
+ int pkt_count = 1;
+ struct vmpktdesc packet = {
+ .vm_flags = 0,
+ .vm_pkt_size = max_packet_size,
+ .vm_pkt_iov = &read_iov_in,
+ .vm_pkt_iovcnt = 1,
+ };
+
+ if_status = vmnet_read(vmnet_if, &packet, &pkt_count);
+
+ if(if_status != VMNET_SUCCESS) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read packet: %s", str_vmnet_status(if_status));
+ return;
+ }
+
+ if(pkt_count && packet.vm_pkt_iovcnt) {
+ struct iovec read_iov_out = {
+ .iov_base = packet.vm_pkt_iov->iov_base,
+ .iov_len = packet.vm_pkt_size,
+ };
+
+ if(writev(read_socket[1], &read_iov_out, 1) < 0) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Unable to write to read socket: %s", strerror(errno));
+ return;
+ }
+ }
+}
int macos_vmnet_open(const char device[]) {
if(socketpair(AF_UNIX, SOCK_DGRAM, 0, read_socket)) {
return 0;
}
-void macos_vmnet_read(void) {
- if(if_status != VMNET_SUCCESS) {
- return;
- }
-
- int pkt_count = 1;
- struct vmpktdesc packet = {
- .vm_flags = 0,
- .vm_pkt_size = max_packet_size,
- .vm_pkt_iov = &read_iov_in,
- .vm_pkt_iovcnt = 1,
- };
-
- if_status = vmnet_read(vmnet_if, &packet, &pkt_count);
-
- if(if_status != VMNET_SUCCESS) {
- logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read packet: %s", str_vmnet_status(if_status));
- return;
- }
-
- if(pkt_count && packet.vm_pkt_iovcnt) {
- struct iovec read_iov_out = {
- .iov_base = packet.vm_pkt_iov->iov_base,
- .iov_len = packet.vm_pkt_size,
- };
-
- if(writev(read_socket[1], &read_iov_out, 1) < 0) {
- logger(DEBUG_ALWAYS, LOG_ERR, "Unable to write to read socket: %s", strerror(errno));
- return;
- }
- }
-}
-
ssize_t macos_vmnet_write(uint8_t *buffer, size_t buflen) {
if(buflen > max_packet_size) {
logger(DEBUG_ALWAYS, LOG_ERR, "Max packet size (%zd) exceeded: %zd", max_packet_size, buflen);
return pkt_count ? buflen : 0;
}
-
-const char *str_vmnet_status(vmnet_return_t status) {
- switch(status) {
- case VMNET_SUCCESS:
- return "success";
-
- case VMNET_FAILURE:
- return "general failure (possibly not enough privileges)";
-
- case VMNET_MEM_FAILURE:
- return "memory allocation failure";
-
- case VMNET_INVALID_ARGUMENT:
- return "invalid argument specified";
-
- case VMNET_SETUP_INCOMPLETE:
- return "interface setup is not complete";
-
- case VMNET_INVALID_ACCESS:
- return "invalid access, permission denied";
-
- case VMNET_PACKET_TOO_BIG:
- return "packet size is larger than MTU";
-
- case VMNET_BUFFER_EXHAUSTED:
- return "buffers exhausted in kernel";
-
- case VMNET_TOO_MANY_PACKETS:
- return "packet count exceeds limit";
-
- case VMNET_SHARING_SERVICE_BUSY:
- return "conflict, sharing service is in use";
-
- default:
- return "unknown vmnet error";
- }
-}