xref: /freebsd/crypto/openssh/addr.h (revision f374ba41f55c1a127303d92d830dd58eef2f5243)
119261079SEd Maste /*
219261079SEd Maste  * Copyright (c) 2004,2005 Damien Miller <djm@mindrot.org>
319261079SEd Maste  *
419261079SEd Maste  * Permission to use, copy, modify, and distribute this software for any
519261079SEd Maste  * purpose with or without fee is hereby granted, provided that the above
619261079SEd Maste  * copyright notice and this permission notice appear in all copies.
719261079SEd Maste  *
819261079SEd Maste  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
919261079SEd Maste  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1019261079SEd Maste  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1119261079SEd Maste  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1219261079SEd Maste  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1319261079SEd Maste  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1419261079SEd Maste  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1519261079SEd Maste  */
1619261079SEd Maste 
1719261079SEd Maste /* Address handling routines */
1819261079SEd Maste 
1919261079SEd Maste #ifndef _ADDR_H
2019261079SEd Maste #define _ADDR_H
2119261079SEd Maste 
2219261079SEd Maste #include <sys/socket.h>
2319261079SEd Maste #include <netinet/in.h>
2419261079SEd Maste 
2519261079SEd Maste struct xaddr {
2619261079SEd Maste 	sa_family_t	af;
2719261079SEd Maste 	union {
2819261079SEd Maste 		struct in_addr		v4;
2919261079SEd Maste 		struct in6_addr		v6;
3019261079SEd Maste 		u_int8_t		addr8[16];
3119261079SEd Maste 		u_int16_t		addr16[8];
3219261079SEd Maste 		u_int32_t		addr32[4];
3319261079SEd Maste 	} xa;		    /* 128-bit address */
3419261079SEd Maste 	u_int32_t	scope_id;	/* iface scope id for v6 */
3519261079SEd Maste #define v4	xa.v4
3619261079SEd Maste #define v6	xa.v6
3719261079SEd Maste #define addr8	xa.addr8
3819261079SEd Maste #define addr16	xa.addr16
3919261079SEd Maste #define addr32	xa.addr32
4019261079SEd Maste };
4119261079SEd Maste 
4219261079SEd Maste int addr_unicast_masklen(int af);
4319261079SEd Maste int addr_xaddr_to_sa(const struct xaddr *xa, struct sockaddr *sa,
4419261079SEd Maste     socklen_t *len, u_int16_t port);
4519261079SEd Maste int addr_sa_to_xaddr(struct sockaddr *sa, socklen_t slen, struct xaddr *xa);
4619261079SEd Maste int addr_netmask(int af, u_int l, struct xaddr *n);
4719261079SEd Maste int addr_hostmask(int af, u_int l, struct xaddr *n);
4819261079SEd Maste int addr_invert(struct xaddr *n);
4919261079SEd Maste int addr_pton(const char *p, struct xaddr *n);
5019261079SEd Maste int addr_sa_pton(const char *h, const char *s, struct sockaddr *sa,
5119261079SEd Maste     socklen_t slen);
5219261079SEd Maste int addr_pton_cidr(const char *p, struct xaddr *n, u_int *l);
5319261079SEd Maste int addr_ntop(const struct xaddr *n, char *p, size_t len);
5419261079SEd Maste int addr_and(struct xaddr *dst, const struct xaddr *a, const struct xaddr *b);
55*f374ba41SEd Maste int addr_or(struct xaddr *dst, const struct xaddr *a, const struct xaddr *b);
5619261079SEd Maste int addr_cmp(const struct xaddr *a, const struct xaddr *b);
5719261079SEd Maste int addr_is_all0s(const struct xaddr *n);
5819261079SEd Maste int addr_host_is_all0s(const struct xaddr *n, u_int masklen);
59*f374ba41SEd Maste int addr_host_to_all0s(struct xaddr *a, u_int masklen);
60*f374ba41SEd Maste int addr_host_to_all1s(struct xaddr *a, u_int masklen);
6119261079SEd Maste int addr_netmatch(const struct xaddr *host, const struct xaddr *net,
6219261079SEd Maste     u_int masklen);
63*f374ba41SEd Maste void addr_increment(struct xaddr *a);
6419261079SEd Maste #endif /* _ADDR_H */
65