xref: /openbsd-src/usr.bin/ssh/addr.h (revision 632d59bf82ef1c5ae20fd4a1838ec4a541a50a00)
14b59ce38Sdtucker /*
24b59ce38Sdtucker  * Copyright (c) 2004,2005 Damien Miller <djm@mindrot.org>
34b59ce38Sdtucker  *
44b59ce38Sdtucker  * Permission to use, copy, modify, and distribute this software for any
54b59ce38Sdtucker  * purpose with or without fee is hereby granted, provided that the above
64b59ce38Sdtucker  * copyright notice and this permission notice appear in all copies.
74b59ce38Sdtucker  *
84b59ce38Sdtucker  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
94b59ce38Sdtucker  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
104b59ce38Sdtucker  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
114b59ce38Sdtucker  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
124b59ce38Sdtucker  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
134b59ce38Sdtucker  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
144b59ce38Sdtucker  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
154b59ce38Sdtucker  */
164b59ce38Sdtucker 
174b59ce38Sdtucker /* Address handling routines */
184b59ce38Sdtucker 
194b59ce38Sdtucker #ifndef _ADDR_H
204b59ce38Sdtucker #define _ADDR_H
214b59ce38Sdtucker 
224b59ce38Sdtucker #include <sys/socket.h>
234b59ce38Sdtucker #include <netinet/in.h>
244b59ce38Sdtucker 
254b59ce38Sdtucker struct xaddr {
264b59ce38Sdtucker 	sa_family_t	af;
274b59ce38Sdtucker 	union {
284b59ce38Sdtucker 		struct in_addr		v4;
294b59ce38Sdtucker 		struct in6_addr		v6;
304b59ce38Sdtucker 		u_int8_t		addr8[16];
314b59ce38Sdtucker 		u_int16_t		addr16[8];
324b59ce38Sdtucker 		u_int32_t		addr32[4];
334b59ce38Sdtucker 	} xa;		    /* 128-bit address */
344b59ce38Sdtucker 	u_int32_t	scope_id;	/* iface scope id for v6 */
354b59ce38Sdtucker #define v4	xa.v4
364b59ce38Sdtucker #define v6	xa.v6
374b59ce38Sdtucker #define addr8	xa.addr8
384b59ce38Sdtucker #define addr16	xa.addr16
394b59ce38Sdtucker #define addr32	xa.addr32
404b59ce38Sdtucker };
414b59ce38Sdtucker 
424b59ce38Sdtucker int addr_sa_to_xaddr(struct sockaddr *sa, socklen_t slen, struct xaddr *xa);
434b59ce38Sdtucker int addr_netmask(int af, u_int l, struct xaddr *n);
444b59ce38Sdtucker int addr_pton(const char *p, struct xaddr *n);
454b59ce38Sdtucker int addr_pton_cidr(const char *p, struct xaddr *n, u_int *l);
464b59ce38Sdtucker int addr_ntop(const struct xaddr *n, char *p, size_t len);
474b59ce38Sdtucker int addr_and(struct xaddr *dst, const struct xaddr *a, const struct xaddr *b);
484b59ce38Sdtucker int addr_cmp(const struct xaddr *a, const struct xaddr *b);
49*ba77ede9Sdjm int addr_host_to_all1s(struct xaddr *a, u_int masklen);
504b59ce38Sdtucker int addr_netmatch(const struct xaddr *host, const struct xaddr *net,
514b59ce38Sdtucker     u_int masklen);
52*ba77ede9Sdjm void addr_increment(struct xaddr *a);
534b59ce38Sdtucker #endif /* _ADDR_H */
54