The EVL network stack implements the
UDP protocol over
IPv4 as specified by RFC768. This is the EVL equivalent of the
AF_INET
protocol family using datagram sockets (SOCK_DGRAM
)
available wih the in-band network stack. Using out-of-band datagram
sockets with EVL is very similar to using its in-band counterpart, as
illustrated by the oob-net-udp
demo program. This boils down to:
SOCK_OOB
flag set, which extends the
associated protocol support to out-of-band handling, in this case
AF_PACKET
.#include <sys/socket.h>
/* Get a datagram socket in the IPv4 domain with out-of-band capabilities. */
s = socket(AF_INET, SOCK_DGRAM | SOCK_OOB, 0);
#include <sys/socket.h>
#include <arpa/inet.h>
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(udp_port_number);
if (!inet_pton(AF_INET, ip_address_as_string, &addr.sin_addr))
error(1, EINVAL, "invalid IPv4 address");
int ret = evl_net_solicit(s, (const struct sockaddr *)&addr, EVL_NEIGH_PERMANENT);
if (ret)
error(1, -ret, "evl_net_solicit()");
struct oob_msghdr msghdr;
struct sockaddr_in addr;
struct iovec iov;
ssize_t count;
/* INPUT */
iov.iov_base = input_datagram;
iov.iov_len = sizeof(input_datagram);
msghdr.msg_iov = &iov;
msghdr.msg_iovlen = 1;
msghdr.msg_control = NULL;
msghdr.msg_controllen = 0;
msghdr.msg_name = &addr; /* or NULL, optional */
msghdr.msg_namelen = sizeof(addr); /* or zero, optional */
msghdr.msg_flags = 0;
count = oob_recvmsg(s, &msghdr, NULL, 0);
if (count < 0)
error(1, errno, "oob_recvmsg() failed");
/* OUTPUT */
iov.iov_base = output_datagram;
iov.iov_len = sizeof(output_datagram);
msghdr.msg_iov = &iov;
msghdr.msg_iovlen = 1;
msghdr.msg_control = NULL;
msghdr.msg_controllen = 0;
msghdr.msg_name = NULL; /* Optional, use bound device if NULL. */
msghdr.msg_namelen = 0;
msghdr.msg_flags = 0;
count = oob_sendmsg(s, &msghdr, NULL, 0);
if (count < 0)
error(1, errno, "oob_sendmsg() failed");
Threads issuing the oob_recvmsg() and/or oob_sendmsg() calls must be attached to the EVL core.