getconf: don't include xpg4 bits, gcc7 includes xpg6 bits for us
[unleashed.git] / usr / src / common / smbsrv / smb_inet.c
blob6f3ac26617627045b2c3ab897a3329b251667f06
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2017 Nexenta Systems, Inc.
29 * This file was originally generated using rpcgen.
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <netinet/in.h>
36 #if !defined(_KERNEL)
37 #include <errno.h>
38 #include <string.h>
39 #include <strings.h>
40 #include <arpa/inet.h>
41 #else /* !_KERNEL */
42 #include <sys/errno.h>
43 #include <sys/sunddi.h>
44 /* Don't want the rest of what's in inet/ip.h */
45 extern char *inet_ntop(int, const void *, char *, int);
46 extern int inet_pton(int, char *, void *);
47 #endif /* !_KERNEL */
49 #include <smbsrv/smb_inet.h>
51 const struct in6_addr ipv6addr_any = IN6ADDR_ANY_INIT;
53 boolean_t
54 smb_inet_equal(smb_inaddr_t *ip1, smb_inaddr_t *ip2)
56 if ((ip1->a_family == AF_INET) &&
57 (ip2->a_family == AF_INET) &&
58 (ip1->a_ipv4 == ip2->a_ipv4))
59 return (B_TRUE);
61 if ((ip1->a_family == AF_INET6) &&
62 (ip2->a_family == AF_INET6) &&
63 (!memcmp(&ip1->a_ipv6, &ip2->a_ipv6, sizeof (in6_addr_t))))
64 return (B_TRUE);
65 else
66 return (B_FALSE);
69 boolean_t
70 smb_inet_same_subnet(smb_inaddr_t *ip1, smb_inaddr_t *ip2, uint32_t v4mask)
72 if ((ip1->a_family == AF_INET) &&
73 (ip2->a_family == AF_INET) &&
74 ((ip1->a_ipv4 & v4mask) == (ip2->a_ipv4 & v4mask)))
75 return (B_TRUE);
77 if ((ip1->a_family == AF_INET6) &&
78 (ip2->a_family == AF_INET6) &&
79 (!memcmp(&ip1->a_ipv6, &ip2->a_ipv6, sizeof (in6_addr_t))))
80 return (B_TRUE);
81 else
82 return (B_FALSE);
85 boolean_t
86 smb_inet_iszero(smb_inaddr_t *ipaddr)
88 const void *ipsz = (const void *)&ipv6addr_any;
90 if ((ipaddr->a_family == AF_INET) &&
91 (ipaddr->a_ipv4 == 0))
92 return (B_TRUE);
94 if ((ipaddr->a_family == AF_INET6) &&
95 !memcmp(&ipaddr->a_ipv6, ipsz, sizeof (in6_addr_t)))
96 return (B_TRUE);
97 else
98 return (B_FALSE);
101 const char *
102 smb_inet_ntop(smb_inaddr_t *addr, char *buf, int size)
104 #ifdef _KERNEL
105 int sz = size;
106 #else
107 size_t sz = (size_t)size;
108 #endif
110 return ((char *)inet_ntop(addr->a_family, addr, buf, sz));