xref: /illumos-gate/usr/src/uts/common/netsmb/netbios.h (revision 4bff34e3)
1*4bff34e3Sthurlow /*
2*4bff34e3Sthurlow  * Copyright (c) 2000-2001 Boris Popov
3*4bff34e3Sthurlow  * All rights reserved.
4*4bff34e3Sthurlow  *
5*4bff34e3Sthurlow  * Redistribution and use in source and binary forms, with or without
6*4bff34e3Sthurlow  * modification, are permitted provided that the following conditions
7*4bff34e3Sthurlow  * are met:
8*4bff34e3Sthurlow  * 1. Redistributions of source code must retain the above copyright
9*4bff34e3Sthurlow  *    notice, this list of conditions and the following disclaimer.
10*4bff34e3Sthurlow  * 2. Redistributions in binary form must reproduce the above copyright
11*4bff34e3Sthurlow  *    notice, this list of conditions and the following disclaimer in the
12*4bff34e3Sthurlow  *    documentation and/or other materials provided with the distribution.
13*4bff34e3Sthurlow  * 3. All advertising materials mentioning features or use of this software
14*4bff34e3Sthurlow  *    must display the following acknowledgement:
15*4bff34e3Sthurlow  *    This product includes software developed by Boris Popov.
16*4bff34e3Sthurlow  * 4. Neither the name of the author nor the names of any co-contributors
17*4bff34e3Sthurlow  *    may be used to endorse or promote products derived from this software
18*4bff34e3Sthurlow  *    without specific prior written permission.
19*4bff34e3Sthurlow  *
20*4bff34e3Sthurlow  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21*4bff34e3Sthurlow  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*4bff34e3Sthurlow  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*4bff34e3Sthurlow  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24*4bff34e3Sthurlow  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*4bff34e3Sthurlow  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*4bff34e3Sthurlow  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*4bff34e3Sthurlow  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*4bff34e3Sthurlow  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*4bff34e3Sthurlow  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*4bff34e3Sthurlow  * SUCH DAMAGE.
31*4bff34e3Sthurlow  *
32*4bff34e3Sthurlow  * $Id: netbios.h,v 1.5 2004/03/19 01:49:45 lindak Exp $
33*4bff34e3Sthurlow  */
34*4bff34e3Sthurlow 
35*4bff34e3Sthurlow #ifndef _NETSMB_NETBIOS_H_
36*4bff34e3Sthurlow #define	_NETSMB_NETBIOS_H_
37*4bff34e3Sthurlow 
38*4bff34e3Sthurlow #pragma ident	"%Z%%M%	%I%	%E% SMI"
39*4bff34e3Sthurlow 
40*4bff34e3Sthurlow #ifndef _NETINET_IN_H_
41*4bff34e3Sthurlow #include <netinet/in.h>
42*4bff34e3Sthurlow #endif
43*4bff34e3Sthurlow 
44*4bff34e3Sthurlow /*
45*4bff34e3Sthurlow  * This is a fake address family number, used to
46*4bff34e3Sthurlow  * recognize our fake sockaddr_nb objects.
47*4bff34e3Sthurlow  * This is never handed to bind or connect.
48*4bff34e3Sthurlow  */
49*4bff34e3Sthurlow #ifndef AF_NETBIOS
50*4bff34e3Sthurlow #define	AF_NETBIOS (AF_MAX+2)
51*4bff34e3Sthurlow #endif
52*4bff34e3Sthurlow 
53*4bff34e3Sthurlow #define	PF_NETBIOS	AF_NETBIOS
54*4bff34e3Sthurlow 
55*4bff34e3Sthurlow /*
56*4bff34e3Sthurlow  * NetBIOS port numbers by the names used in the Darwin code.
57*4bff34e3Sthurlow  * XXX: Change the code to use IPPORT_xxx from in.h directly.
58*4bff34e3Sthurlow  * XXX: Add IPPORT_SMB_OVER_TCP or some such (port 445)
59*4bff34e3Sthurlow  */
60*4bff34e3Sthurlow #define	NBNS_UDP_PORT		IPPORT_NETBIOS_NS	/* 137 */
61*4bff34e3Sthurlow #define	SMB_TCP_PORT		IPPORT_NETBIOS_SSN	/* 139 */
62*4bff34e3Sthurlow 
63*4bff34e3Sthurlow #define	NBPROTO_TCPSSN	1		/* NETBIOS session over TCP */
64*4bff34e3Sthurlow 
65*4bff34e3Sthurlow #define	NB_NAMELEN	16
66*4bff34e3Sthurlow #define	NB_ENCNAMELEN	NB_NAMELEN * 2
67*4bff34e3Sthurlow #define	NB_MAXLABLEN	63
68*4bff34e3Sthurlow 
69*4bff34e3Sthurlow #define	NB_MINSALEN	(sizeof (struct sockaddr_nb))
70*4bff34e3Sthurlow 
71*4bff34e3Sthurlow /*
72*4bff34e3Sthurlow  * name types
73*4bff34e3Sthurlow  */
74*4bff34e3Sthurlow #define	NBT_WKSTA	0x00
75*4bff34e3Sthurlow #define	NBT_CLIENT	0x03
76*4bff34e3Sthurlow #define	NBT_RASSRVR	0x06
77*4bff34e3Sthurlow #define	NBT_DMB		0x1B
78*4bff34e3Sthurlow #define	NBT_IP		0x1C
79*4bff34e3Sthurlow #define	NBT_MB		0x1D
80*4bff34e3Sthurlow #define	NBT_BS		0x1E
81*4bff34e3Sthurlow #define	NBT_NETDDE	0x1F
82*4bff34e3Sthurlow #define	NBT_SERVER	0x20
83*4bff34e3Sthurlow #define	NBT_RASCLNT	0x21
84*4bff34e3Sthurlow #define	NBT_NMAGENT	0xBE
85*4bff34e3Sthurlow #define	NBT_NMUTIL	0xBF
86*4bff34e3Sthurlow 
87*4bff34e3Sthurlow /*
88*4bff34e3Sthurlow  * Session packet types
89*4bff34e3Sthurlow  */
90*4bff34e3Sthurlow #define	NB_SSN_MESSAGE		0x0
91*4bff34e3Sthurlow #define	NB_SSN_REQUEST		0x81
92*4bff34e3Sthurlow #define	NB_SSN_POSRESP		0x82
93*4bff34e3Sthurlow #define	NB_SSN_NEGRESP		0x83
94*4bff34e3Sthurlow #define	NB_SSN_RTGRESP		0x84
95*4bff34e3Sthurlow #define	NB_SSN_KEEPALIVE	0x85
96*4bff34e3Sthurlow 
97*4bff34e3Sthurlow /*
98*4bff34e3Sthurlow  * resolver: Opcodes
99*4bff34e3Sthurlow  */
100*4bff34e3Sthurlow #define	NBNS_OPCODE_QUERY	0x00
101*4bff34e3Sthurlow #define	NBNS_OPCODE_REGISTER	0x05
102*4bff34e3Sthurlow #define	NBNS_OPCODE_RELEASE	0x06
103*4bff34e3Sthurlow #define	NBNS_OPCODE_WACK	0x07
104*4bff34e3Sthurlow #define	NBNS_OPCODE_REFRESH	0x08
105*4bff34e3Sthurlow #define	NBNS_OPCODE_RESPONSE	0x10	/* or'ed with other opcodes */
106*4bff34e3Sthurlow 
107*4bff34e3Sthurlow /*
108*4bff34e3Sthurlow  * resolver: NM_FLAGS
109*4bff34e3Sthurlow  */
110*4bff34e3Sthurlow #define	NBNS_NMFLAG_BCAST	0x01
111*4bff34e3Sthurlow #define	NBNS_NMFLAG_RA		0x08	/* recursion available */
112*4bff34e3Sthurlow #define	NBNS_NMFLAG_RD		0x10	/* recursion desired */
113*4bff34e3Sthurlow #define	NBNS_NMFLAG_TC		0x20	/* truncation occured */
114*4bff34e3Sthurlow #define	NBNS_NMFLAG_AA		0x40	/* authoritative answer */
115*4bff34e3Sthurlow 
116*4bff34e3Sthurlow /*
117*4bff34e3Sthurlow  * resolver: Question types
118*4bff34e3Sthurlow  */
119*4bff34e3Sthurlow #define	NBNS_QUESTION_TYPE_NB		0x0020
120*4bff34e3Sthurlow #define	NBNS_QUESTION_TYPE_NBSTAT	0x0021
121*4bff34e3Sthurlow 
122*4bff34e3Sthurlow /*
123*4bff34e3Sthurlow  * resolver: Question class
124*4bff34e3Sthurlow  */
125*4bff34e3Sthurlow #define	NBNS_QUESTION_CLASS_IN	0x0001
126*4bff34e3Sthurlow 
127*4bff34e3Sthurlow /*
128*4bff34e3Sthurlow  * resolver: Limits
129*4bff34e3Sthurlow  */
130*4bff34e3Sthurlow #define	NBNS_MAXREDIRECTS	3	/* max number of accepted redirects */
131*4bff34e3Sthurlow #define	NBDG_MAXSIZE		576	/* maximum nbns datagram size */
132*4bff34e3Sthurlow 
133*4bff34e3Sthurlow /*
134*4bff34e3Sthurlow  * NETBIOS addressing
135*4bff34e3Sthurlow  */
136*4bff34e3Sthurlow 
137*4bff34e3Sthurlow struct nb_name {
138*4bff34e3Sthurlow 	uint_t		nn_type;
139*4bff34e3Sthurlow 	char		nn_name[NB_NAMELEN];
140*4bff34e3Sthurlow 	char		*nn_scope;
141*4bff34e3Sthurlow };
142*4bff34e3Sthurlow typedef struct nb_name nb_name_t;
143*4bff34e3Sthurlow 
144*4bff34e3Sthurlow /*
145*4bff34e3Sthurlow  * Our private NetBIOS socket address format.
146*4bff34e3Sthurlow  * Note that it's LARGER than sockaddr.
147*4bff34e3Sthurlow  *
148*4bff34e3Sthurlow  * XXX: Also note that the library code is sloppy about
149*4bff34e3Sthurlow  * casting this to sockaddr_in so let's keep snb_ipaddr
150*4bff34e3Sthurlow  * at the same offset, at least until that's fixed.
151*4bff34e3Sthurlow  */
152*4bff34e3Sthurlow struct sockaddr_nb {
153*4bff34e3Sthurlow 	sa_family_t	snb_family;	/* address family */
154*4bff34e3Sthurlow 	uint16_t    snb_flags;	/* NBNS_GROUPFLG, etc. */
155*4bff34e3Sthurlow 	uint32_t	snb_ipaddr; /* always IPv4 */
156*4bff34e3Sthurlow 	char		snb_name[NB_NAMELEN]; /* NOT encoded */
157*4bff34e3Sthurlow };
158*4bff34e3Sthurlow typedef struct sockaddr_nb sockaddr_nb_t;
159*4bff34e3Sthurlow 
160*4bff34e3Sthurlow #endif /* !_NETSMB_NETBIOS_H_ */
161