xref: /illumos-gate/usr/src/lib/libsmbfs/netsmb/nb_lib.h (revision 613a2f6ba31e891e3d947a356daf5e563d43c1ce)
14bff34e3Sthurlow /*
24bff34e3Sthurlow  * Copyright (c) 2000, Boris Popov
34bff34e3Sthurlow  * All rights reserved.
44bff34e3Sthurlow  *
54bff34e3Sthurlow  * Redistribution and use in source and binary forms, with or without
64bff34e3Sthurlow  * modification, are permitted provided that the following conditions
74bff34e3Sthurlow  * are met:
84bff34e3Sthurlow  * 1. Redistributions of source code must retain the above copyright
94bff34e3Sthurlow  *    notice, this list of conditions and the following disclaimer.
104bff34e3Sthurlow  * 2. Redistributions in binary form must reproduce the above copyright
114bff34e3Sthurlow  *    notice, this list of conditions and the following disclaimer in the
124bff34e3Sthurlow  *    documentation and/or other materials provided with the distribution.
134bff34e3Sthurlow  * 3. All advertising materials mentioning features or use of this software
144bff34e3Sthurlow  *    must display the following acknowledgement:
154bff34e3Sthurlow  *    This product includes software developed by Boris Popov.
164bff34e3Sthurlow  * 4. Neither the name of the author nor the names of any co-contributors
174bff34e3Sthurlow  *    may be used to endorse or promote products derived from this software
184bff34e3Sthurlow  *    without specific prior written permission.
194bff34e3Sthurlow  *
204bff34e3Sthurlow  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
214bff34e3Sthurlow  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
224bff34e3Sthurlow  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
234bff34e3Sthurlow  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
244bff34e3Sthurlow  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
254bff34e3Sthurlow  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
264bff34e3Sthurlow  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
274bff34e3Sthurlow  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
284bff34e3Sthurlow  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
294bff34e3Sthurlow  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
304bff34e3Sthurlow  * SUCH DAMAGE.
314bff34e3Sthurlow  *
324bff34e3Sthurlow  * $Id: nb_lib.h,v 1.4 2004/12/11 05:23:58 lindak Exp $
334bff34e3Sthurlow  */
344bff34e3Sthurlow 
359c9af259SGordon Ross /*
36*613a2f6bSGordon Ross  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
379c9af259SGordon Ross  * Use is subject to license terms.
389c9af259SGordon Ross  */
399c9af259SGordon Ross 
404bff34e3Sthurlow #ifndef _NETSMB_NB_LIB_H_
414bff34e3Sthurlow #define	_NETSMB_NB_LIB_H_
424bff34e3Sthurlow 
434bff34e3Sthurlow /*
444bff34e3Sthurlow  * Error codes
454bff34e3Sthurlow  */
464bff34e3Sthurlow #define	NBERR_INVALIDFORMAT	0x0001
474bff34e3Sthurlow #define	NBERR_SRVFAILURE	0x0002
484bff34e3Sthurlow #define	NBERR_NAMENOTFOUND	0x0003
494bff34e3Sthurlow #define	NBERR_IMP		0x0004
504bff34e3Sthurlow #define	NBERR_REFUSED		0x0005
514bff34e3Sthurlow #define	NBERR_ACTIVE		0x0006
524bff34e3Sthurlow #define	NBERR_HOSTNOTFOUND	0x0101
534bff34e3Sthurlow #define	NBERR_TOOMANYREDIRECTS	0x0102
544bff34e3Sthurlow #define	NBERR_INVALIDRESPONSE	0x0103
554bff34e3Sthurlow #define	NBERR_NAMETOOLONG	0x0104
564bff34e3Sthurlow #define	NBERR_NOBCASTIFS	0x0105
574bff34e3Sthurlow #define	NBERR_MAX		0x0106
584bff34e3Sthurlow #define	NBERROR(e)		((e) |  SMB_NB_ERROR)
594bff34e3Sthurlow 
604bff34e3Sthurlow #define	NBCF_RESOLVED	0x0001
614bff34e3Sthurlow #define	NBCF_NS_ENABLE	0x0002		/* any NetBIOS lookup */
624bff34e3Sthurlow #define	NBCF_BC_ENABLE	0x0004		/* lookup via broadcast */
634bff34e3Sthurlow 
644bff34e3Sthurlow /*
654bff34e3Sthurlow  * nb environment
664bff34e3Sthurlow  */
674bff34e3Sthurlow struct nb_ctx {
684bff34e3Sthurlow 	int		nb_flags;
694bff34e3Sthurlow 	int		nb_timo;
704bff34e3Sthurlow 	char		*nb_scope;	/* NetBIOS scope */
714bff34e3Sthurlow 	in_addr_t	nb_wins1;	/* primary WINS */
724bff34e3Sthurlow 	in_addr_t	nb_wins2;	/* secondary WINS (unused now) */
734bff34e3Sthurlow 	struct sockaddr_in	nb_lastns; /* see cmd:lookup.c */
744bff34e3Sthurlow };
754bff34e3Sthurlow typedef struct nb_ctx nb_ctx_t;
764bff34e3Sthurlow 
774bff34e3Sthurlow /*
784bff34e3Sthurlow  * resource record
794bff34e3Sthurlow  */
804bff34e3Sthurlow struct nbns_rr {
814bff34e3Sthurlow 	uchar_t		*rr_name;	/* compressed NETBIOS name */
824bff34e3Sthurlow 	uint16_t	rr_type;
834bff34e3Sthurlow 	uint16_t	rr_class;
844bff34e3Sthurlow 	uint32_t	rr_ttl;
854bff34e3Sthurlow 	uint16_t	rr_rdlength;
864bff34e3Sthurlow 	uchar_t		*rr_data;
874bff34e3Sthurlow };
884bff34e3Sthurlow typedef struct nbns_rr nfns_rr_t;
894bff34e3Sthurlow 
904bff34e3Sthurlow /*
914bff34e3Sthurlow  * NetBIOS name return
924bff34e3Sthurlow  */
934bff34e3Sthurlow struct nbns_nr {
944bff34e3Sthurlow 	char		ns_name[NB_NAMELEN];
954bff34e3Sthurlow 	uint16_t	ns_flags;
964bff34e3Sthurlow };
974bff34e3Sthurlow typedef struct nbns_nr nbns_nr_t;
984bff34e3Sthurlow 
994bff34e3Sthurlow #define	NBRQF_POINT	0x0000
1004bff34e3Sthurlow #define	NBRQF_BROADCAST	0x0001
1014bff34e3Sthurlow 
1024bff34e3Sthurlow #define	NBNS_GROUPFLG 0x8000
1034bff34e3Sthurlow 
1044bff34e3Sthurlow struct sockaddr;
1054bff34e3Sthurlow 
1064bff34e3Sthurlow #ifdef __cplusplus
1074bff34e3Sthurlow extern "C" {
1084bff34e3Sthurlow #endif
1094bff34e3Sthurlow 
110*613a2f6bSGordon Ross struct rcfile;
111*613a2f6bSGordon Ross int  nb_resolvehost_in(const char *, struct in_addr *);
1124bff34e3Sthurlow int  nbns_resolvename(const char *, struct nb_ctx *, struct sockaddr **);
113*613a2f6bSGordon Ross int  nbns_getnodestatus(struct nb_ctx *ctx, struct in_addr *,
114*613a2f6bSGordon Ross     char *system, char *workgroup);
1154bff34e3Sthurlow int  nb_getlocalname(char *name, size_t maxlen);
1164bff34e3Sthurlow const char *nb_strerror(int error);
1174bff34e3Sthurlow 
1184bff34e3Sthurlow int  nb_ctx_create(struct nb_ctx **);
1194bff34e3Sthurlow void nb_ctx_done(struct nb_ctx *);
1204bff34e3Sthurlow int  nb_ctx_setns(struct nb_ctx *, const char *);
1214bff34e3Sthurlow int  nb_ctx_setscope(struct nb_ctx *, const char *);
1224bff34e3Sthurlow int  nb_ctx_resolve(struct nb_ctx *);
1234bff34e3Sthurlow int  nb_ctx_readrcsection(struct rcfile *, struct nb_ctx *, const char *, int);
1244bff34e3Sthurlow 
1254bff34e3Sthurlow #ifdef __cplusplus
1264bff34e3Sthurlow }
1274bff34e3Sthurlow #endif
1284bff34e3Sthurlow 
1294bff34e3Sthurlow #endif /* !_NETSMB_NB_LIB_H_ */
130