| 1 |
#ifndef PROTON_NETADDR_H |
| 2 |
#define PROTON_NETADDR_H |
| 3 |
|
| 4 |
/* |
| 5 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 6 |
* or more contributor license agreements. See the NOTICE file |
| 7 |
* distributed with this work for additional information |
| 8 |
* regarding copyright ownership. The ASF licenses this file |
| 9 |
* to you under the Apache License, Version 2.0 (the |
| 10 |
* "License"); you may not use this file except in compliance |
| 11 |
* with the License. You may obtain a copy of the License at |
| 12 |
* |
| 13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 14 |
* |
| 15 |
* Unless required by applicable law or agreed to in writing, |
| 16 |
* software distributed under the License is distributed on an |
| 17 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 18 |
* KIND, either express or implied. See the License for the |
| 19 |
* specific language governing permissions and limitations |
| 20 |
* under the License. |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <proton/import_export.h> |
| 24 |
#include <proton/types.h> |
| 25 |
|
| 26 |
#ifdef __cplusplus |
| 27 |
extern "C" { |
| 28 |
#endif |
| 29 |
|
| 30 |
/** |
| 31 |
* @file |
| 32 |
* |
| 33 |
* @copybrief pn_netaddr_t |
| 34 |
* |
| 35 |
* @addtogroup proactor |
| 36 |
* @{ |
| 37 |
*/ |
| 38 |
|
| 39 |
/** |
| 40 |
* **Unsettled API** - The network address of a proactor transport. |
| 41 |
*/ |
| 42 |
typedef struct pn_netaddr_t pn_netaddr_t; |
| 43 |
|
| 44 |
/** |
| 45 |
* Format a network address string in `buf`. |
| 46 |
* |
| 47 |
* @return the length of the string (excluding trailing '\0'), if >= size then |
| 48 |
* the address was truncated. |
| 49 |
*/ |
| 50 |
PNP_EXTERN int pn_netaddr_str(const pn_netaddr_t *addr, char *buf, size_t size); |
| 51 |
|
| 52 |
/** |
| 53 |
* Get the local address of a transport. Return `NULL` if not available. |
| 54 |
* Pointer is invalid after the transport closes (PN_TRANSPORT_CLOSED event is handled) |
| 55 |
*/ |
| 56 |
PNP_EXTERN const pn_netaddr_t *pn_transport_local_addr(pn_transport_t *t); |
| 57 |
|
| 58 |
/** |
| 59 |
* Get the local address of a transport. Return `NULL` if not available. |
| 60 |
* Pointer is invalid after the transport closes (PN_TRANSPORT_CLOSED event is handled) |
| 61 |
*/ |
| 62 |
PNP_EXTERN const pn_netaddr_t *pn_transport_remote_addr(pn_transport_t *t); |
| 63 |
|
| 64 |
/** |
| 65 |
* Get the listening addresses of a listener. |
| 66 |
* Addresses are only available after the @ref PN_LISTENER_OPEN event for the listener. |
| 67 |
* |
| 68 |
* A listener can have more than one address for several reasons: |
| 69 |
* - DNS host records may indicate more than one address |
| 70 |
* - On a multi-homed host, listening on the default host "" will listen on all local addresses. |
| 71 |
* - Some IPv4/IPV6 configurations may expand a single address into a v4/v6 pair. |
| 72 |
* |
| 73 |
* pn_netaddr_next() will iterate over the addresses in the list. |
| 74 |
* |
| 75 |
* @param l points to the listener |
| 76 |
* @return The first listening address or NULL if there are no addresses are available. |
| 77 |
* Use pn_netaddr_next() to iterate over the list. |
| 78 |
* Pointer is invalid after the listener closes (PN_LISTENER_CLOSED event is handled) |
| 79 |
*/ |
| 80 |
PNP_EXTERN const pn_netaddr_t *pn_listener_addr(pn_listener_t *l); |
| 81 |
|
| 82 |
/** |
| 83 |
* @return Pointer to the next address in a list of addresses, NULL if at the end of the list or |
| 84 |
* if this address is not part of a list. |
| 85 |
*/ |
| 86 |
PNP_EXTERN const pn_netaddr_t *pn_netaddr_next(const pn_netaddr_t *na); |
| 87 |
|
| 88 |
struct sockaddr; |
| 89 |
|
| 90 |
/** |
| 91 |
* On POSIX or Windows, get the underlying `struct sockaddr`. |
| 92 |
* Return NULL if not available. |
| 93 |
*/ |
| 94 |
PNP_EXTERN const struct sockaddr *pn_netaddr_sockaddr(const pn_netaddr_t *na); |
| 95 |
|
| 96 |
/** |
| 97 |
* On POSIX or Windows, get the size of the underlying `struct sockaddr`. |
| 98 |
* Return 0 if not available. |
| 99 |
*/ |
| 100 |
PNP_EXTERN size_t pn_netaddr_socklen(const pn_netaddr_t *na); |
| 101 |
|
| 102 |
/** |
| 103 |
* Get the host and port name from na as separate strings. |
| 104 |
* Returns 0 if successful, non-0 on error. |
| 105 |
*/ |
| 106 |
PNP_EXTERN int pn_netaddr_host_port(const pn_netaddr_t* na, char *host, size_t hlen, char *port, size_t plen); |
| 107 |
|
| 108 |
/** |
| 109 |
* **Deprecated** - Use ::pn_transport_local_addr() |
| 110 |
*/ |
| 111 |
PN_DEPRECATED("Use pn_transport_local_addr") |
| 112 |
PNP_EXTERN const pn_netaddr_t *pn_netaddr_local(pn_transport_t *t); |
| 113 |
|
| 114 |
/** |
| 115 |
* **Deprecated** - Use ::pn_transport_remote_addr() |
| 116 |
*/ |
| 117 |
PN_DEPRECATED("Use pn_transport_remote_addr") |
| 118 |
PNP_EXTERN const pn_netaddr_t *pn_netaddr_remote(pn_transport_t *t); |
| 119 |
|
| 120 |
/** |
| 121 |
* **Deprecated** - Use ::pn_listener_addr() |
| 122 |
*/ |
| 123 |
PN_DEPRECATED("Use pn_listener_addr") |
| 124 |
PNP_EXTERN const pn_netaddr_t *pn_netaddr_listening(pn_listener_t *l); |
| 125 |
|
| 126 |
/** |
| 127 |
* @} |
| 128 |
*/ |
| 129 |
|
| 130 |
#ifdef __cplusplus |
| 131 |
} |
| 132 |
#endif |
| 133 |
|
| 134 |
#endif /* PROTON_NETADDR_H */ |