xref: /titanic_51/usr/src/common/smbsrv/smb_inet.c (revision bb8220ba212644c001e84164b32fc576a73ff8e0)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * This file was originally generated using rpcgen.
28  */
29 
30 #ifndef _KERNEL
31 #include <string.h>
32 #include <stdlib.h>
33 #include <arpa/inet.h>
34 #endif /* !_KERNEL */
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <inet/tcp.h>
39 #include <smbsrv/smb_inet.h>
40 
41 const struct in6_addr ipv6addr_any = IN6ADDR_ANY_INIT;
42 
43 boolean_t
44 smb_inet_equal(smb_inaddr_t *ip1, smb_inaddr_t *ip2, uint32_t v4mask)
45 {
46 	if ((ip1->a_family == AF_INET) &&
47 	    (ip2->a_family == AF_INET) &&
48 	    ((ip1->a_ipv4 & v4mask) == (ip2->a_ipv4 & v4mask)))
49 		return (B_TRUE);
50 
51 	if ((ip1->a_family == AF_INET6) &&
52 	    (ip2->a_family == AF_INET6) &&
53 	    (!memcmp(&ip1->a_ipv6, &ip2->a_ipv6, IPV6_ADDR_LEN)))
54 		return (B_TRUE);
55 	else
56 		return (B_FALSE);
57 }
58 
59 boolean_t
60 smb_inet_iszero(smb_inaddr_t *ipaddr)
61 {
62 	const void *ipsz = (const void *)&ipv6addr_any;
63 
64 	if ((ipaddr->a_family == AF_INET) &&
65 	    (ipaddr->a_ipv4 == 0))
66 		return (B_TRUE);
67 
68 	if ((ipaddr->a_family == AF_INET6) &&
69 	    !memcmp(&ipaddr->a_ipv6, ipsz, IPV6_ADDR_LEN))
70 		return (B_TRUE);
71 	else
72 		return (B_FALSE);
73 }
74 
75 const char *
76 smb_inet_ntop(smb_inaddr_t *addr, char *buf, int size)
77 {
78 	return ((char *)inet_ntop(addr->a_family, (char *)addr, buf, size));
79 }
80