CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
unix_net.h
1#pragma once
2
3#include <cx/net/net_private.h>
4#include <cx/platform/unix.h>
5#include <cx/buffer/buffer.h>
6
7#include <limits.h>
8#include <sys/socket.h>
9#include <sys/uio.h>
10
11bool netAddrToSockaddr(_In_ const NetAddr* addr, _Out_ struct sockaddr_storage* sa,
12 _Out_ int* sasz);
13
19bool netAddrFromSockaddr(_Out_ NetAddr* addr, _In_ const struct sockaddr* sa);
20
21// Enough room for the control messages one datagram carries in either direction, in either address
22// family: a packet info structure and a traffic class byte. Buffers of this size sit on the stack
23// of every ingest loop, so it is sized to what is actually used rather than generously -- a
24// too-small buffer truncates a control message silently.
25#define NET_CMSG_SPACE 128
26
27// Reads the local address and ECN mark out of a received message's control data, and clears what
28// was not there. Anything unrecognized is skipped: an option enabled by something else on the same
29// socket must not stop the two that matter from being found.
30void _netCmsgToPktInfo(_Inout_ struct msghdr* mh, _Out_ NetPktInfo* info);
31
36typedef struct iovec NetPlatIov;
37
44#if defined(NET_MAX_IOV)
45#undef NET_MAX_IOV
46#endif
47#if defined(IOV_MAX) && IOV_MAX < 64
48#define NET_MAX_IOV IOV_MAX
49#else
50#define NET_MAX_IOV 64
51#endif
52
72_meta_inline size_t netIovToPlatform(_Out_writes_(count) NetPlatIov* out,
73 _In_reads_(count) const BufIov* iov, size_t count)
74{
75 for (size_t i = 0; i < count; ++i) {
76 out[i].iov_base = iov[i].data;
77 out[i].iov_len = iov[i].len;
78 }
79 return count;
80}
Simple buffer management.
Per-datagram information the IP layer carries alongside the payload.
Definition net_shared.h:328