14bff34ethurlow/*
24bff34ethurlow * Copyright (c) 2000-2001 Boris Popov
34bff34ethurlow * All rights reserved.
44bff34ethurlow *
54bff34ethurlow * Redistribution and use in source and binary forms, with or without
64bff34ethurlow * modification, are permitted provided that the following conditions
74bff34ethurlow * are met:
84bff34ethurlow * 1. Redistributions of source code must retain the above copyright
94bff34ethurlow *    notice, this list of conditions and the following disclaimer.
104bff34ethurlow * 2. Redistributions in binary form must reproduce the above copyright
114bff34ethurlow *    notice, this list of conditions and the following disclaimer in the
124bff34ethurlow *    documentation and/or other materials provided with the distribution.
134bff34ethurlow * 3. All advertising materials mentioning features or use of this software
144bff34ethurlow *    must display the following acknowledgement:
154bff34ethurlow *    This product includes software developed by Boris Popov.
164bff34ethurlow * 4. Neither the name of the author nor the names of any co-contributors
174bff34ethurlow *    may be used to endorse or promote products derived from this software
184bff34ethurlow *    without specific prior written permission.
194bff34ethurlow *
204bff34ethurlow * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
214bff34ethurlow * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
224bff34ethurlow * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
234bff34ethurlow * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
244bff34ethurlow * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
254bff34ethurlow * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
264bff34ethurlow * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
274bff34ethurlow * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
284bff34ethurlow * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
294bff34ethurlow * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
304bff34ethurlow * SUCH DAMAGE.
314bff34ethurlow *
324bff34ethurlow * $Id: netbios.h,v 1.5 2004/03/19 01:49:45 lindak Exp $
334bff34ethurlow */
344bff34ethurlow
35613a2f6Gordon Ross/*
36613a2f6Gordon Ross * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
37613a2f6Gordon Ross * Use is subject to license terms.
38613a2f6Gordon Ross */
39613a2f6Gordon Ross
404bff34ethurlow#ifndef _NETSMB_NETBIOS_H_
414bff34ethurlow#define	_NETSMB_NETBIOS_H_
424bff34ethurlow
434bff34ethurlow#ifndef _NETINET_IN_H_
444bff34ethurlow#include <netinet/in.h>
454bff34ethurlow#endif
464bff34ethurlow
474bff34ethurlow/*
484bff34ethurlow * This is a fake address family number, used to
494bff34ethurlow * recognize our fake sockaddr_nb objects.
504bff34ethurlow * This is never handed to bind or connect.
514bff34ethurlow */
524bff34ethurlow#ifndef AF_NETBIOS
534bff34ethurlow#define	AF_NETBIOS (AF_MAX+2)
544bff34ethurlow#endif
554bff34ethurlow
564bff34ethurlow#define	PF_NETBIOS	AF_NETBIOS
574bff34ethurlow
584bff34ethurlow/*
594bff34ethurlow * NetBIOS port numbers by the names used in the Darwin code.
604bff34ethurlow * XXX: Change the code to use IPPORT_xxx from in.h directly.
614bff34ethurlow * XXX: Add IPPORT_SMB_OVER_TCP or some such (port 445)
624bff34ethurlow */
634bff34ethurlow#define	NBNS_UDP_PORT		IPPORT_NETBIOS_NS	/* 137 */
644bff34ethurlow#define	SMB_TCP_PORT		IPPORT_NETBIOS_SSN	/* 139 */
654bff34ethurlow
664bff34ethurlow#define	NBPROTO_TCPSSN	1		/* NETBIOS session over TCP */
674bff34ethurlow
684bff34ethurlow#define	NB_NAMELEN	16
694bff34ethurlow#define	NB_ENCNAMELEN	NB_NAMELEN * 2
704bff34ethurlow#define	NB_MAXLABLEN	63
714bff34ethurlow
72613a2f6Gordon Ross#define	NB_MAXPKTLEN	0x1FFFF
73613a2f6Gordon Ross
744bff34ethurlow#define	NB_MINSALEN	(sizeof (struct sockaddr_nb))
754bff34ethurlow
764bff34ethurlow/*
774bff34ethurlow * name types
784bff34ethurlow */
794bff34ethurlow#define	NBT_WKSTA	0x00
804bff34ethurlow#define	NBT_CLIENT	0x03
814bff34ethurlow#define	NBT_RASSRVR	0x06
824bff34ethurlow#define	NBT_DMB		0x1B
834bff34ethurlow#define	NBT_IP		0x1C
844bff34ethurlow#define	NBT_MB		0x1D
854bff34ethurlow#define	NBT_BS		0x1E
864bff34ethurlow#define	NBT_NETDDE	0x1F
874bff34ethurlow#define	NBT_SERVER	0x20
884bff34ethurlow#define	NBT_RASCLNT	0x21
894bff34ethurlow#define	NBT_NMAGENT	0xBE
904bff34ethurlow#define	NBT_NMUTIL	0xBF
914bff34ethurlow
924bff34ethurlow/*
934bff34ethurlow * Session packet types
944bff34ethurlow */
954bff34ethurlow#define	NB_SSN_MESSAGE		0x0
964bff34ethurlow#define	NB_SSN_REQUEST		0x81
974bff34ethurlow#define	NB_SSN_POSRESP		0x82
984bff34ethurlow#define	NB_SSN_NEGRESP		0x83
994bff34ethurlow#define	NB_SSN_RTGRESP		0x84
1004bff34ethurlow#define	NB_SSN_KEEPALIVE	0x85
1014bff34ethurlow
1024bff34ethurlow/*
1034bff34ethurlow * resolver: Opcodes
1044bff34ethurlow */
1054bff34ethurlow#define	NBNS_OPCODE_QUERY	0x00
1064bff34ethurlow#define	NBNS_OPCODE_REGISTER	0x05
1074bff34ethurlow#define	NBNS_OPCODE_RELEASE	0x06
1084bff34ethurlow#define	NBNS_OPCODE_WACK	0x07
1094bff34ethurlow#define	NBNS_OPCODE_REFRESH	0x08
1104bff34ethurlow#define	NBNS_OPCODE_RESPONSE	0x10	/* or'ed with other opcodes */
1114bff34ethurlow
1124bff34ethurlow/*
1134bff34ethurlow * resolver: NM_FLAGS
1144bff34ethurlow */
1154bff34ethurlow#define	NBNS_NMFLAG_BCAST	0x01
1164bff34ethurlow#define	NBNS_NMFLAG_RA		0x08	/* recursion available */
1174bff34ethurlow#define	NBNS_NMFLAG_RD		0x10	/* recursion desired */
1184bff34ethurlow#define	NBNS_NMFLAG_TC		0x20	/* truncation occured */
1194bff34ethurlow#define	NBNS_NMFLAG_AA		0x40	/* authoritative answer */
1204bff34ethurlow
1214bff34ethurlow/*
1224bff34ethurlow * resolver: Question types
1234bff34ethurlow */
1244bff34ethurlow#define	NBNS_QUESTION_TYPE_NB		0x0020
1254bff34ethurlow#define	NBNS_QUESTION_TYPE_NBSTAT	0x0021
1264bff34ethurlow
1274bff34ethurlow/*
1284bff34ethurlow * resolver: Question class
1294bff34ethurlow */
1304bff34ethurlow#define	NBNS_QUESTION_CLASS_IN	0x0001
1314bff34ethurlow
1324bff34ethurlow/*
1334bff34ethurlow * resolver: Limits
1344bff34ethurlow */
1354bff34ethurlow#define	NBNS_MAXREDIRECTS	3	/* max number of accepted redirects */
1364bff34ethurlow#define	NBDG_MAXSIZE		576	/* maximum nbns datagram size */
1374bff34ethurlow
1384bff34ethurlow/*
1394bff34ethurlow * NETBIOS addressing
1404bff34ethurlow */
1414bff34ethurlow
1424bff34ethurlowstruct nb_name {
1434bff34ethurlow	uint_t		nn_type;
1444bff34ethurlow	char		nn_name[NB_NAMELEN];
1454bff34ethurlow	char		*nn_scope;
1464bff34ethurlow};
1474bff34ethurlowtypedef struct nb_name nb_name_t;
1484bff34ethurlow
1494bff34ethurlow/*
1504bff34ethurlow * Our private NetBIOS socket address format.
1514bff34ethurlow * Note that it's LARGER than sockaddr.
1524bff34ethurlow *
1534bff34ethurlow * XXX: Also note that the library code is sloppy about
1544bff34ethurlow * casting this to sockaddr_in so let's keep snb_ipaddr
1554bff34ethurlow * at the same offset, at least until that's fixed.
1564bff34ethurlow */
1574bff34ethurlowstruct sockaddr_nb {
1584bff34ethurlow	sa_family_t	snb_family;	/* address family */
1594bff34ethurlow	uint16_t    snb_flags;	/* NBNS_GROUPFLG, etc. */
1604bff34ethurlow	uint32_t	snb_ipaddr; /* always IPv4 */
1614bff34ethurlow	char		snb_name[NB_NAMELEN]; /* NOT encoded */
1624bff34ethurlow};
1634bff34ethurlowtypedef struct sockaddr_nb sockaddr_nb_t;
1644bff34ethurlow
1654bff34ethurlow#endif /* !_NETSMB_NETBIOS_H_ */
166