Commit 48f33194 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(isc_mkipaddress): Use SOCKADDR_STORAGE as argument, not struct sockaddr.

(CHOOSE_IP4OR6): New macro.
(FOR_EACH_AF): New macro.
(FOR_EACH_PF): New macro.
(STORE_ADDR): New macro.
parent 91d3d7d6
......@@ -90,7 +90,7 @@ isc_default_close_fn(IscHandlerList *hl, IscSession *scb);
extern IscAddress *
isc_mkipaddress(struct sockaddr *addr);
isc_mkipaddress(SOCKADDR_STORAGE *addr);
extern void
......@@ -163,4 +163,61 @@ typedef unsigned long uint32_t;
# endif
#endif
/* IPv4/IPv6 compatibility macros:
*
* These are used as wrappers around IPv4/IPv6 specific socket
* handling code. When USE_INET6 is not defined, IPv6 specific
* parts will not be compiled.
*
* CHOOSE_IP4OR6: Takes 3 args:
* evaluates to second arg if first arg (of type
* enum sockaddrs) contains an AF_INET address or
* IPv6 is not used, otherwise to third arg.
* FOR_EACH_AF: Takes 2 args; first is an int lvalue, second
* an int expression. For each available address
* family (from most preferred to last preferred),
* the second arg is evaluated with the address
* family assigned to the first arg, until it
* evaluates to false (in which case the entire
* macro expansion evaluates to false), or until
* there are no more address families, in which
* case the entire macro expansion evaluates to
* false.
* FOR_EACH_PF: As FOR_EACH_AF, but for protocol families
* instead of address families.
* STORE_ADDR: First arg (enum sockaddrs) is checked for
* address family (if several address families
* are supported), and its address part
* assigned the value of the second arg
* (of type in_addr) for IPv4, otherwise
* the third arg (of type in6_addr).
*/
#ifdef USE_INET6
#define CHOOSE_IP4OR6(saddrs, ifip4, ifip6) \
((((saddrs).sa.sa_family) == AF_INET) ? (ifip4) : (ifip6))
#define FOR_EACH_AF(af,expr) \
(((af)=AF_INET6, (expr)) && ((af)=AF_INET, (expr)))
#define FOR_EACH_PF(pf,expr) \
(((pf)=PF_INET6, (expr)) && ((pf)=PF_INET, (expr)))
#define STORE_ADDR(addr, IPv4addr, IPv6addr) \
CHOOSE_IP4OR6((addr), \
(addr).sa_in.sin_addr.s_addr = (IPv4addr), \
(memcpy(&(addr).sa_in6.sin6_addr, \
&(IPv6addr), \
sizeof((addr).sa_in6.sin6_addr)), 0))
#else
#define CHOOSE_IP4OR6(saddrs, ifip4, ifip6) (ifip4)
#define FOR_EACH_AF(af,expr) ((af)=AF_INET, (expr))
#define FOR_EACH_PF(pf,expr) ((pf)=PF_INET, (expr))
#define STORE_ADDR(addr, IPv4addr, IPv6addr) \
((addr).sa_in.sin_addr.s_addr = (IPv4addr));
#endif /* USE_INET6 */
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment