/*1* Copyright (c) 2004,2005 Damien Miller <[email protected]>2*3* Permission to use, copy, modify, and distribute this software for any4* purpose with or without fee is hereby granted, provided that the above5* copyright notice and this permission notice appear in all copies.6*7* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES8* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF9* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR10* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES11* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN12* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF13* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.14*/1516/* Address handling routines */1718#ifndef _ADDR_H19#define _ADDR_H2021#include <sys/socket.h>22#include <netinet/in.h>2324struct xaddr {25sa_family_t af;26union {27struct in_addr v4;28struct in6_addr v6;29u_int8_t addr8[16];30u_int16_t addr16[8];31u_int32_t addr32[4];32} xa; /* 128-bit address */33u_int32_t scope_id; /* iface scope id for v6 */34#define v4 xa.v435#define v6 xa.v636#define addr8 xa.addr837#define addr16 xa.addr1638#define addr32 xa.addr3239};4041int addr_sa_to_xaddr(struct sockaddr *sa, socklen_t slen, struct xaddr *xa);42int addr_netmask(int af, u_int l, struct xaddr *n);43int addr_pton(const char *p, struct xaddr *n);44int addr_pton_cidr(const char *p, struct xaddr *n, u_int *l);45int addr_ntop(const struct xaddr *n, char *p, size_t len);46int addr_and(struct xaddr *dst, const struct xaddr *a, const struct xaddr *b);47int addr_cmp(const struct xaddr *a, const struct xaddr *b);48int addr_host_to_all1s(struct xaddr *a, u_int masklen);49int addr_netmatch(const struct xaddr *host, const struct xaddr *net,50u_int masklen);51void addr_increment(struct xaddr *a);52#endif /* _ADDR_H */535455