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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
29 * This file was originally generated using rpcgen.
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <netinet/in.h>
40 #include <arpa/inet.h>
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 *);
49 #include <smbsrv/smb_inet.h>
51 const struct in6_addr ipv6addr_any
= IN6ADDR_ANY_INIT
;
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
))
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
))))
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
)))
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
))))
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))
94 if ((ipaddr
->a_family
== AF_INET6
) &&
95 !memcmp(&ipaddr
->a_ipv6
, ipsz
, sizeof (in6_addr_t
)))
102 smb_inet_ntop(smb_inaddr_t
*addr
, char *buf
, int size
)
104 /* Lint avoidance. */
105 #if !defined(_KERNEL)
106 size_t sz
= (size_t)size
;
111 * Until uts/common/inet/ip/inet_ntop.c is fixed so it
112 * no longer uses leading zeros printing IPv4 addresses,
113 * we need to handle IPv4 ourselves. If we leave the
114 * leading zeros, Windows clients get errors trying to
115 * resolve those address strings to names. After:
116 * https://www.illumos.org/issues/5980 is fixed,
117 * this work-around can be removed.
119 if (addr
->a_family
== AF_INET
) {
120 uint8_t *p
= (void *) &addr
->a_ipv4
;
121 (void) snprintf(buf
, size
, "%d.%d.%d.%d",
122 p
[0], p
[1], p
[2], p
[3]);
127 return ((char *)inet_ntop(addr
->a_family
, addr
, buf
, sz
));