2020-05-01 19:15:38 -07:00
|
|
|
|
/*
|
2021-01-30 13:53:49 -08:00
|
|
|
|
* Copyright (c)2013-2021 ZeroTier, Inc.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* Use of this software is governed by the Business Source License included
|
|
|
|
|
|
* in the LICENSE.TXT file in the project's root directory.
|
|
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* Change Date: 2026-01-01
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* On the date above, in accordance with the Business Source License, use
|
|
|
|
|
|
* of this software will be governed by version 2.0 of the Apache License.
|
|
|
|
|
|
*/
|
|
|
|
|
|
/****/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @file
|
|
|
|
|
|
*
|
|
|
|
|
|
* This defines the external C API for ZeroTier Sockets
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#ifndef ZTS_SOCKETS_H
|
|
|
|
|
|
#define ZTS_SOCKETS_H
|
2021-01-05 10:00:48 -08:00
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
extern "C" {
|
2021-02-24 01:25:15 -08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Error codes //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
2021-01-04 20:57:18 -08:00
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
/** Common error return values */
|
2021-04-22 11:20:04 -07:00
|
|
|
|
typedef enum {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/** No error */
|
|
|
|
|
|
ZTS_ERR_OK = 0,
|
|
|
|
|
|
/** Socket error, see `zts_errno` */
|
|
|
|
|
|
ZTS_ERR_SOCKET = -1,
|
|
|
|
|
|
/** This operation is not allowed at this time. Or possibly the node hasn't been started */
|
|
|
|
|
|
ZTS_ERR_SERVICE = -2,
|
|
|
|
|
|
/** Invalid argument */
|
|
|
|
|
|
ZTS_ERR_ARG = -3,
|
|
|
|
|
|
/** No result (not necessarily an error) */
|
|
|
|
|
|
ZTS_ERR_NO_RESULT = -4,
|
|
|
|
|
|
/** Consider filing a bug report */
|
|
|
|
|
|
ZTS_ERR_GENERAL = -5
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_error_t;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Event codes //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/** Event codes used by the (optional) callback API */
|
|
|
|
|
|
typedef enum {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Node has been initialized
|
|
|
|
|
|
*
|
|
|
|
|
|
* This is the first event generated, and is always sent. It may occur
|
|
|
|
|
|
* before node's constructor returns.
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_EVENT_NODE_UP = 200,
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Node is online -- at least one upstream node appears reachable
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_EVENT_NODE_ONLINE = 201,
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Node is offline -- network does not seem to be reachable by any available
|
|
|
|
|
|
* strategy
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_EVENT_NODE_OFFLINE = 202,
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Node is shutting down
|
|
|
|
|
|
*
|
|
|
|
|
|
* This is generated within Node's destructor when it is being shut down.
|
|
|
|
|
|
* It's done for convenience, since cleaning up other state in the event
|
|
|
|
|
|
* handler may appear more idiomatic.
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_EVENT_NODE_DOWN = 203,
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* A fatal error has occurred. One possible reason is:
|
|
|
|
|
|
*
|
|
|
|
|
|
* Your identity has collided with another node's ZeroTier address
|
|
|
|
|
|
*
|
|
|
|
|
|
* This happens if two different public keys both hash (via the algorithm
|
|
|
|
|
|
* in Identity::generate()) to the same 40-bit ZeroTier address.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This is something you should "never" see, where "never" is defined as
|
|
|
|
|
|
* once per 2^39 new node initializations / identity creations. If you do
|
|
|
|
|
|
* see it, you're going to see it very soon after a node is first
|
|
|
|
|
|
* initialized.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This is reported as an event rather than a return code since it's
|
|
|
|
|
|
* detected asynchronously via error messages from authoritative nodes.
|
|
|
|
|
|
*
|
|
|
|
|
|
* If this occurs, you must shut down and delete the node, delete the
|
|
|
|
|
|
* identity.secret record/file from the data store, and restart to generate
|
|
|
|
|
|
* a new identity. If you don't do this, you will not be able to communicate
|
|
|
|
|
|
* with other nodes.
|
|
|
|
|
|
*
|
|
|
|
|
|
* We'd automate this process, but we don't think silently deleting
|
|
|
|
|
|
* private keys or changing our address without telling the calling code
|
|
|
|
|
|
* is good form. It violates the principle of least surprise.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You can technically get away with not handling this, but we recommend
|
|
|
|
|
|
* doing so in a mature reliable application. Besides, handling this
|
|
|
|
|
|
* condition is a good way to make sure it never arises. It's like how
|
|
|
|
|
|
* umbrellas prevent rain and smoke detectors prevent fires. They do, right?
|
|
|
|
|
|
*
|
|
|
|
|
|
* Meta-data: none
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_EVENT_NODE_FATAL_ERROR = 204,
|
|
|
|
|
|
|
|
|
|
|
|
/** Network ID does not correspond to a known network */
|
|
|
|
|
|
ZTS_EVENT_NETWORK_NOT_FOUND = 210,
|
|
|
|
|
|
/** The version of ZeroTier inside libzt is too old */
|
|
|
|
|
|
ZTS_EVENT_NETWORK_CLIENT_TOO_OLD = 211,
|
|
|
|
|
|
/** The configuration for a network has been requested (no action needed) */
|
|
|
|
|
|
ZTS_EVENT_NETWORK_REQ_CONFIG = 212,
|
|
|
|
|
|
/** The node joined the network successfully (no action needed) */
|
|
|
|
|
|
ZTS_EVENT_NETWORK_OK = 213,
|
|
|
|
|
|
/** The node is not allowed to join the network (you must authorize node) */
|
|
|
|
|
|
ZTS_EVENT_NETWORK_ACCESS_DENIED = 214,
|
|
|
|
|
|
/** The node has received an IPv4 address from the network controller */
|
|
|
|
|
|
ZTS_EVENT_NETWORK_READY_IP4 = 215,
|
|
|
|
|
|
/** The node has received an IPv6 address from the network controller */
|
|
|
|
|
|
ZTS_EVENT_NETWORK_READY_IP6 = 216,
|
|
|
|
|
|
/** Deprecated */
|
|
|
|
|
|
ZTS_EVENT_NETWORK_READY_IP4_IP6 = 217,
|
|
|
|
|
|
/** Network controller is unreachable */
|
|
|
|
|
|
ZTS_EVENT_NETWORK_DOWN = 218,
|
|
|
|
|
|
/** Network change received from controller */
|
|
|
|
|
|
ZTS_EVENT_NETWORK_UPDATE = 219,
|
|
|
|
|
|
|
|
|
|
|
|
/** TCP/IP stack (lwIP) is up (for debug purposes) */
|
|
|
|
|
|
ZTS_EVENT_STACK_UP = 220,
|
|
|
|
|
|
/** TCP/IP stack (lwIP) id down (for debug purposes) */
|
|
|
|
|
|
ZTS_EVENT_STACK_DOWN = 221,
|
|
|
|
|
|
|
|
|
|
|
|
/** lwIP netif up (for debug purposes) */
|
|
|
|
|
|
ZTS_EVENT_NETIF_UP = 230,
|
|
|
|
|
|
/** lwIP netif down (for debug purposes) */
|
|
|
|
|
|
ZTS_EVENT_NETIF_DOWN = 231,
|
|
|
|
|
|
/** lwIP netif removed (for debug purposes) */
|
|
|
|
|
|
ZTS_EVENT_NETIF_REMOVED = 232,
|
|
|
|
|
|
/** lwIP netif link up (for debug purposes) */
|
|
|
|
|
|
ZTS_EVENT_NETIF_LINK_UP = 233,
|
|
|
|
|
|
/** lwIP netif link down (for debug purposes) */
|
|
|
|
|
|
ZTS_EVENT_NETIF_LINK_DOWN = 234,
|
|
|
|
|
|
|
|
|
|
|
|
/** A direct P2P path to peer is known */
|
|
|
|
|
|
ZTS_EVENT_PEER_DIRECT = 240,
|
|
|
|
|
|
/** A direct P2P path to peer is NOT known. Traffic is now relayed */
|
|
|
|
|
|
ZTS_EVENT_PEER_RELAY = 241,
|
|
|
|
|
|
/** A peer is unreachable. Check NAT/Firewall settings */
|
|
|
|
|
|
ZTS_EVENT_PEER_UNREACHABLE = 242,
|
|
|
|
|
|
/** A new path to a peer was discovered */
|
|
|
|
|
|
ZTS_EVENT_PEER_PATH_DISCOVERED = 243,
|
|
|
|
|
|
/** A known path to a peer is now considered dead */
|
|
|
|
|
|
ZTS_EVENT_PEER_PATH_DEAD = 244,
|
|
|
|
|
|
|
|
|
|
|
|
/** A new managed network route was added */
|
|
|
|
|
|
ZTS_EVENT_ROUTE_ADDED = 250,
|
|
|
|
|
|
/** A managed network route was removed */
|
|
|
|
|
|
ZTS_EVENT_ROUTE_REMOVED = 251,
|
|
|
|
|
|
|
|
|
|
|
|
/** A new managed IPv4 address was assigned to this peer */
|
|
|
|
|
|
ZTS_EVENT_ADDR_ADDED_IP4 = 260,
|
|
|
|
|
|
/** A managed IPv4 address assignment was removed from this peer */
|
|
|
|
|
|
ZTS_EVENT_ADDR_REMOVED_IP4 = 261,
|
|
|
|
|
|
/** A new managed IPv4 address was assigned to this peer */
|
|
|
|
|
|
ZTS_EVENT_ADDR_ADDED_IP6 = 262,
|
|
|
|
|
|
/** A managed IPv6 address assignment was removed from this peer */
|
|
|
|
|
|
ZTS_EVENT_ADDR_REMOVED_IP6 = 263,
|
|
|
|
|
|
|
|
|
|
|
|
/** The node's secret key (identity) */
|
|
|
|
|
|
ZTS_EVENT_STORE_IDENTITY_SECRET = 270,
|
|
|
|
|
|
/** The node's public key (identity) */
|
|
|
|
|
|
ZTS_EVENT_STORE_IDENTITY_PUBLIC = 271,
|
|
|
|
|
|
/** The node has received an updated planet config */
|
|
|
|
|
|
ZTS_EVENT_STORE_PLANET = 272,
|
|
|
|
|
|
/** New reachability hints and peer configuration */
|
|
|
|
|
|
ZTS_EVENT_STORE_PEER = 273,
|
|
|
|
|
|
/** New network config */
|
|
|
|
|
|
ZTS_EVENT_STORE_NETWORK = 274
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_event_t;
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// zts_errno Error codes //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
2021-02-01 17:59:21 -08:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Error variable set after each `zts_*` socket call. Provides additional error context.
|
|
|
|
|
|
*/
|
2020-05-01 19:15:38 -07:00
|
|
|
|
extern int zts_errno;
|
|
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
typedef enum {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/** Operation not permitted (`zts_errno` value) */
|
|
|
|
|
|
ZTS_EPERM = 1,
|
|
|
|
|
|
/** No such file or directory */
|
|
|
|
|
|
ZTS_ENOENT = 2,
|
|
|
|
|
|
/** No such process */
|
|
|
|
|
|
ZTS_ESRCH = 3,
|
|
|
|
|
|
/** Interrupted system call */
|
|
|
|
|
|
ZTS_EINTR = 4,
|
|
|
|
|
|
/** I/O error */
|
|
|
|
|
|
ZTS_EIO = 5,
|
|
|
|
|
|
/** No such device or address */
|
|
|
|
|
|
ZTS_ENXIO = 6,
|
|
|
|
|
|
/** Bad file number */
|
|
|
|
|
|
ZTS_EBADF = 9,
|
|
|
|
|
|
/** Try again */
|
|
|
|
|
|
ZTS_EAGAIN = 11,
|
|
|
|
|
|
/** Operation would block */
|
|
|
|
|
|
ZTS_EWOULDBLOCK = ZTS_EAGAIN,
|
|
|
|
|
|
/** Out of memory */
|
|
|
|
|
|
ZTS_ENOMEM = 12,
|
|
|
|
|
|
/** Permission denied */
|
|
|
|
|
|
ZTS_EACCES = 13,
|
|
|
|
|
|
/** Bad address */
|
|
|
|
|
|
ZTS_EFAULT = 14,
|
|
|
|
|
|
/** Device or resource busy */
|
|
|
|
|
|
ZTS_EBUSY = 16,
|
|
|
|
|
|
/** File exists */
|
|
|
|
|
|
ZTS_EEXIST = 17,
|
|
|
|
|
|
/** No such device */
|
|
|
|
|
|
ZTS_ENODEV = 19,
|
|
|
|
|
|
/** Invalid argument */
|
|
|
|
|
|
ZTS_EINVAL = 22,
|
|
|
|
|
|
/** File table overflow */
|
|
|
|
|
|
ZTS_ENFILE = 23,
|
|
|
|
|
|
/** Too many open files */
|
|
|
|
|
|
ZTS_EMFILE = 24,
|
|
|
|
|
|
/** Function not implemented */
|
|
|
|
|
|
ZTS_ENOSYS = 38,
|
|
|
|
|
|
/** Socket operation on non-socket */
|
|
|
|
|
|
ZTS_ENOTSOCK = 88,
|
|
|
|
|
|
/** Destination address required */
|
|
|
|
|
|
ZTS_EDESTADDRREQ = 89,
|
|
|
|
|
|
/** Message too long */
|
|
|
|
|
|
ZTS_EMSGSIZE = 90,
|
|
|
|
|
|
/** Protocol wrong type for socket */
|
|
|
|
|
|
ZTS_EPROTOTYPE = 91,
|
|
|
|
|
|
/** Protocol not available */
|
|
|
|
|
|
ZTS_ENOPROTOOPT = 92,
|
|
|
|
|
|
/** Protocol not supported */
|
|
|
|
|
|
ZTS_EPROTONOSUPPORT = 93,
|
|
|
|
|
|
/** Socket type not supported */
|
|
|
|
|
|
ZTS_ESOCKTNOSUPPORT = 94,
|
|
|
|
|
|
/** Operation not supported on transport endpoint */
|
|
|
|
|
|
ZTS_EOPNOTSUPP = 95,
|
|
|
|
|
|
/** Protocol family not supported */
|
|
|
|
|
|
ZTS_EPFNOSUPPORT = 96,
|
|
|
|
|
|
/** Address family not supported by protocol */
|
|
|
|
|
|
ZTS_EAFNOSUPPORT = 97,
|
|
|
|
|
|
/** Address already in use */
|
|
|
|
|
|
ZTS_EADDRINUSE = 98,
|
|
|
|
|
|
/** Cannot assign requested address */
|
|
|
|
|
|
ZTS_EADDRNOTAVAIL = 99,
|
|
|
|
|
|
/** Network is down */
|
|
|
|
|
|
ZTS_ENETDOWN = 100,
|
|
|
|
|
|
/** Network is unreachable */
|
|
|
|
|
|
ZTS_ENETUNREACH = 101,
|
|
|
|
|
|
/** Software caused connection abort */
|
|
|
|
|
|
ZTS_ECONNABORTED = 103,
|
|
|
|
|
|
/** Connection reset by peer */
|
|
|
|
|
|
ZTS_ECONNRESET = 104,
|
|
|
|
|
|
/** No buffer space available */
|
|
|
|
|
|
ZTS_ENOBUFS = 105,
|
|
|
|
|
|
/** Transport endpoint is already connected */
|
|
|
|
|
|
ZTS_EISCONN = 106,
|
|
|
|
|
|
/** Transport endpoint is not connected */
|
|
|
|
|
|
ZTS_ENOTCONN = 107,
|
|
|
|
|
|
/** Connection timed out */
|
|
|
|
|
|
ZTS_ETIMEDOUT = 110,
|
|
|
|
|
|
/** No route to host */
|
|
|
|
|
|
ZTS_EHOSTUNREACH = 113,
|
|
|
|
|
|
/** Operation already in progress */
|
|
|
|
|
|
ZTS_EALREADY = 114,
|
|
|
|
|
|
/** Operation now in progress */
|
|
|
|
|
|
ZTS_EINPROGRESS = 115
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_errno_t;
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Misc definitions //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Length of human-readable MAC address string
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define ZTS_MAC_ADDRSTRLEN 18
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Max length of human-readable IPv4 string
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define ZTS_INET_ADDRSTRLEN 16
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Max length of human-readable IPv6 string
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define ZTS_INET6_ADDRSTRLEN 46
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Maximum (and required) length of string buffers used to receive
|
|
|
|
|
|
* string-format IP addresses from the API. This is set to `ZTS_INET6_ADDRSTRLEN`
|
|
|
|
|
|
* to handle all cases: `ZTS_AF_INET` and `ZTS_AF_INET6`
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define ZTS_IP_MAX_STR_LEN ZTS_INET6_ADDRSTRLEN
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Required buffer length to safely receive data store items
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define ZTS_STORE_DATA_LEN 4096
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Maximum length of network short name
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define ZTS_MAX_NETWORK_SHORT_NAME_LENGTH 127
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Maximum number of pushed routes on a network
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define ZTS_MAX_NETWORK_ROUTES 32
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Maximum number of statically assigned IP addresses per network endpoint
|
|
|
|
|
|
* using ZT address management (not DHCP)
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define ZTS_MAX_ASSIGNED_ADDRESSES 16
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Maximum number of direct network paths to a given peer
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define ZTS_MAX_PEER_NETWORK_PATHS 16
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Maximum number of multicast groups a device / network interface can be
|
|
|
|
|
|
* subscribed to at once
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define ZTS_MAX_MULTICAST_SUBSCRIPTIONS 1024
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Misc //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#if ! defined(ZTS_ENABLE_PYTHON) && ! defined(ZTS_ENABLE_PINVOKE)
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#define ZTS_C_API_ONLY 1
|
2021-03-24 12:20:39 -07:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#if ! ZTS_NO_STDINT_H
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#include <stdint.h>
|
2021-03-24 12:20:39 -07:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#ifndef ssize_t
|
2021-04-17 23:46:21 -07:00
|
|
|
|
// TODO: Should be SSIZE_T, would require lwIP patch
|
|
|
|
|
|
// #include <BaseTsd.h>
|
|
|
|
|
|
// typedef SSIZE_T ssize_t;
|
|
|
|
|
|
typedef int ssize_t;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#endif
|
2021-03-24 12:20:39 -07:00
|
|
|
|
#else
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#include <unistd.h>
|
2021-03-24 12:20:39 -07:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ZTS_ENABLE_PINVOKE
|
2021-04-17 23:46:21 -07:00
|
|
|
|
// Used by P/INVOKE wrappers
|
|
|
|
|
|
typedef void (*CppCallback)(void* msg);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Common definitions and structures for interoperability between zts_* and //
|
|
|
|
|
|
// lwIP functions. Some of the code in the following section is a borrowed //
|
|
|
|
|
|
// from the lwIP codebase so that the user doesn't need to include headers //
|
|
|
|
|
|
// from that project in addition to the ZeroTier SDK headers. The license //
|
|
|
|
|
|
// applying to this code borrowed from lwIP is produced below and only //
|
|
|
|
|
|
// applies to the portions of code which are merely renamed versions of //
|
|
|
|
|
|
// their lwIP counterparts. The rest of the code in this C API file is //
|
|
|
|
|
|
// governed by the license text provided at the beginning of this file. //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
|
|
*
|
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
|
|
|
|
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* This file is part of the lwIP TCP/IP stack.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Author: Adam Dunkels <adam@sics.se>
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/** 255.255.255.255 */
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_IPADDR_NONE ((uint32_t)0xffffffffUL)
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/** 127.0.0.1 */
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_IPADDR_LOOPBACK ((uint32_t)0x7f000001UL)
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/** 0.0.0.0 */
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_IPADDR_ANY ((uint32_t)0x00000000UL)
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/** 255.255.255.255 */
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_IPADDR_BROADCAST ((uint32_t)0xffffffffUL)
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/** 255.255.255.255 */
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_INADDR_NONE ZTS_IPADDR_NONE
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/** 127.0.0.1 */
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_INADDR_LOOPBACK ZTS_IPADDR_LOOPBACK
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/** 0.0.0.0 */
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_INADDR_ANY ZTS_IPADDR_ANY
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/** 255.255.255.255 */
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_INADDR_BROADCAST ZTS_IPADDR_BROADCAST
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
// Socket protocol types
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_SOCK_STREAM 0x0001
|
|
|
|
|
|
#define ZTS_SOCK_DGRAM 0x0002
|
|
|
|
|
|
#define ZTS_SOCK_RAW 0x0003
|
2020-05-01 19:15:38 -07:00
|
|
|
|
// Socket family types
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_AF_UNSPEC 0x0000
|
|
|
|
|
|
#define ZTS_AF_INET 0x0002
|
|
|
|
|
|
#define ZTS_AF_INET6 0x000a
|
|
|
|
|
|
#define ZTS_PF_INET ZTS_AF_INET
|
|
|
|
|
|
#define ZTS_PF_INET6 ZTS_AF_INET6
|
|
|
|
|
|
#define ZTS_PF_UNSPEC ZTS_AF_UNSPEC
|
2020-05-01 19:15:38 -07:00
|
|
|
|
// Protocol command types
|
|
|
|
|
|
#define ZTS_IPPROTO_IP 0x0000
|
|
|
|
|
|
#define ZTS_IPPROTO_ICMP 0x0001
|
|
|
|
|
|
#define ZTS_IPPROTO_TCP 0x0006
|
|
|
|
|
|
#define ZTS_IPPROTO_UDP 0x0011
|
|
|
|
|
|
#define ZTS_IPPROTO_IPV6 0x0029
|
|
|
|
|
|
#define ZTS_IPPROTO_ICMPV6 0x003a
|
|
|
|
|
|
#define ZTS_IPPROTO_UDPLITE 0x0088
|
|
|
|
|
|
#define ZTS_IPPROTO_RAW 0x00ff
|
|
|
|
|
|
// send() and recv() flags
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_MSG_PEEK 0x0001
|
|
|
|
|
|
#define ZTS_MSG_WAITALL 0x0002 // NOT YET SUPPORTED
|
|
|
|
|
|
#define ZTS_MSG_OOB 0x0004 // NOT YET SUPPORTED
|
|
|
|
|
|
#define ZTS_MSG_DONTWAIT 0x0008
|
|
|
|
|
|
#define ZTS_MSG_MORE 0x0010
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
// Macro's for defining ioctl() command values
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_IOCPARM_MASK 0x7fU
|
|
|
|
|
|
#define ZTS_IOC_VOID 0x20000000UL
|
|
|
|
|
|
#define ZTS_IOC_OUT 0x40000000UL
|
|
|
|
|
|
#define ZTS_IOC_IN 0x80000000UL
|
|
|
|
|
|
#define ZTS_IOC_INOUT (ZTS_IOC_IN | ZTS_IOC_OUT)
|
|
|
|
|
|
#define ZTS_IO(x, y) (ZTS_IOC_VOID | ((x) << 8) | (y))
|
2021-04-26 21:55:01 -07:00
|
|
|
|
#define ZTS_IOR(x, y, t) (ZTS_IOC_OUT | (((long)sizeof(t) & ZTS_IOCPARM_MASK) << 16) | ((x) << 8) | (y))
|
|
|
|
|
|
#define ZTS_IOW(x, y, t) (ZTS_IOC_IN | (((long)sizeof(t) & ZTS_IOCPARM_MASK) << 16) | ((x) << 8) | (y))
|
2020-05-01 19:15:38 -07:00
|
|
|
|
// ioctl() commands
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_FIONREAD ZTS_IOR('f', 127, unsigned long)
|
|
|
|
|
|
#define ZTS_FIONBIO ZTS_IOW('f', 126, unsigned long)
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Custom but still mostly standard socket interface structures //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
typedef uint32_t zts_socklen_t;
|
|
|
|
|
|
typedef uint32_t zts_in_addr_t;
|
|
|
|
|
|
typedef uint16_t zts_in_port_t;
|
|
|
|
|
|
typedef uint8_t zts_sa_family_t;
|
|
|
|
|
|
|
|
|
|
|
|
struct zts_in_addr {
|
2020-05-30 18:29:04 -07:00
|
|
|
|
#if defined(_WIN32)
|
2021-04-26 22:07:55 -07:00
|
|
|
|
zts_in_addr_t S_addr;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
#else
|
2021-04-26 22:07:55 -07:00
|
|
|
|
// A definition in winsock may conflict with s_addr
|
|
|
|
|
|
zts_in_addr_t s_addr;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
#endif
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct zts_in6_addr {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
union un {
|
|
|
|
|
|
uint32_t u32_addr[4];
|
|
|
|
|
|
uint8_t u8_addr[16];
|
|
|
|
|
|
} un;
|
|
|
|
|
|
//#define s6_addr un.u8_addr
|
2020-05-01 19:15:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Address structure to specify an IPv4 endpoint
|
|
|
|
|
|
*/
|
2020-05-01 19:15:38 -07:00
|
|
|
|
struct zts_sockaddr_in {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
uint8_t sin_len;
|
|
|
|
|
|
zts_sa_family_t sin_family;
|
|
|
|
|
|
zts_in_port_t sin_port;
|
|
|
|
|
|
struct zts_in_addr sin_addr;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
#define SIN_ZERO_LEN 8
|
2021-04-26 22:07:55 -07:00
|
|
|
|
char sin_zero[SIN_ZERO_LEN];
|
2020-05-01 19:15:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Address structure to specify an IPv6 endpoint
|
|
|
|
|
|
*/
|
2020-05-01 19:15:38 -07:00
|
|
|
|
struct zts_sockaddr_in6 {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
uint8_t sin6_len; // length of this structure
|
|
|
|
|
|
zts_sa_family_t sin6_family; // ZTS_AF_INET6
|
|
|
|
|
|
zts_in_port_t sin6_port; // Transport layer port #
|
|
|
|
|
|
uint32_t sin6_flowinfo; // IPv6 flow information
|
|
|
|
|
|
struct zts_in6_addr sin6_addr; // IPv6 address
|
|
|
|
|
|
uint32_t sin6_scope_id; // Set of interfaces for scope
|
2020-05-01 19:15:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Pointers to socket address structures are often cast to this type
|
|
|
|
|
|
*/
|
2020-05-01 19:15:38 -07:00
|
|
|
|
struct zts_sockaddr {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
uint8_t sa_len;
|
|
|
|
|
|
zts_sa_family_t sa_family;
|
|
|
|
|
|
char sa_data[14];
|
2020-05-01 19:15:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Address structure large enough to hold IPv4 and IPv6 addresses
|
|
|
|
|
|
*/
|
2020-05-01 19:15:38 -07:00
|
|
|
|
struct zts_sockaddr_storage {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
uint8_t s2_len;
|
|
|
|
|
|
zts_sa_family_t ss_family;
|
|
|
|
|
|
char s2_data1[2];
|
|
|
|
|
|
uint32_t s2_data2[3];
|
|
|
|
|
|
uint32_t s2_data3[3];
|
2020-05-01 19:15:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
2021-04-22 11:20:04 -07:00
|
|
|
|
// Callback Structures //
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* Runtime details about the current node
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
typedef struct {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Node ID
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint64_t node_id;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Port used by ZeroTier to send and receive traffic
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint16_t port_primary;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Port used by ZeroTier to send and receive traffic
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint16_t port_secondary;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Port used by ZeroTier to send and receive traffic
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint16_t port_tertiary;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* ZT Major version
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint8_t ver_major;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* ZT Minor version
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint8_t ver_minor;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* ZT Patch revision
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint8_t ver_rev;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_node_info_t;
|
2020-05-30 18:29:04 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* Details about an assigned address that was added or removed
|
2020-05-30 18:29:04 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
typedef struct {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
uint64_t net_id;
|
|
|
|
|
|
struct zts_sockaddr_storage addr;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_addr_info_t;
|
2020-05-30 18:29:04 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Virtual network status codes
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
typedef enum {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Waiting for network configuration (also means revision == 0)
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_NETWORK_STATUS_REQUESTING_CONFIGURATION = 0,
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Configuration received and we are authorized
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_NETWORK_STATUS_OK = 1,
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Netconf master told us 'nope'
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_NETWORK_STATUS_ACCESS_DENIED = 2,
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Netconf master exists, but this virtual network does not
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_NETWORK_STATUS_NOT_FOUND = 3,
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Initialization of network failed or other internal error
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_NETWORK_STATUS_PORT_ERROR = 4,
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* ZeroTier core version too old
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_NETWORK_STATUS_CLIENT_TOO_OLD = 5
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_network_status_t;
|
2020-05-30 18:29:04 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Virtual network type codes
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
typedef enum {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Private networks are authorized via certificates of membership
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_NETWORK_TYPE_PRIVATE = 0,
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Public networks have no access control -- they'll always be AUTHORIZED
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_NETWORK_TYPE_PUBLIC = 1
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_net_info_type_t;
|
2020-05-30 18:29:04 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* A route to be pushed on a virtual network
|
|
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
typedef struct {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Target network / netmask bits (in port field) or NULL or 0.0.0.0/0
|
|
|
|
|
|
* for default
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct zts_sockaddr_storage target;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Gateway IP address (port ignored) or NULL (family == 0) for LAN-local
|
|
|
|
|
|
* (no gateway)
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct zts_sockaddr_storage via;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Route flags
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint16_t flags;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Route metric (not currently used)
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint16_t metric;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_route_info_t;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* An Ethernet multicast group
|
|
|
|
|
|
*/
|
|
|
|
|
|
typedef struct {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* MAC address (least significant 48 bits)
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint64_t mac;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Additional distinguishing information (usually zero)
|
|
|
|
|
|
*/
|
|
|
|
|
|
unsigned long adi;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_multicast_group_t;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The peer's trust hierarchy role
|
|
|
|
|
|
*/
|
|
|
|
|
|
typedef enum {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Ordinary node
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_PEER_ROLE_LEAF = 0,
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Moon root
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_PEER_ROLE_MOON = 1,
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Planetary root
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_PEER_ROLE_PLANET = 2
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_peer_role_t;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2020-05-30 18:29:04 -07:00
|
|
|
|
* Virtual network configuration
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
typedef struct {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* 64-bit ZeroTier network ID
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint64_t net_id;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Ethernet MAC (48 bits) that should be assigned to port
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint64_t mac;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Network name (from network configuration master)
|
|
|
|
|
|
*/
|
|
|
|
|
|
char name[ZTS_MAX_NETWORK_SHORT_NAME_LENGTH + 1];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Network configuration request status
|
|
|
|
|
|
*/
|
|
|
|
|
|
zts_network_status_t status;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Network type
|
|
|
|
|
|
*/
|
|
|
|
|
|
zts_net_info_type_t type;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Maximum interface MTU
|
|
|
|
|
|
*/
|
|
|
|
|
|
unsigned int mtu;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* If nonzero, the network this port belongs to indicates DHCP availability
|
|
|
|
|
|
*
|
|
|
|
|
|
* This is a suggestion. The underlying implementation is free to ignore it
|
|
|
|
|
|
* for security or other reasons. This is simply a netconf parameter that
|
|
|
|
|
|
* means 'DHCP is available on this network.'
|
|
|
|
|
|
*/
|
|
|
|
|
|
int dhcp;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* If nonzero, this port is allowed to bridge to other networks
|
|
|
|
|
|
*
|
|
|
|
|
|
* This is informational. If this is false (0), bridged packets will simply
|
|
|
|
|
|
* be dropped and bridging won't work.
|
|
|
|
|
|
*/
|
|
|
|
|
|
int bridge;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* If nonzero, this network supports and allows broadcast
|
|
|
|
|
|
* (ff:ff:ff:ff:ff:ff) traffic
|
|
|
|
|
|
*/
|
|
|
|
|
|
int broadcast_enabled;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* If the network is in PORT_ERROR state, this is the (negative) error code
|
|
|
|
|
|
* most recently reported
|
|
|
|
|
|
*/
|
|
|
|
|
|
int port_error;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Revision number as reported by controller or 0 if still waiting for
|
|
|
|
|
|
* config
|
|
|
|
|
|
*/
|
|
|
|
|
|
unsigned long netconf_rev;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Number of assigned addresses
|
|
|
|
|
|
*/
|
|
|
|
|
|
unsigned int assigned_addr_count;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* ZeroTier-assigned addresses (in sockaddr_storage structures)
|
|
|
|
|
|
*
|
|
|
|
|
|
* For IP, the port number of the sockaddr_XX structure contains the number
|
|
|
|
|
|
* of bits in the address netmask. Only the IP address and port are used.
|
|
|
|
|
|
* Other fields like interface number can be ignored.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This is only used for ZeroTier-managed address assignments sent by the
|
|
|
|
|
|
* virtual network's configuration master.
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct zts_sockaddr_storage assigned_addrs[ZTS_MAX_ASSIGNED_ADDRESSES];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Number of ZT-pushed routes
|
|
|
|
|
|
*/
|
|
|
|
|
|
unsigned int route_count;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Routes (excluding those implied by assigned addresses and their masks)
|
|
|
|
|
|
*/
|
|
|
|
|
|
zts_route_info_t routes[ZTS_MAX_NETWORK_ROUTES];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Number of multicast groups subscribed
|
|
|
|
|
|
*/
|
|
|
|
|
|
unsigned int multicast_sub_count;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Multicast groups to which this network's device is subscribed
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct {
|
|
|
|
|
|
uint64_t mac; /* MAC in lower 48 bits */
|
|
|
|
|
|
uint32_t adi; /* Additional distinguishing information, usually zero
|
|
|
|
|
|
except for IPv4 ARP groups */
|
|
|
|
|
|
} multicast_subs[ZTS_MAX_MULTICAST_SUBSCRIPTIONS];
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_net_info_t;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Physical network path to a peer
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
typedef struct {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Address of endpoint
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct zts_sockaddr_storage address;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Time of last send in milliseconds or 0 for never
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint64_t last_tx;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Time of last receive in milliseconds or 0 for never
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint64_t last_rx;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Is this a trusted path? If so this will be its nonzero ID.
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint64_t trusted_path_id;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* One-way latency
|
|
|
|
|
|
*/
|
|
|
|
|
|
float latency;
|
|
|
|
|
|
|
|
|
|
|
|
float unused_0;
|
|
|
|
|
|
float unused_1;
|
|
|
|
|
|
float unused_2;
|
|
|
|
|
|
float unused_3;
|
|
|
|
|
|
float unused_4;
|
|
|
|
|
|
uint64_t unused_5;
|
|
|
|
|
|
uint64_t unused_6;
|
|
|
|
|
|
float unused_7;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Name of physical interface (for monitoring)
|
|
|
|
|
|
*/
|
|
|
|
|
|
char* ifname;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Is path expired?
|
|
|
|
|
|
*/
|
|
|
|
|
|
int expired;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Is path preferred?
|
|
|
|
|
|
*/
|
|
|
|
|
|
int preferred;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_path_t;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Peer status result buffer
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
typedef struct {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* ZeroTier address (40 bits)
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint64_t address;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Remote major version or -1 if not known
|
|
|
|
|
|
*/
|
|
|
|
|
|
int ver_major;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Remote minor version or -1 if not known
|
|
|
|
|
|
*/
|
|
|
|
|
|
int ver_minor;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Remote revision or -1 if not known
|
|
|
|
|
|
*/
|
|
|
|
|
|
int ver_rev;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Last measured latency in milliseconds or -1 if unknown
|
|
|
|
|
|
*/
|
|
|
|
|
|
int latency;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* What trust hierarchy role does this device have?
|
|
|
|
|
|
*/
|
|
|
|
|
|
zts_peer_role_t role;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Number of paths (size of paths[])
|
|
|
|
|
|
*/
|
|
|
|
|
|
unsigned int path_count;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Whether this peer was ever reachable via an aggregate link
|
|
|
|
|
|
*/
|
|
|
|
|
|
int unused_0;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Known network paths to peer
|
|
|
|
|
|
*/
|
|
|
|
|
|
zts_path_t paths[ZTS_MAX_PEER_NETWORK_PATHS];
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_peer_info_t;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-04-26 21:55:01 -07:00
|
|
|
|
#define ZTS_MAX_NUM_ROOTS 16
|
|
|
|
|
|
#define ZTS_MAX_ENDPOINTS_PER_ROOT 32
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Structure used to specify a root topology (aka a world)
|
|
|
|
|
|
*/
|
|
|
|
|
|
typedef struct {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
char* public_id_str[ZTS_MAX_NUM_ROOTS];
|
|
|
|
|
|
char* endpoint_ip_str[ZTS_MAX_NUM_ROOTS][ZTS_MAX_ENDPOINTS_PER_ROOT];
|
2021-04-26 21:55:01 -07:00
|
|
|
|
} zts_world_t;
|
|
|
|
|
|
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/**
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* Structure used to convey information about a virtual network
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* interface (netif) to a user application.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
typedef struct {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* The virtual network that this interface was created for
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint64_t net_id;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The hardware address assigned to this interface
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint64_t mac;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* The MTU for this interface
|
|
|
|
|
|
*/
|
|
|
|
|
|
int mtu;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_netif_info_t;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Callback message
|
|
|
|
|
|
*/
|
|
|
|
|
|
typedef struct {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Event identifier
|
|
|
|
|
|
*/
|
|
|
|
|
|
int16_t event_code;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Node status
|
|
|
|
|
|
*/
|
|
|
|
|
|
zts_node_info_t* node;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Network information
|
|
|
|
|
|
*/
|
|
|
|
|
|
zts_net_info_t* network;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Netif status
|
|
|
|
|
|
*/
|
|
|
|
|
|
zts_netif_info_t* netif;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Managed routes
|
|
|
|
|
|
*/
|
|
|
|
|
|
zts_route_info_t* route;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Peer info
|
|
|
|
|
|
*/
|
|
|
|
|
|
zts_peer_info_t* peer;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Assigned address
|
|
|
|
|
|
*/
|
|
|
|
|
|
zts_addr_info_t* addr;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Binary data (identities, planets, network configs, peer hints, etc)
|
|
|
|
|
|
*/
|
|
|
|
|
|
void* cache;
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Length of data message or structure
|
|
|
|
|
|
*/
|
|
|
|
|
|
int len;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_event_msg_t;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
2021-04-22 11:20:04 -07:00
|
|
|
|
// Python Bindings (Subset of regular socket API) //
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
2021-02-24 01:25:15 -08:00
|
|
|
|
|
|
|
|
|
|
#ifdef ZTS_ENABLE_PYTHON
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#include "Python.h"
|
2021-02-24 01:25:15 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Abstract class used as a director. Pointer to an instance of this class
|
|
|
|
|
|
* is provided to the Python layer.
|
|
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
class PythonDirectorCallbackClass {
|
|
|
|
|
|
public:
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Called by native code on event. Implemented in Python
|
|
|
|
|
|
*/
|
|
|
|
|
|
virtual void on_zerotier_event(zts_event_msg_t* msg);
|
|
|
|
|
|
virtual ~PythonDirectorCallbackClass() {};
|
2021-02-24 01:25:15 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
extern PythonDirectorCallbackClass* _userEventCallback;
|
2021-02-24 01:25:15 -08:00
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
int zts_py_bind(int fd, int family, int type, PyObject* addro);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
int zts_py_connect(int fd, int family, int type, PyObject* addro);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
PyObject* zts_py_accept(int fd);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
2021-03-01 22:34:12 -08:00
|
|
|
|
int zts_py_listen(int fd, int backlog);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
PyObject* zts_py_recv(int fd, int len, int flags);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
int zts_py_send(int fd, PyObject* buf, int flags);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
2021-03-01 22:34:12 -08:00
|
|
|
|
int zts_py_close(int fd);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
2021-03-05 00:18:11 -08:00
|
|
|
|
int zts_py_setblocking(int fd, int flag);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
2021-03-05 00:18:11 -08:00
|
|
|
|
int zts_py_getblocking(int fd);
|
2021-02-24 01:25:15 -08:00
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#endif // ZTS_ENABLE_PYTHON
|
2021-02-24 01:25:15 -08:00
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// ZeroTier Service and Network Controls //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2020-05-30 18:29:04 -07:00
|
|
|
|
#if defined(_WIN32)
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#ifdef ADD_EXPORTS
|
|
|
|
|
|
#define ZTS_API __declspec(dllexport)
|
|
|
|
|
|
#else
|
|
|
|
|
|
#define ZTS_API __declspec(dllimport)
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#define ZTCALL __cdecl
|
2020-05-01 19:15:38 -07:00
|
|
|
|
#else
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#define ZTS_API
|
|
|
|
|
|
#define ZTCALL
|
2020-05-01 19:15:38 -07:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Central API //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#ifndef ZTS_DISABLE_CENTRAL_API
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#define ZTS_CENTRAL_DEFAULT_URL "https://my.zerotier.com"
|
|
|
|
|
|
#define ZTS_CENRTAL_MAX_URL_LEN 128
|
|
|
|
|
|
#define ZTS_CENTRAL_TOKEN_LEN 32
|
|
|
|
|
|
#define ZTS_CENTRAL_RESP_BUF_DEFAULT_SZ (128 * 1024)
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#define ZTS_HTTP_GET 0
|
|
|
|
|
|
#define ZTS_HTTP_POST 1
|
|
|
|
|
|
#define ZTS_HTTP_DELETE 2
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#define ZTS_CENTRAL_NODE_AUTH_FALSE 0
|
|
|
|
|
|
#define ZTS_CENTRAL_NODE_AUTH_TRUE 1
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#define ZTS_CENTRAL_READ 1
|
|
|
|
|
|
#define ZTS_CENTRAL_WRITE 2
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Enable read/write capability. Default before calling this is
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* read-only: `ZTS_CENTRAL_READ`
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param modes `ZTS_CENTRAL_READ` and/or `ZTS_CENTRAL_WRITE`. Whether the API allows read, write,
|
|
|
|
|
|
* or both
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_ARG` if invalid argument.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_set_access_mode(int8_t modes);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Enable or disable libcurl verbosity
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param is_verbose `[1, 0]`, Whether debug information is desired
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_ARG` if invalid argument.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_set_verbose(int8_t is_verbose);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
2021-03-14 01:01:04 -08:00
|
|
|
|
ZTS_API void ZTCALL zts_central_clear_resp_buf();
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Set the Central API `URL` and user API token.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
|
|
|
|
|
* @param url_str The URL to the Central API server
|
|
|
|
|
|
* @param token_str User API token
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param resp_buf Destination buffer for raw `JSON` output
|
|
|
|
|
|
* @param buf_len Size of buffer for server response (specify `0` for default
|
|
|
|
|
|
* size)
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_ARG` if invalid argument.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_init(const char* url_str, const char* token_str, char* resp_buf, uint32_t buf_len);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
2021-03-14 01:01:04 -08:00
|
|
|
|
ZTS_API void ZTCALL zts_central_cleanup();
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Copies the `JSON`-formatted string buffer from the last request into
|
2021-03-14 01:01:04 -08:00
|
|
|
|
* a user-provided buffer.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param dst User-provided destination buffer
|
|
|
|
|
|
* @param len Length of aforementioned buffer
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if all contents were copied successfully.
|
|
|
|
|
|
* `ZTS_ERR_ARG` if provided buffer was too small.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_get_last_resp_buf(char* dst, int len);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Get the status of the Central API server.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return Standard HTTP response codes.
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_status_get(int* http_resp_code);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Get the currently authenticated user’s record.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
|
|
|
|
|
* @return Standard HTTP response codes.
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_self_get(int* http_resp_code);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Retrieve a `Network`.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
|
|
|
|
|
* @return Standard HTTP response codes.
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_net_get(int* http_resp_code, uint64_t net_id);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Update or create a `Network`.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
|
|
|
|
|
* Only fields marked as [rw] can be directly modified. If other fields are
|
2021-03-14 01:01:04 -08:00
|
|
|
|
* present in the posted request they are ignored. New networks can be
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* created by POSTing to /api/network with no net_id parameter. The server
|
2021-03-14 01:01:04 -08:00
|
|
|
|
* will create a random unused network ID and return the new network record.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
|
|
|
|
|
* @return Standard HTTP response codes.
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_net_update(int* http_resp_code, uint64_t net_id);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Delete a Network.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Delete a network and all its related information permanently.
|
|
|
|
|
|
* Use extreme caution as this cannot be undone!
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return Standard HTTP response codes.
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_net_delete(int* http_resp_code, uint64_t net_id);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Get All Viewable Networks.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Get all networks for which you have at least read access.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return Standard HTTP response codes.
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_net_get_all(int* http_resp_code);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief Retrieve a Member.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return Standard HTTP response codes.
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_member_get(int* http_resp_code, uint64_t net_id, uint64_t node_id);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Update or add a Member.
|
|
|
|
|
|
*
|
|
|
|
|
|
* New members can be added to a network by POSTing them.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return Standard HTTP response codes.
|
|
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_member_update(int* http_resp_code, uint64_t net_id, uint64_t node_id, char* post_data);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-14 01:01:04 -08:00
|
|
|
|
* @brief Authorize or (De)authorize a node on a network. This operation
|
|
|
|
|
|
* is idempotent.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param node_id Node ID
|
2021-01-30 13:53:49 -08:00
|
|
|
|
* @param is_authed Boolean value for whether this node should be authorized
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_ARG` if invalid argument.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_node_auth(int* http_resp_code, uint64_t net_id, uint64_t node_id, uint8_t is_authed);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Get All Members of a Network.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Get all members of a network for which you have at least read access.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return Standard HTTP response codes.
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_central_net_get_members(int* http_resp_code, uint64_t net_id);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#endif // ZTS_DISABLE_CENTRAL_API
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Identity Management //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* The length of a human-friendly identity key pair string
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define ZTS_ID_STR_BUF_LEN 384
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Generates a node identity (public/secret key-pair) and stores it in a
|
|
|
|
|
|
* user-provided buffer.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param key User-provided destination buffer
|
|
|
|
|
|
* @param key_buf_len Length of user-provided destination buffer. Will be set
|
|
|
|
|
|
* to the number of bytes copied.
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_ARG` if invalid argument.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_id_new(char* key, unsigned int* key_buf_len);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Verifies that a key-pair is valid. Checks formatting and pairing of
|
|
|
|
|
|
* key to address.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param key Buffer containing key-pair
|
|
|
|
|
|
* @param len Length of key-pair buffer
|
|
|
|
|
|
* @return `1` if true, `0` if false.
|
|
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_id_pair_is_valid(const char* key, unsigned int len);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Instruct ZeroTier to look for node identity files at the given location. This is an
|
|
|
|
|
|
* initialization function that can only be called before `zts_node_start()`.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Note that calling this function is not mandatory and if it is not called the node's keys will be
|
|
|
|
|
|
* kept in memory and retrievable via `zts_node_get_id_pair()`.
|
|
|
|
|
|
*
|
|
|
|
|
|
* See also: `zts_init_from_memory()`
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param port Path Null-terminated file-system path string
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_init_from_storage(const char* path);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Instruct ZeroTier to use the identity provided in `key`. This is an initialization
|
|
|
|
|
|
* function that can only be called before `zts_node_start()`.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Note that calling this function is not mandatory and if it is not called the node's keys will be
|
|
|
|
|
|
* kept in memory and retrievable via `zts_node_get_id_pair()`.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* See also: `zts_init_from_storage()`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param key Path Null-terminated file-system path string
|
|
|
|
|
|
* @param len Length of `key` buffer
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_init_from_memory(const char* key, unsigned int len);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Set the event handler function. This is an initialization function that can only be called
|
|
|
|
|
|
* before `zts_node_start()`.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param callback A function pointer to the event handler function
|
|
|
|
|
|
* @param family `ZTS_AF_INET`, or `ZTS_AF_INET6`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*/
|
2021-02-24 01:25:15 -08:00
|
|
|
|
#ifdef ZTS_ENABLE_PYTHON
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_init_set_event_handler(PythonDirectorCallbackClass* callback);
|
2021-02-24 01:25:15 -08:00
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef ZTS_ENABLE_PINVOKE
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_init_set_event_handler(CppCallback callback);
|
2021-02-24 01:25:15 -08:00
|
|
|
|
#endif
|
|
|
|
|
|
#ifdef ZTS_C_API_ONLY
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_init_set_event_handler(void (*callback)(void*));
|
2021-01-30 13:53:49 -08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Blacklist an interface prefix (or name). This prevents ZeroTier from
|
|
|
|
|
|
* sending traffic over matching interfaces. This is an initialization function that can
|
|
|
|
|
|
* only be called before `zts_node_start()`.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param prefix Null-terminated interface prefix string
|
|
|
|
|
|
* @param len Length of prefix string
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_init_blacklist_if(const char* prefix, unsigned int len);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @brief Present a world definition for ZeroTier to use instead of the default.
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* This is an initialization function that can only be called before `zts_node_start()`.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @param world_data Array of world definition data (binary)
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param len Length of binary data
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_init_set_world(const void* world_data, unsigned int len);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Set the port to which the node should bind. This is an initialization function that can
|
|
|
|
|
|
* only be called before `zts_node_start()`.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param port Port number
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_init_set_port(unsigned short port);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-01-30 13:53:49 -08:00
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Enable or disable whether the node will cache network details
|
|
|
|
|
|
* (enabled by default when `zts_init_from_storage()` is used.) Must be called before
|
|
|
|
|
|
* `zts_node_start()`.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This can potentially shorten (startup) times between node restarts. This allows the service to
|
|
|
|
|
|
* nearly instantly inform the network stack of an address to use for this peer
|
|
|
|
|
|
* so that it can create a transport service. This can be disabled for cases where one
|
|
|
|
|
|
* may not want network config details to be written to storage. This is
|
|
|
|
|
|
* especially useful for situations where address assignments do not change
|
|
|
|
|
|
* often.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* See also: `zts_init_allow_peer_cache()`
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*
|
|
|
|
|
|
* @param enabled Whether or not this feature is enabled
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2021-01-30 13:53:49 -08:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_init_allow_net_cache(unsigned int allowed);
|
2021-01-30 13:53:49 -08:00
|
|
|
|
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Enable or disable whether the node will cache peer details (enabled
|
|
|
|
|
|
* by default when `zts_init_from_storage()` is used.) Must be called before `zts_node_start()`.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This can potentially shorten (connection) times between node restarts. This allows the service to
|
|
|
|
|
|
* re-use previously discovered paths to a peer, this prevents the service from
|
|
|
|
|
|
* having to go through the entire transport-triggered link provisioning
|
|
|
|
|
|
* process. This is especially useful for situations where paths to peers do not
|
|
|
|
|
|
* change often. This is enabled by default and can be disabled for cases where
|
|
|
|
|
|
* one may not want peer details to be written to storage.
|
|
|
|
|
|
*
|
|
|
|
|
|
* See also: `zts_init_allow_net_cache()`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param enabled Whether or not this feature is enabled
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_init_allow_peer_cache(unsigned int allowed);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @brief Enable or disable whether the node will cache world definitions (enabled
|
|
|
|
|
|
* by default when `zts_init_from_storage()` is used.) Must be called before `zts_node_start()`.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @param enabled Whether or not this feature is enabled
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_init_allow_world_cache(unsigned int allowed);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Enable or disable whether the node will cache identities (enabled
|
|
|
|
|
|
* by default when `zts_init_from_storage()` is used.) Must be called before `zts_node_start()`.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param enabled Whether or not this feature is enabled
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_init_allow_id_cache(unsigned int allowed);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Return whether an address of the given family has been assigned by the network
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param family `ZTS_AF_INET`, or `ZTS_AF_INET6`
|
|
|
|
|
|
* @return `1` if true, `0` if false.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_addr_is_assigned(uint64_t net_id, unsigned int family);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Get the first-assigned IP on the given network.
|
|
|
|
|
|
*
|
|
|
|
|
|
* To get *all* assigned addresses on a given network, use `zts_addr_get_all()`.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param family `ZTS_AF_INET`, or `ZTS_AF_INET6`
|
|
|
|
|
|
* @param addr Destination buffer to hold address
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_addr_get(uint64_t net_id, unsigned int family, struct zts_sockaddr_storage* addr);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Get the first-assigned IP on the given network as a null-terminated human-readable string
|
|
|
|
|
|
*
|
|
|
|
|
|
* To get *all* assigned addresses on a given network, use `zts_addr_get_all()`.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param family `ZTS_AF_INET`, or `ZTS_AF_INET6`
|
|
|
|
|
|
* @param dst Destination buffer
|
|
|
|
|
|
* @param len Length of destination buffer (must be exactly `ZTS_IP_MAX_STR_LEN`)
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_addr_get_str(uint64_t net_id, unsigned int family, char* dst, unsigned int len);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Get all IP addresses assigned to this node by the given network
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param addr Destination buffer to hold address
|
|
|
|
|
|
* @param count Number of addresses returned
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_addr_get_all(uint64_t net_id, struct zts_sockaddr_storage* addr, unsigned int* count);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Compute a `6PLANE` IPv6 address for the given Network ID and Node ID
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param node_id Node ID
|
|
|
|
|
|
* @param addr Destination structure for address
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL
|
|
|
|
|
|
zts_addr_compute_6plane(const uint64_t net_id, const uint64_t node_id, struct zts_sockaddr_storage* addr);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Compute `RFC4193` IPv6 address for the given Network ID and Node ID
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param node_id Node ID
|
|
|
|
|
|
* @param addr Destination structure for address
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL
|
|
|
|
|
|
zts_addr_compute_rfc4193(const uint64_t net_id, const uint64_t node_id, struct zts_sockaddr_storage* addr);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Compute `RFC4193` IPv6 address for the given Network ID and Node ID and copy its
|
|
|
|
|
|
* null-terminated human-readable string representation into destination buffer.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param node_id Node ID
|
|
|
|
|
|
* @param dst Destination string buffer
|
|
|
|
|
|
* @param len Length of destination string buffer (must be exactly `ZTS_IP_MAX_STR_LEN`)
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_addr_compute_rfc4193_str(uint64_t net_id, uint64_t node_id, char* dst, unsigned int len);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Compute `6PLANE` IPv6 address for the given Network ID and Node ID and copy its
|
|
|
|
|
|
* null-terminated human-readable string representation into destination buffer.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param node_id Node ID
|
|
|
|
|
|
* @param dst Destination string buffer
|
|
|
|
|
|
* @param len Length of destination string buffer (must be exactly `ZTS_IP_MAX_STR_LEN`)
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_addr_compute_6plane_str(uint64_t net_id, uint64_t node_id, char* dst, unsigned int len);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Compute `RFC4193` IPv6 address for the given Network ID and Node ID
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* Ad-hoc Network:
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* ```
|
2020-05-01 19:15:38 -07:00
|
|
|
|
* ffSSSSEEEE000000
|
|
|
|
|
|
* | | | |
|
|
|
|
|
|
* | | | Reserved for future use, must be 0
|
|
|
|
|
|
* | | End of port range (hex)
|
|
|
|
|
|
* | Start of port range (hex)
|
|
|
|
|
|
* Reserved ZeroTier address prefix indicating a controller-less network.
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* ```
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* Ad-hoc networks are public (no access control) networks that have no network
|
|
|
|
|
|
* controller. Instead their configuration and other credentials are generated
|
|
|
|
|
|
* locally. Ad-hoc networks permit only IPv6 UDP and TCP unicast traffic
|
|
|
|
|
|
* (no multicast or broadcast) using 6plane format NDP-emulated IPv6 addresses.
|
|
|
|
|
|
* In addition an ad-hoc network ID encodes an IP port range. UDP packets and
|
|
|
|
|
|
* TCP SYN (connection open) packets are only allowed to destination ports
|
|
|
|
|
|
* within the encoded range.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* For example `ff00160016000000` is an ad-hoc network allowing only SSH,
|
|
|
|
|
|
* while `ff0000ffff000000` is an ad-hoc network allowing any UDP or TCP port.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* Keep in mind that these networks are public and anyone in the entire world
|
|
|
|
|
|
* can join them. Care must be taken to avoid exposing vulnerable services or
|
|
|
|
|
|
* sharing unwanted files or other resources.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param start_port Start of port allowed port range
|
|
|
|
|
|
* @param end_port End of allowed port range
|
2020-05-01 19:15:38 -07:00
|
|
|
|
* @return An Ad-hoc network ID
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API uint64_t ZTCALL zts_net_compute_adhoc_id(uint16_t start_port, uint16_t end_port);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Join a network
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_net_join(uint64_t net_id);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief Leave a network
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_net_leave(uint64_t net_id);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/**
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @brief Return whether this network is ready to send and receive traffic.
|
2021-04-22 11:20:04 -07:00
|
|
|
|
*
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @return `1` if true, `0` if false.
|
2021-04-22 11:20:04 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_net_transport_is_ready(const uint64_t net_id);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief Get the MAC Address for this node on the given network
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return MAC address in numerical format
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API uint64_t ZTCALL zts_net_get_mac(uint64_t net_id);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief Get the MAC Address for this node on the given network
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param dst Destination string buffer
|
|
|
|
|
|
* @param len Length of destination string buffer. Must be exactly `ZTS_MAC_ADDRSTRLEN`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return MAC address in string format
|
|
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_net_get_mac_str(uint64_t net_id, char* dst, unsigned int len);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return whether broadcast is enabled on this network
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `1` if true, `0` if false.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_net_get_broadcast(uint64_t net_id);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief Get the MTU of the given network
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return MTU
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_net_get_mtu(uint64_t net_id);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Get the nickname of the network
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param dst Destination string buffer
|
|
|
|
|
|
* @param len Length of destination string buffer
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
|
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_net_get_name(uint64_t net_id, char* dst, unsigned int len);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Get the status of the network
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return Status
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_net_get_status(uint64_t net_id);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Get the type of network (public or private.)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return Type
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_net_get_type(uint64_t net_id);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return whether a managed route of the given address family has been assigned by the
|
|
|
|
|
|
* network
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param net_id Network ID
|
|
|
|
|
|
* @param family `ZTS_AF_INET`, or `ZTS_AF_INET6`
|
|
|
|
|
|
* @return `1` if true, `0` if false.
|
|
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_route_is_assigned(uint64_t net_id, unsigned int family);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Start the ZeroTier node. Should be called after calling the relevant
|
|
|
|
|
|
* `zts_init_*` functions for your application. To enable storage call
|
|
|
|
|
|
* `zts_init_from_storage()` before this function. To enable event callbacks
|
|
|
|
|
|
* call `zts_init_set_event_handler()` before this function.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Note: If neither `zts_init_from_storage()` or `zts_init_from_memory()` are
|
|
|
|
|
|
* called a new identity will be generated and will be retrievable via
|
|
|
|
|
|
* `zts_node_get_id_pair()` *after* the node has started.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_node_start();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return whether the node is online (Can reach the Internet)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `1` if true, `0` if false.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_node_is_online();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Get the public node identity (aka `node_id`). Callable only after the node has been
|
|
|
|
|
|
* started.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return Identity in numerical form
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API uint64_t ZTCALL zts_node_get_id();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Copy the current node's public (and secret!) identity into a buffer.
|
|
|
|
|
|
*
|
|
|
|
|
|
* `WARNING`: This function exports your secret key and should be used carefully.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param key User-provided destination buffer
|
|
|
|
|
|
* @param key_buf_len Length of user-provided destination buffer. Will be set to
|
|
|
|
|
|
* number of bytes copied.
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
|
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_node_get_id_pair(char* key, unsigned int* key_buf_len);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Get the primary port to which the node is bound. Callable only after the node has been
|
|
|
|
|
|
* started.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return Port number
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_node_get_port();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Stop the ZeroTier node and bring down all virtual network
|
|
|
|
|
|
* transport services. Callable only after the node has been started.
|
|
|
|
|
|
*
|
|
|
|
|
|
* While the ZeroTier will stop, the stack driver (with associated
|
|
|
|
|
|
* timers) will remain active in case future traffic processing is required.
|
|
|
|
|
|
* To stop all activity and free all resources use `zts_free()` instead.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_node_stop();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Stop all background threads, bring down all transport services, free all
|
|
|
|
|
|
* resources. After calling this function an application restart will be
|
|
|
|
|
|
* required before the library can be used again. Callable only after the node
|
|
|
|
|
|
* has been started.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This should be called at the end of your program or when you do not
|
|
|
|
|
|
* anticipate communicating over ZeroTier again.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_node_free();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Orbit a given moon (user-defined root server)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param moon_world_id World ID
|
|
|
|
|
|
* @param moon_seed Seed ID
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_moon_orbit(uint64_t moon_world_id, uint64_t moon_seed);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief De-orbit a given moon (user-defined root server)
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param moon_world_id World ID
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_moon_deorbit(uint64_t moon_world_id);
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Statistics //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* Structure containing counters for various protocol statistics
|
|
|
|
|
|
*/
|
|
|
|
|
|
typedef struct {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
/** Number of link packets transmitted */
|
|
|
|
|
|
uint32_t link_tx;
|
|
|
|
|
|
/** Number of link packets received */
|
|
|
|
|
|
uint32_t link_rx;
|
|
|
|
|
|
/** Number of link packets dropped */
|
|
|
|
|
|
uint32_t link_drop;
|
|
|
|
|
|
/** Aggregate number of link-level errors */
|
|
|
|
|
|
uint32_t link_err;
|
|
|
|
|
|
|
|
|
|
|
|
/** Number of etharp packets transmitted */
|
|
|
|
|
|
uint32_t etharp_tx;
|
|
|
|
|
|
/** Number of etharp packets received */
|
|
|
|
|
|
uint32_t etharp_rx;
|
|
|
|
|
|
/** Number of etharp packets dropped */
|
|
|
|
|
|
uint32_t etharp_drop;
|
|
|
|
|
|
/** Aggregate number of etharp errors */
|
|
|
|
|
|
uint32_t etharp_err;
|
|
|
|
|
|
|
|
|
|
|
|
/** Number of IPv4 packets transmitted */
|
|
|
|
|
|
uint32_t ip4_tx;
|
|
|
|
|
|
/** Number of IPv4 packets received */
|
|
|
|
|
|
uint32_t ip4_rx;
|
|
|
|
|
|
/** Number of IPv4 packets dropped */
|
|
|
|
|
|
uint32_t ip4_drop;
|
|
|
|
|
|
/** Aggregate number of IPv4 errors */
|
|
|
|
|
|
uint32_t ip4_err;
|
|
|
|
|
|
|
|
|
|
|
|
/** Number of IPv6 packets transmitted */
|
|
|
|
|
|
uint32_t ip6_tx;
|
|
|
|
|
|
/** Number of IPv6 packets received */
|
|
|
|
|
|
uint32_t ip6_rx;
|
|
|
|
|
|
/** Number of IPv6 packets dropped */
|
|
|
|
|
|
uint32_t ip6_drop;
|
|
|
|
|
|
/** Aggregate number of IPv6 errors */
|
|
|
|
|
|
uint32_t ip6_err;
|
|
|
|
|
|
|
|
|
|
|
|
/** Number of ICMPv4 packets transmitted */
|
|
|
|
|
|
uint32_t icmp4_tx;
|
|
|
|
|
|
/** Number of ICMPv4 packets received */
|
|
|
|
|
|
uint32_t icmp4_rx;
|
|
|
|
|
|
/** Number of ICMPv4 packets dropped */
|
|
|
|
|
|
uint32_t icmp4_drop;
|
|
|
|
|
|
/** Aggregate number of ICMPv4 errors */
|
|
|
|
|
|
uint32_t icmp4_err;
|
|
|
|
|
|
|
|
|
|
|
|
/** Number of ICMPv6 packets transmitted */
|
|
|
|
|
|
uint32_t icmp6_tx;
|
|
|
|
|
|
/** Number of ICMPv6 packets received */
|
|
|
|
|
|
uint32_t icmp6_rx;
|
|
|
|
|
|
/** Number of ICMPv6 packets dropped */
|
|
|
|
|
|
uint32_t icmp6_drop;
|
|
|
|
|
|
/** Aggregate number of ICMPv6 errors */
|
|
|
|
|
|
uint32_t icmp6_err;
|
|
|
|
|
|
|
|
|
|
|
|
/** Number of UDP packets transmitted */
|
|
|
|
|
|
uint32_t udp_tx;
|
|
|
|
|
|
/** Number of UDP packets received */
|
|
|
|
|
|
uint32_t udp_rx;
|
|
|
|
|
|
/** Number of UDP packets dropped */
|
|
|
|
|
|
uint32_t udp_drop;
|
|
|
|
|
|
/** Aggregate number of UDP errors */
|
|
|
|
|
|
uint32_t udp_err;
|
|
|
|
|
|
|
|
|
|
|
|
/** Number of TCP packets transmitted */
|
|
|
|
|
|
uint32_t tcp_tx;
|
|
|
|
|
|
/** Number of TCP packets received */
|
|
|
|
|
|
uint32_t tcp_rx;
|
|
|
|
|
|
/** Number of TCP packets dropped */
|
|
|
|
|
|
uint32_t tcp_drop;
|
|
|
|
|
|
/** Aggregate number of TCP errors */
|
|
|
|
|
|
uint32_t tcp_err;
|
|
|
|
|
|
|
|
|
|
|
|
/** Number of ND6 packets transmitted */
|
|
|
|
|
|
uint32_t nd6_tx;
|
|
|
|
|
|
/** Number of ND6 packets received */
|
|
|
|
|
|
uint32_t nd6_rx;
|
|
|
|
|
|
/** Number of ND6 packets dropped */
|
|
|
|
|
|
uint32_t nd6_drop;
|
|
|
|
|
|
/** Aggregate number of ND6 errors */
|
|
|
|
|
|
uint32_t nd6_err;
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_stats_counter_t;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Get all statistical counters for all protocols and levels, where
|
|
|
|
|
|
* *all* means *most*. If you need anything more detailed you should inspect
|
|
|
|
|
|
* what is available in `lwip/stats.h`.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* This function can only be used in debug builds.
|
2021-04-22 11:20:04 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param dst Pointer to structure that will be populated with statistics
|
|
|
|
|
|
*
|
2020-05-01 19:15:38 -07:00
|
|
|
|
* @return ZTS_ERR_OK on success. ZTS_ERR_ARG or ZTS_ERR_NO_RESULT on failure.
|
|
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_stats_get_all(zts_stats_counter_t* dst);
|
2021-03-01 22:34:12 -08:00
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Socket API //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Create a socket
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param family `ZTS_AF_INET` or `ZTS_AF_INET6`
|
|
|
|
|
|
* @param type `ZTS_SOCK_STREAM` or `ZTS_SOCK_DGRAM`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
* @param protocol Protocols supported on this socket
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return Numbered file descriptor on success, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_socket(int family, int type, int protocol);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Connect a socket to a remote host
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param addr Remote host address to connect to
|
|
|
|
|
|
* @param addrlen Length of address
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_connect(int fd, const struct zts_sockaddr* addr, zts_socklen_t addrlen);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Connect a socket to a remote host
|
|
|
|
|
|
*
|
2021-03-26 16:33:22 -07:00
|
|
|
|
* This convenience function exists because ZeroTier uses transport-triggered
|
|
|
|
|
|
* links. This means that links between peers do not exist until peers try to
|
|
|
|
|
|
* talk to each other. This can be a problem during connection procedures since
|
|
|
|
|
|
* some of the initial packets are lost. To alleviate the need to try
|
|
|
|
|
|
* `zts_connect` many times, this function will keep re-trying for you, even if
|
|
|
|
|
|
* no known routes exist. However, if the socket is set to `non-blocking` mode
|
|
|
|
|
|
* it will behave identically to `zts_connect` and return immediately upon
|
|
|
|
|
|
* failure.
|
|
|
|
|
|
*
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param ipstr Human-readable IP string
|
|
|
|
|
|
* @param port Port
|
2021-03-26 16:33:22 -07:00
|
|
|
|
* @param timeout_ms (Approximate) amount of time in milliseconds before
|
|
|
|
|
|
* connection attempt is aborted. Will block for `30 seconds` if timeout is
|
|
|
|
|
|
* set to `0`.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SOCKET` if the function times
|
|
|
|
|
|
* out with no connection made, `ZTS_ERR_SERVICE` if the node experiences a
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_connect(int fd, const char* ipstr, int port, int timeout_ms);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Bind a socket to a local address
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param addr Local interface address to bind to
|
|
|
|
|
|
* @param addrlen Length of address
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_bind(int fd, const struct zts_sockaddr* addr, zts_socklen_t addrlen);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Bind a socket to a local address
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param ipstr Human-readable IP string
|
|
|
|
|
|
* @param port Port
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_bind(int fd, const char* ipstr, int port);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Listen for incoming connections on socket
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param backlog Number of backlogged connections allowed
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2020-05-30 18:29:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_listen(int fd, int backlog);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Accept an incoming connection
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param addr Address of remote host for accepted connection
|
|
|
|
|
|
* @param addrlen Length of address
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return New file descriptor if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_accept(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-03-26 16:33:22 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief Accept an incoming connection
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param remote_addr Buffer that will receive remote host IP string
|
2021-03-26 16:33:22 -07:00
|
|
|
|
* @param len Size of buffer that will receive remote host IP string
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* (must be exactly `ZTS_IP_MAX_STR_LEN`)
|
2021-03-26 16:33:22 -07:00
|
|
|
|
* @param port Port number of the newly connected remote host (value-result)
|
|
|
|
|
|
* @return New file descriptor if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_simple_accept(int fd, char* remote_addr, int len, int* port);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief A convenience function that takes a remote address IP string and creates
|
|
|
|
|
|
* the appropriate type of socket, and uses it to connect to a remote host.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param remote_ipstr Remote address string. IPv4 or IPv6
|
|
|
|
|
|
* @param remote_port Port to
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return New file descriptor if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_simple_tcp_client(const char* remote_ipstr, int remote_port);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief A convenience function that takes a remote address IP string and creates
|
|
|
|
|
|
* the appropriate type of socket, binds, listens, and then accepts on it.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param local_ipstr Local address to bind
|
|
|
|
|
|
* @param local_port Local port to bind
|
|
|
|
|
|
* @param remote_ipstr String-format IP address of newly connected remote host
|
|
|
|
|
|
* @param len Length of `remote_ipstr`
|
|
|
|
|
|
* @param remote_port Port of remote host
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return New file descriptor if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
|
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL
|
|
|
|
|
|
zts_simple_tcp_server(const char* local_ipstr, int local_port, char* remote_ipstr, int len, int* remote_port);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief A convenience function that takes a remote address IP string and creates
|
|
|
|
|
|
* the appropriate type of socket, and binds to it.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param local_ipstr Local address to bind
|
|
|
|
|
|
* @param local_port Local port to bind
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return New file descriptor if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-26 16:33:22 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_udp_server(const char* local_ipstr, int local_port);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief This function doesn't really do anything other than be a namespace
|
|
|
|
|
|
* counterpart to `zts_simple_udp_server`. All this function does is create a
|
|
|
|
|
|
* `ZTS_SOCK_DGRAM` socket and return its file descriptor.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param remote_ipstr Remote address string. IPv4 or IPv6
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return New file descriptor if successful, `ZTS_ERR_SERVICE` if the node
|
|
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_simple_udp_client(const char* remote_ipstr);
|
2021-03-26 16:33:22 -07:00
|
|
|
|
|
2020-05-01 19:15:38 -07:00
|
|
|
|
// Socket level option number
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_SOL_SOCKET 0x0fff
|
2020-05-01 19:15:38 -07:00
|
|
|
|
// Socket options
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_SO_DEBUG 0x0001 // NOT YET SUPPORTED
|
|
|
|
|
|
#define ZTS_SO_ACCEPTCONN 0x0002
|
|
|
|
|
|
#define ZTS_SO_REUSEADDR 0x0004
|
|
|
|
|
|
#define ZTS_SO_KEEPALIVE 0x0008
|
|
|
|
|
|
#define ZTS_SO_DONTROUTE 0x0010 // NOT YET SUPPORTED
|
|
|
|
|
|
#define ZTS_SO_BROADCAST 0x0020
|
|
|
|
|
|
#define ZTS_SO_USELOOPBACK 0x0040 // NOT YET SUPPORTED
|
|
|
|
|
|
#define ZTS_SO_LINGER 0x0080
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Structure used for manipulating linger option.
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct zts_linger {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
int l_onoff; // option on/off
|
|
|
|
|
|
int l_linger; // linger time in seconds
|
2020-05-01 19:15:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define ZTS_SO_DONTLINGER ((int)(~ZTS_SO_LINGER))
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_SO_OOBINLINE 0x0100 // NOT YET SUPPORTED
|
|
|
|
|
|
#define ZTS_SO_REUSEPORT 0x0200 // NOT YET SUPPORTED
|
|
|
|
|
|
#define ZTS_SO_SNDBUF 0x1001 // NOT YET SUPPORTED
|
2020-05-01 19:15:38 -07:00
|
|
|
|
#define ZTS_SO_RCVBUF 0x1002
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_SO_SNDLOWAT 0x1003 // NOT YET SUPPORTED
|
|
|
|
|
|
#define ZTS_SO_RCVLOWAT 0x1004 // NOT YET SUPPORTED
|
2020-05-01 19:15:38 -07:00
|
|
|
|
#define ZTS_SO_SNDTIMEO 0x1005
|
|
|
|
|
|
#define ZTS_SO_RCVTIMEO 0x1006
|
|
|
|
|
|
#define ZTS_SO_ERROR 0x1007
|
|
|
|
|
|
#define ZTS_SO_TYPE 0x1008
|
|
|
|
|
|
#define ZTS_SO_CONTIMEO 0x1009
|
|
|
|
|
|
#define ZTS_SO_NO_CHECK 0x100a
|
|
|
|
|
|
#define ZTS_SO_BINDTODEVICE 0x100b
|
|
|
|
|
|
// IPPROTO_IP options
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_IP_TOS 0x0001
|
|
|
|
|
|
#define ZTS_IP_TTL 0x0002
|
|
|
|
|
|
#define ZTS_IP_PKTINFO 0x0008
|
2020-05-01 19:15:38 -07:00
|
|
|
|
// IPPROTO_TCP options
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_TCP_NODELAY 0x0001
|
|
|
|
|
|
#define ZTS_TCP_KEEPALIVE 0x0002
|
|
|
|
|
|
#define ZTS_TCP_KEEPIDLE 0x0003
|
|
|
|
|
|
#define ZTS_TCP_KEEPINTVL 0x0004
|
|
|
|
|
|
#define ZTS_TCP_KEEPCNT 0x0005
|
2020-05-01 19:15:38 -07:00
|
|
|
|
// IPPROTO_IPV6 options
|
2021-04-26 21:55:01 -07:00
|
|
|
|
#define ZTS_IPV6_CHECKSUM \
|
2021-04-26 22:07:55 -07:00
|
|
|
|
0x0007 /* RFC3542: calculate and insert the ICMPv6 checksum for raw \
|
|
|
|
|
|
sockets. */
|
2021-04-26 21:55:01 -07:00
|
|
|
|
#define ZTS_IPV6_V6ONLY \
|
2021-04-26 22:07:55 -07:00
|
|
|
|
0x001b /* RFC3493: boolean control to restrict ZTS_AF_INET6 sockets to \
|
|
|
|
|
|
IPv6 communications only. */
|
2020-05-01 19:15:38 -07:00
|
|
|
|
// UDPLITE options
|
|
|
|
|
|
#define ZTS_UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
|
|
|
|
|
|
#define ZTS_UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
|
|
|
|
|
|
// UDPLITE options
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_IP_MULTICAST_TTL 5
|
|
|
|
|
|
#define ZTS_IP_MULTICAST_IF 6
|
|
|
|
|
|
#define ZTS_IP_MULTICAST_LOOP 7
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
// Multicast options
|
|
|
|
|
|
#define ZTS_IP_ADD_MEMBERSHIP 3
|
|
|
|
|
|
#define ZTS_IP_DROP_MEMBERSHIP 4
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct zts_ip_mreq {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
struct zts_in_addr imr_multiaddr; /* IP multicast address of group */
|
|
|
|
|
|
struct zts_in_addr imr_interface; /* local IP address of interface */
|
2020-05-01 19:15:38 -07:00
|
|
|
|
} zts_ip_mreq;
|
|
|
|
|
|
|
|
|
|
|
|
struct zts_in_pktinfo {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
unsigned int ipi_ifindex; /* Interface index */
|
|
|
|
|
|
struct zts_in_addr ipi_addr; /* Destination (from header) address */
|
2020-05-01 19:15:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define ZTS_IPV6_JOIN_GROUP 12
|
|
|
|
|
|
#define ZTS_IPV6_ADD_MEMBERSHIP ZTS_IPV6_JOIN_GROUP
|
|
|
|
|
|
#define ZTS_IPV6_LEAVE_GROUP 13
|
|
|
|
|
|
#define ZTS_IPV6_DROP_MEMBERSHIP ZTS_IPV6_LEAVE_GROUP
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct zts_ipv6_mreq {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
struct zts_in6_addr ipv6mr_multiaddr; /* IPv6 multicast addr */
|
|
|
|
|
|
unsigned int ipv6mr_interface; /* interface index, or 0 */
|
2020-05-01 19:15:38 -07:00
|
|
|
|
} zts_ipv6_mreq;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* The Type of Service provides an indication of the abstract
|
|
|
|
|
|
* parameters of the quality of service desired. These parameters are
|
|
|
|
|
|
* to be used to guide the selection of the actual service parameters
|
|
|
|
|
|
* when transmitting a datagram through a particular network. Several
|
|
|
|
|
|
* networks offer service precedence, which somehow treats high
|
|
|
|
|
|
* precedence traffic as more important than other traffic (generally
|
|
|
|
|
|
* by accepting only traffic above a certain precedence at time of high
|
|
|
|
|
|
* load). The major choice is a three way tradeoff between low-delay,
|
|
|
|
|
|
* high-reliability, and high-throughput.
|
|
|
|
|
|
* The use of the Delay, Throughput, and Reliability indications may
|
|
|
|
|
|
* increase the cost (in some sense) of the service. In many networks
|
|
|
|
|
|
* better performance for one of these parameters is coupled with worse
|
|
|
|
|
|
* performance on another. Except for very unusual cases at most two
|
|
|
|
|
|
* of these three indications should be set.
|
|
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_IPTOS_TOS_MASK 0x1E
|
|
|
|
|
|
#define ZTS_IPTOS_TOS(tos) ((tos)&ZTS_IPTOS_TOS_MASK)
|
|
|
|
|
|
#define ZTS_IPTOS_LOWDELAY 0x10
|
|
|
|
|
|
#define ZTS_IPTOS_THROUGHPUT 0x08
|
|
|
|
|
|
#define ZTS_IPTOS_RELIABILITY 0x04
|
|
|
|
|
|
#define ZTS_IPTOS_LOWCOST 0x02
|
|
|
|
|
|
#define ZTS_IPTOS_MINCOST ZTS_IPTOS_LOWCOST
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* The Network Control precedence designation is intended to be used
|
|
|
|
|
|
* within a network only. The actual use and control of that
|
|
|
|
|
|
* designation is up to each network. The Internetwork Control
|
|
|
|
|
|
* designation is intended for use by gateway control originators only.
|
|
|
|
|
|
* If the actual use of these precedence designations is of concern to
|
|
|
|
|
|
* a particular network, it is the responsibility of that network to
|
|
|
|
|
|
* control the access to, and use of, those precedence designations.
|
|
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_IPTOS_PREC_MASK 0xe0
|
|
|
|
|
|
#define ZTS_IPTOS_PREC(tos) ((tos)&ZTS_IPTOS_PREC_MASK)
|
|
|
|
|
|
#define ZTS_IPTOS_PREC_NETCONTROL 0xe0
|
|
|
|
|
|
#define ZTS_IPTOS_PREC_INTERNETCONTROL 0xc0
|
|
|
|
|
|
#define ZTS_IPTOS_PREC_CRITIC_ECP 0xa0
|
|
|
|
|
|
#define ZTS_IPTOS_PREC_FLASHOVERRIDE 0x80
|
|
|
|
|
|
#define ZTS_IPTOS_PREC_FLASH 0x60
|
|
|
|
|
|
#define ZTS_IPTOS_PREC_IMMEDIATE 0x40
|
|
|
|
|
|
#define ZTS_IPTOS_PREC_PRIORITY 0x20
|
|
|
|
|
|
#define ZTS_IPTOS_PREC_ROUTINE 0x00
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Set socket options.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param level Protocol level to which option name should apply
|
|
|
|
|
|
* @param optname Option name to set
|
|
|
|
|
|
* @param optval Source of option value to set
|
|
|
|
|
|
* @param optlen Length of option value
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_setsockopt(int fd, int level, int optname, const void* optval, zts_socklen_t optlen);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Get socket options.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param level Protocol level to which option name should apply
|
|
|
|
|
|
* @param optname Option name to get
|
|
|
|
|
|
* @param optval Where option value will be stored
|
|
|
|
|
|
* @param optlen Length of value
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_getsockopt(int fd, int level, int optname, void* optval, zts_socklen_t* optlen);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Get socket name.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param addr Name associated with this socket
|
|
|
|
|
|
* @param addrlen Length of name
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_getsockname(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Get the peer name for the remote end of a connected socket.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param addr Name associated with remote end of this socket
|
|
|
|
|
|
* @param addrlen Length of name
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_getpeername(int fd, struct zts_sockaddr* addr, zts_socklen_t* addrlen);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Close socket.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2020-05-30 18:29:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_close(int fd);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/* FD_SET used for lwip_select */
|
|
|
|
|
|
|
2020-05-30 18:29:04 -07:00
|
|
|
|
#define LWIP_SOCKET_OFFSET 0
|
|
|
|
|
|
#define MEMP_NUM_NETCONN 1024
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
#ifndef ZTS_FD_SET
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#undef ZTS_FD_SETSIZE
|
|
|
|
|
|
// Make FD_SETSIZE match NUM_SOCKETS in socket.c
|
|
|
|
|
|
#define ZTS_FD_SETSIZE MEMP_NUM_NETCONN
|
2021-04-26 21:55:01 -07:00
|
|
|
|
#define ZTS_FDSETSAFESET(n, code) \
|
2021-04-26 22:07:55 -07:00
|
|
|
|
do { \
|
|
|
|
|
|
if (((n)-LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n)-LWIP_SOCKET_OFFSET) >= 0)) { \
|
|
|
|
|
|
code; \
|
|
|
|
|
|
} \
|
|
|
|
|
|
} while (0)
|
2021-04-26 21:55:01 -07:00
|
|
|
|
#define ZTS_FDSETSAFEGET(n, code) \
|
2021-04-26 22:07:55 -07:00
|
|
|
|
(((n)-LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n)-LWIP_SOCKET_OFFSET) >= 0) ? (code) : 0)
|
2021-04-26 21:55:01 -07:00
|
|
|
|
#define ZTS_FD_SET(n, p) \
|
2021-04-26 22:07:55 -07:00
|
|
|
|
ZTS_FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET) / 8] |= (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
|
2021-04-26 21:55:01 -07:00
|
|
|
|
#define ZTS_FD_CLR(n, p) \
|
2021-04-26 22:07:55 -07:00
|
|
|
|
ZTS_FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET) / 8] &= ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
|
2021-04-26 21:55:01 -07:00
|
|
|
|
#define ZTS_FD_ISSET(n, p) \
|
2021-04-26 22:07:55 -07:00
|
|
|
|
ZTS_FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET) / 8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#define ZTS_FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
#elif LWIP_SOCKET_OFFSET
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#error LWIP_SOCKET_OFFSET does not work with external FD_SET!
|
2020-05-01 19:15:38 -07:00
|
|
|
|
#elif ZTS_FD_SETSIZE < MEMP_NUM_NETCONN
|
2021-04-22 11:20:04 -07:00
|
|
|
|
#error "external ZTS_FD_SETSIZE too small for number of sockets"
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#endif // FD_SET
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
typedef struct zts_fd_set {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
unsigned char fd_bits[(ZTS_FD_SETSIZE + 7) / 8];
|
2020-05-01 19:15:38 -07:00
|
|
|
|
} zts_fd_set;
|
|
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
typedef struct zts_timeval {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
long tv_sec; /* seconds */
|
|
|
|
|
|
long tv_usec; /* and microseconds */
|
2021-04-22 11:20:04 -07:00
|
|
|
|
} zts_timeval;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Monitor multiple file descriptors for "readiness"
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param nfds Set to the highest numbered file descriptor in any of the given
|
|
|
|
|
|
* sets
|
2020-05-01 19:15:38 -07:00
|
|
|
|
* @param readfds Set of file descriptors to monitor for READ readiness
|
|
|
|
|
|
* @param writefds Set of file descriptors to monitor for WRITE readiness
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param exceptfds Set of file descriptors to monitor for exceptional
|
|
|
|
|
|
* conditions
|
2020-05-01 19:15:38 -07:00
|
|
|
|
* @param timeout How long this call should block
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @return Number of ready file descriptors on success. `ZTS_ERR_SOCKET`,
|
|
|
|
|
|
* `ZTS_ERR_SERVICE` on failure. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL
|
|
|
|
|
|
zts_select(int nfds, zts_fd_set* readfds, zts_fd_set* writefds, zts_fd_set* exceptfds, struct zts_timeval* timeout);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
// fnctl() commands
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_F_GETFL 0x0003
|
|
|
|
|
|
#define ZTS_F_SETFL 0x0004
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/* File status flags and file access modes for fnctl,
|
|
|
|
|
|
these are bits in an int. */
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_O_NONBLOCK 1
|
|
|
|
|
|
#define ZTS_O_NDELAY ZTS_O_NONBLOCK
|
|
|
|
|
|
#define ZTS_O_RDONLY 2
|
|
|
|
|
|
#define ZTS_O_WRONLY 4
|
|
|
|
|
|
#define ZTS_O_RDWR (ZTS_O_RDONLY | ZTS_O_WRONLY)
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Issue file control commands on a socket
|
|
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param cmd Operation to be performed
|
|
|
|
|
|
* @param flags Flags
|
2020-05-01 19:15:38 -07:00
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2020-05-30 18:29:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_fcntl(int fd, int cmd, int flags);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_POLLIN 0x001
|
|
|
|
|
|
#define ZTS_POLLOUT 0x002
|
|
|
|
|
|
#define ZTS_POLLERR 0x004
|
|
|
|
|
|
#define ZTS_POLLNVAL 0x008
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/* Below values are unimplemented */
|
|
|
|
|
|
#define ZTS_POLLRDNORM 0x010
|
|
|
|
|
|
#define ZTS_POLLRDBAND 0x020
|
|
|
|
|
|
#define ZTS_POLLPRI 0x040
|
|
|
|
|
|
#define ZTS_POLLWRNORM 0x080
|
|
|
|
|
|
#define ZTS_POLLWRBAND 0x100
|
|
|
|
|
|
#define ZTS_POLLHUP 0x200
|
|
|
|
|
|
|
|
|
|
|
|
typedef unsigned int zts_nfds_t;
|
|
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
struct zts_pollfd {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
int fd;
|
|
|
|
|
|
short events;
|
|
|
|
|
|
short revents;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Wait for some event on a file descriptor.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fds Set of file descriptors to monitor
|
|
|
|
|
|
* @param nfds Number of elements in the fds array
|
|
|
|
|
|
* @param timeout How long this call should block
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @return Number of ready file descriptors if successful, `ZTS_ERR_SERVICE` if
|
|
|
|
|
|
* the node experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets
|
|
|
|
|
|
* `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_poll(struct zts_pollfd* fds, zts_nfds_t nfds, int timeout);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Control a device
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param request Selects the control function to be performed
|
|
|
|
|
|
* @param argp Additional information
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_ioctl(int fd, unsigned long request, void* argp);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Send data to remote host
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param buf Pointer to data buffer
|
|
|
|
|
|
* @param len Length of data to write
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @param flags (e.g. `ZTS_MSG_DONTWAIT`, `ZTS_MSG_MORE`)
|
|
|
|
|
|
* @return Number of bytes sent if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API ssize_t ZTCALL zts_send(int fd, const void* buf, size_t len, int flags);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Send data to remote host
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param buf Pointer to data buffer
|
|
|
|
|
|
* @param len Length of data to write
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param flags Specifies type of message transmission
|
2020-05-01 19:15:38 -07:00
|
|
|
|
* @param addr Destination address
|
|
|
|
|
|
* @param addrlen Length of destination address
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return Number of bytes sent if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API ssize_t ZTCALL
|
|
|
|
|
|
zts_sendto(int fd, const void* buf, size_t len, int flags, const struct zts_sockaddr* addr, zts_socklen_t addrlen);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
struct zts_iovec {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
void* iov_base;
|
|
|
|
|
|
size_t iov_len;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* */
|
|
|
|
|
|
struct zts_msghdr {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
void* msg_name;
|
|
|
|
|
|
zts_socklen_t msg_namelen;
|
|
|
|
|
|
struct zts_iovec* msg_iov;
|
|
|
|
|
|
int msg_iovlen;
|
|
|
|
|
|
void* msg_control;
|
|
|
|
|
|
zts_socklen_t msg_controllen;
|
|
|
|
|
|
int msg_flags;
|
2020-05-01 19:15:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* struct msghdr->msg_flags bit field values */
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#define ZTS_MSG_TRUNC 0x04
|
|
|
|
|
|
#define ZTS_MSG_CTRUNC 0x08
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Send message to remote host
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param msg Message to send
|
|
|
|
|
|
* @param flags Specifies type of message transmission
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return Number of bytes sent if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API ssize_t ZTCALL zts_sendmsg(int fd, const struct zts_msghdr* msg, int flags);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Receive data from remote host
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param buf Pointer to data buffer
|
|
|
|
|
|
* @param len Length of data buffer
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param flags Specifies the type of message receipt
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return Number of bytes received if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API ssize_t ZTCALL zts_recv(int fd, void* buf, size_t len, int flags);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Receive data from remote host
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param buf Pointer to data buffer
|
|
|
|
|
|
* @param len Length of data buffer
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param flags Specifies the type of message receipt
|
|
|
|
|
|
* @param addr Destination address buffer
|
|
|
|
|
|
* @param addrlen Length of destination address buffer
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return Number of bytes received if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API ssize_t ZTCALL
|
|
|
|
|
|
zts_recvfrom(int fd, void* buf, size_t len, int flags, struct zts_sockaddr* addr, zts_socklen_t* addrlen);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Receive a message from remote host
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param msg Message that was received
|
|
|
|
|
|
* @param flags Specifies the type of message receipt
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return Number of bytes received if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API ssize_t ZTCALL zts_recvmsg(int fd, struct zts_msghdr* msg, int flags);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Read data from socket onto buffer
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param buf Pointer to data buffer
|
|
|
|
|
|
* @param len Length of data buffer to receive data
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return Number of bytes read if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API ssize_t ZTCALL zts_read(int fd, void* buf, size_t len);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Read data from socket into multiple buffers
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param iov Array of destination buffers
|
|
|
|
|
|
* @param iovcnt Number of buffers to read into
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return Number of bytes read if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API ssize_t ZTCALL zts_readv(int fd, const struct zts_iovec* iov, int iovcnt);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @brief Write data from buffer to socket
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param buf Pointer to data buffer
|
|
|
|
|
|
* @param len Length of buffer to write
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return Number of bytes written if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API ssize_t ZTCALL zts_write(int fd, const void* buf, size_t len);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Write data from multiple buffers to socket.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param iov Array of source buffers
|
|
|
|
|
|
* @param iovcnt Number of buffers to read from
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return Number of bytes written if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API ssize_t ZTCALL zts_writev(int fd, const struct zts_iovec* iov, int iovcnt);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
#define ZTS_SHUT_RD 0x0
|
|
|
|
|
|
#define ZTS_SHUT_WR 0x1
|
|
|
|
|
|
#define ZTS_SHUT_RDWR 0x2
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Shut down some aspect of a socket
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param how Which aspects of the socket should be shut down. Options are `ZTS_SHUT_RD`,
|
|
|
|
|
|
* `ZTS_SHUT_WR`, or `ZTS_SHUT_RDWR`.
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2020-05-30 18:29:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_shutdown(int fd, int how);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Convenience functions //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Enable or disable `TCP_NODELAY`. Enabling this is equivalent to
|
|
|
|
|
|
* turning off Nagle's algorithm
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param enabled `[0, 1]` integer value
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_set_no_delay(int fd, int enabled);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return whether `TCP_NODELAY` is enabled
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @return `1` if enabled, `0` if disabled, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_get_no_delay(int fd);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Enable or disable `SO_LINGER` while also setting its value
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param enabled `[0, 1]` integer value
|
|
|
|
|
|
* @param value How long socket should linger
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_set_linger(int fd, int enabled, int value);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return whether `SO_LINGER` is enabled
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @return `1` if enabled, `0` if disabled, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_get_linger_enabled(int fd);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return the value of `SO_LINGER`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @return Value of `SO_LINGER` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_get_linger_value(int fd);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Enable or disable `SO_REUSEADDR`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param enabled `[0, 1]` integer value
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_set_reuse_addr(int fd, int enabled);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return whether `SO_REUSEADDR` is enabled
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @return `1` if enabled, `0` if disabled, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_get_reuse_addr(int fd);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Set the value of `SO_RCVTIMEO`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param seconds Number of seconds for timeout
|
|
|
|
|
|
* @param microseconds Number of microseconds for timeout
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_set_recv_timeout(int fd, int seconds, int microseconds);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return the value of `SO_RCVTIMEO`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @return Value of `SO_RCVTIMEO` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_get_recv_timeout(int fd);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Set the value of `SO_SNDTIMEO`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param seconds Number of seconds for timeout
|
|
|
|
|
|
* @param microseconds Number of microseconds for timeout
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_set_send_timeout(int fd, int seconds, int microseconds);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return the value of `SO_SNDTIMEO`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @return Value of `SO_SNDTIMEO` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_get_send_timeout(int fd);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Set the value of `SO_SNDBUF`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param size Size of buffer
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_set_send_buf_size(int fd, int size);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return the value of `SO_SNDBUF`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @return Value of `SO_SNDBUF` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_get_send_buf_size(int fd);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Set the value of `SO_RCVBUF`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param size Size of buffer
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_set_recv_buf_size(int fd, int size);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return the value of `SO_RCVBUF`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @return Value of `SO_RCVBUF` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_get_recv_buf_size(int fd);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Set the value of `IP_TTL`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param ttl Value of `IP_TTL`
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_set_ttl(int fd, int ttl);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return the value of `IP_TTL`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @return Value of `IP_TTL` `[0,255]` if successful, `ZTS_ERR_SERVICE` if the
|
|
|
|
|
|
* node experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_get_ttl(int fd);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Change blocking behavior `O_NONBLOCK`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param enabled `[0, 1]` integer value, `1` maintains default behavior,
|
|
|
|
|
|
* `0` sets to non-blocking mode
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_set_blocking(int fd, int enabled);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return whether blocking mode `O_NONBLOCK` is enabled
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @return `1` if enabled, `0` if disabled, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_get_blocking(int fd);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Enable or disable `SO_KEEPALIVE`
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @param enabled `[0, 1]` integer value
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_set_keepalive(int fd, int enabled);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return whether `SO_KEEPALIVE` is enabled
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param fd Socket file descriptor
|
|
|
|
|
|
* @return `1` if enabled, `0` if disabled, `ZTS_ERR_SERVICE` if the node
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* experiences a problem, `ZTS_ERR_ARG` if invalid argument. Sets `zts_errno`
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_simple_get_keepalive(int fd);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// DNS //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
2021-03-16 00:31:45 -07:00
|
|
|
|
|
|
|
|
|
|
struct zts_hostent {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
char* h_name; /* Official name of the host. */
|
|
|
|
|
|
char** h_aliases; /* A pointer to an array of pointers to alternative host
|
|
|
|
|
|
names, terminated by a null pointer. */
|
|
|
|
|
|
int h_addrtype; /* Address type. */
|
|
|
|
|
|
int h_length; /* The length, in bytes, of the address. */
|
|
|
|
|
|
char** h_addr_list; /* A pointer to an array of pointers to network
|
|
|
|
|
|
addresses (in network byte order) for the host,
|
|
|
|
|
|
terminated by a null pointer. */
|
2021-03-16 00:31:45 -07:00
|
|
|
|
#define h_addr h_addr_list[0] /* for backward compatibility */
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @brief Resolve a host-name
|
2021-03-16 00:31:45 -07:00
|
|
|
|
*
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @param name A null-terminated string representing the name of the host
|
2021-03-16 00:31:45 -07:00
|
|
|
|
* @return Pointer to struct zts_hostent if successful, NULL otherwise
|
|
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
struct zts_hostent* zts_gethostbyname(const char* name);
|
2021-03-16 00:31:45 -07:00
|
|
|
|
|
|
|
|
|
|
struct zts_ip4_addr {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
uint32_t addr;
|
2021-03-16 00:31:45 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** This is the aligned version of ip6_addr_t,
|
2021-04-17 23:46:21 -07:00
|
|
|
|
used as local variable, on the stack, etc. */
|
2021-03-16 00:31:45 -07:00
|
|
|
|
struct zts_ip6_addr {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
uint32_t addr[4];
|
2021-03-16 00:31:45 -07:00
|
|
|
|
#if LWIP_IPV6_SCOPES
|
2021-04-26 22:07:55 -07:00
|
|
|
|
uint8_t zone;
|
2021-03-16 00:31:45 -07:00
|
|
|
|
#endif /* LWIP_IPV6_SCOPES */
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* A union struct for both IP version's addresses.
|
|
|
|
|
|
* ATTENTION: watch out for its size when adding IPv6 address scope!
|
|
|
|
|
|
*/
|
|
|
|
|
|
typedef struct zts_ip_addr {
|
2021-04-26 22:07:55 -07:00
|
|
|
|
union {
|
|
|
|
|
|
struct zts_ip6_addr ip6;
|
|
|
|
|
|
struct zts_ip4_addr ip4;
|
|
|
|
|
|
} u_addr;
|
|
|
|
|
|
uint8_t type; // ZTS_IPADDR_TYPE_V4, ZTS_IPADDR_TYPE_V6
|
2021-03-16 00:31:45 -07:00
|
|
|
|
} zts_ip_addr;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Initialize one of the DNS servers.
|
|
|
|
|
|
*
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param index the index of the DNS server to set must be `< DNS_MAX_SERVERS`
|
2021-03-16 00:31:45 -07:00
|
|
|
|
* @param addr IP address of the DNS server to set
|
|
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_dns_set_server(uint8_t index, const zts_ip_addr* addr);
|
2021-03-16 00:31:45 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Obtain one of the currently configured DNS server.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param index the index of the DNS server
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @return IP address of the indexed DNS server or `ip_addr_any` if the DNS
|
2021-03-16 00:31:45 -07:00
|
|
|
|
* server has not been configured.
|
|
|
|
|
|
*/
|
2021-04-17 23:46:21 -07:00
|
|
|
|
ZTS_API const zts_ip_addr* ZTCALL zts_dns_get_server(uint8_t index);
|
2021-03-16 00:31:45 -07:00
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
2021-04-26 21:55:01 -07:00
|
|
|
|
// Core query sub-API (Used for simplifying high-level language wrappers) //
|
2021-03-24 12:20:39 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
2020-05-01 19:15:38 -07:00
|
|
|
|
/**
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @brief Lock the core service so that queries about addresses, routes, paths, etc. can be
|
|
|
|
|
|
* performed.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* `Notice`: `zts_core_` functions are intended to be used by high-level language wrappers.
|
|
|
|
|
|
* Only lock the core if you know *exactly* what you are doing.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_SERVICE` if the core service is unavailable.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_core_lock_obtain();
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @brief Lock the core service so that queries about addresses, routes, paths, etc. can be
|
|
|
|
|
|
* performed.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* `Notice`: `zts_core_` functions are intended to be used by high-level language wrappers.
|
|
|
|
|
|
* Only lock the core if you know *exactly* what you are doing.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_SERVICE` if the core service is unavailable.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_core_lock_release();
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @brief Lock the core service so that queries about addresses, routes, paths, etc. can be
|
|
|
|
|
|
* performed.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* `Notice`: `zts_core_` functions are intended to be used by high-level language wrappers.
|
|
|
|
|
|
* Only lock the core if you know *exactly* what you are doing. `zts_core_lock_obtain()` and
|
|
|
|
|
|
* `zts_core_lock_release()` must be called before and after this function.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_SERVICE` if the core service is unavailable.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_core_query_addr_count(uint64_t net_id);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @brief Lock the core service so that queries about addresses, routes, paths, etc. can be
|
|
|
|
|
|
* performed.
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* `Notice`: `zts_core_` functions are intended to be used by high-level language wrappers.
|
|
|
|
|
|
* Only lock the core if you know *exactly* what you are doing. `zts_core_lock_obtain()` and
|
|
|
|
|
|
* `zts_core_lock_release()` must be called before and after this function.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_SERVICE` if the core service is unavailable.
|
2021-03-24 12:20:39 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_core_query_addr(uint64_t net_id, unsigned int idx, char* addr, unsigned int len);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Lock the core service so that queries about addresses, routes, paths, etc. can be
|
|
|
|
|
|
* performed.
|
|
|
|
|
|
*
|
|
|
|
|
|
* `Notice`: `zts_core_` functions are intended to be used by high-level language wrappers.
|
|
|
|
|
|
* Only lock the core if you know *exactly* what you are doing. `zts_core_lock_obtain()` and
|
|
|
|
|
|
* `zts_core_lock_release()` must be called before and after this function.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_SERVICE` if the core service is unavailable.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_core_query_route_count(uint64_t net_id);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Lock the core service so that queries about addresses, routes, paths, etc. can be
|
|
|
|
|
|
* performed.
|
|
|
|
|
|
*
|
|
|
|
|
|
* `Notice`: `zts_core_` functions are intended to be used by high-level language wrappers.
|
|
|
|
|
|
* Only lock the core if you know *exactly* what you are doing. `zts_core_lock_obtain()` and
|
|
|
|
|
|
* `zts_core_lock_release()` must be called before and after this function.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_SERVICE` if the core service is unavailable.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_core_query_route(
|
|
|
|
|
|
uint64_t net_id,
|
|
|
|
|
|
unsigned int idx,
|
|
|
|
|
|
char* target,
|
|
|
|
|
|
char* via,
|
|
|
|
|
|
unsigned int len,
|
|
|
|
|
|
uint16_t* flags,
|
|
|
|
|
|
uint16_t* metric);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Lock the core service so that queries about addresses, routes, paths, etc. can be
|
|
|
|
|
|
* performed.
|
|
|
|
|
|
*
|
|
|
|
|
|
* `Notice`: `zts_core_` functions are intended to be used by high-level language wrappers.
|
|
|
|
|
|
* Only lock the core if you know *exactly* what you are doing. `zts_core_lock_obtain()` and
|
|
|
|
|
|
* `zts_core_lock_release()` must be called before and after this function.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_SERVICE` if the core service is unavailable.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_core_query_path_count(uint64_t peer_id);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Lock the core service so that queries about addresses, routes, paths, etc. can be
|
|
|
|
|
|
* performed.
|
|
|
|
|
|
*
|
|
|
|
|
|
* `Notice`: `zts_core_` functions are intended to be used by high-level language wrappers.
|
|
|
|
|
|
* Only lock the core if you know *exactly* what you are doing. `zts_core_lock_obtain()` and
|
|
|
|
|
|
* `zts_core_lock_release()` must be called before and after this function.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_SERVICE` if the core service is unavailable.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_core_query_path(uint64_t peer_id, unsigned int idx, char* dst, unsigned int len);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Lock the core service so that queries about addresses, routes, paths, etc. can be
|
|
|
|
|
|
* performed.
|
|
|
|
|
|
*
|
|
|
|
|
|
* `Notice`: `zts_core_` functions are intended to be used by high-level language wrappers.
|
|
|
|
|
|
* Only lock the core if you know *exactly* what you are doing. `zts_core_lock_obtain()` and
|
|
|
|
|
|
* `zts_core_lock_release()` must be called before and after this function.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_SERVICE` if the core service is unavailable.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_core_query_mc_count(uint64_t net_id);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Lock the core service so that queries about addresses, routes, paths, etc. can be
|
|
|
|
|
|
* performed.
|
|
|
|
|
|
*
|
|
|
|
|
|
* `Notice`: `zts_core_` functions are intended to be used by high-level language wrappers.
|
|
|
|
|
|
* Only lock the core if you know *exactly* what you are doing. `zts_core_lock_obtain()` and
|
|
|
|
|
|
* `zts_core_lock_release()` must be called before and after this function.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @return `ZTS_ERR_OK` if successful. `ZTS_ERR_SERVICE` if the core service is unavailable.
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_core_query_mc(uint64_t net_id, unsigned int idx, uint64_t* mac, uint32_t* adi);
|
2021-03-24 12:20:39 -07:00
|
|
|
|
|
2021-04-22 11:20:04 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Utilities //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @brief Generates a new world definition
|
2021-04-22 11:20:04 -07:00
|
|
|
|
*
|
2021-04-26 21:55:01 -07:00
|
|
|
|
* @param world_id The desired World ID (arbitrary)
|
|
|
|
|
|
* @param ts Timestamp indicating when this generation took place
|
2021-04-22 11:20:04 -07:00
|
|
|
|
*/
|
2021-04-26 21:55:01 -07:00
|
|
|
|
ZTS_API int ZTCALL zts_util_world_new(
|
|
|
|
|
|
char* world_out,
|
|
|
|
|
|
unsigned int* world_len,
|
|
|
|
|
|
char* prev_key,
|
|
|
|
|
|
unsigned int* prev_key_len,
|
|
|
|
|
|
char* curr_key,
|
|
|
|
|
|
unsigned int* curr_key_len,
|
|
|
|
|
|
uint64_t id,
|
|
|
|
|
|
uint64_t ts,
|
|
|
|
|
|
zts_world_t* world_spec);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Platform-agnostic delay
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param milliseconds How long to delay
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API void ZTCALL zts_util_delay(unsigned long milliseconds);
|
2021-04-22 11:20:04 -07:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief Return the family type of the IP string
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param ipstr Either IPv4 or IPv6 string
|
|
|
|
|
|
* @return Either `ZTS_AF_INET` or `ZTS_AF_INET6`
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_util_get_ip_family(const char* ipstr);
|
|
|
|
|
|
|
2021-03-24 12:20:39 -07:00
|
|
|
|
/**
|
|
|
|
|
|
* Convert human-friendly IP string to `zts_sockaddr_in` or `zts_sockaddr_in6`.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param src_ipstr Source IP string
|
|
|
|
|
|
* @param port Port
|
2021-04-22 11:20:04 -07:00
|
|
|
|
* @param dstaddr Pointer to destination structure `zts_sockaddr_in` or
|
|
|
|
|
|
* `zts_sockaddr_in6`
|
|
|
|
|
|
* @param addrlen Size of destination structure. Value-result: Will be set to
|
|
|
|
|
|
* actual size of data available
|
2021-03-24 12:20:39 -07:00
|
|
|
|
* @return return `ZTS_ERR_OK` on success, `ZTS_ERR_ARG` if invalid argument
|
2020-05-01 19:15:38 -07:00
|
|
|
|
*/
|
2021-04-22 11:20:04 -07:00
|
|
|
|
int zts_util_ipstr_to_saddr(
|
|
|
|
|
|
const char* src_ipstr,
|
2021-04-26 21:55:01 -07:00
|
|
|
|
unsigned int port,
|
2021-04-22 11:20:04 -07:00
|
|
|
|
struct zts_sockaddr* dstaddr,
|
2021-04-17 23:46:21 -07:00
|
|
|
|
zts_socklen_t* addrlen);
|
2020-05-01 19:15:38 -07:00
|
|
|
|
|
2021-04-26 21:55:01 -07:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
// Convenience functions pulled from lwIP //
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Convert numeric IP address (both versions) into `ASCII` representation.
|
|
|
|
|
|
* returns ptr to static buffer. Not reentrant.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param addr IP address in network order to convert
|
|
|
|
|
|
* @return Pointer to a global static (!) buffer that holds the `ASCII`
|
|
|
|
|
|
* representation of addr
|
|
|
|
|
|
*/
|
|
|
|
|
|
char* zts_ipaddr_ntoa(const zts_ip_addr* addr);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Convert IP address string (both versions) to numeric.
|
|
|
|
|
|
* The version is auto-detected from the string.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param cp IP address string to convert
|
|
|
|
|
|
* @param addr conversion result is stored here
|
|
|
|
|
|
* @return `1` on success, `0` on error
|
|
|
|
|
|
*/
|
|
|
|
|
|
int zts_ipaddr_aton(const char* cp, zts_ip_addr* addr);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Convert IPv4 and IPv6 address structures to human-readable text form.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param family Address family: `ZTS_AF_INET` or `ZTS_AF_INET6`
|
|
|
|
|
|
* @param src Pointer to source address structure
|
|
|
|
|
|
* @param dst Pointer to destination character array
|
|
|
|
|
|
* @param size Size of the destination buffer
|
|
|
|
|
|
* @return On success, returns a non-null pointer to the destination character
|
|
|
|
|
|
* array
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API const char* ZTCALL zts_inet_ntop(int family, const void* src, char* dst, zts_socklen_t size);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Convert C-string IPv4 and IPv6 addresses to binary form.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param family Address family: `ZTS_AF_INET` or `ZTS_AF_INET6`
|
|
|
|
|
|
* @param src Pointer to source character array
|
|
|
|
|
|
* @param dst Pointer to destination address structure
|
|
|
|
|
|
* @return return `1` on success. `0` or `-1` on failure. (Does not follow regular
|
|
|
|
|
|
* `zts_*` conventions)
|
|
|
|
|
|
*/
|
|
|
|
|
|
ZTS_API int ZTCALL zts_inet_pton(int family, const char* src, void* dst);
|
|
|
|
|
|
|
2020-05-01 19:15:38 -07:00
|
|
|
|
#ifdef __cplusplus
|
2021-04-17 23:46:21 -07:00
|
|
|
|
} // extern "C"
|
2020-05-01 19:15:38 -07:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2021-04-17 23:46:21 -07:00
|
|
|
|
#endif // _H
|