xref: /freebsd/contrib/smbfs/include/netsmb/nb_lib.h (revision ef29b0f6a18f20a861f051e899affa15b2dad284)
1f1b9d127SSheldon Hearn /*
2f1b9d127SSheldon Hearn  * Copyright (c) 2000, Boris Popov
3f1b9d127SSheldon Hearn  * All rights reserved.
4f1b9d127SSheldon Hearn  *
5f1b9d127SSheldon Hearn  * Redistribution and use in source and binary forms, with or without
6f1b9d127SSheldon Hearn  * modification, are permitted provided that the following conditions
7f1b9d127SSheldon Hearn  * are met:
8f1b9d127SSheldon Hearn  * 1. Redistributions of source code must retain the above copyright
9f1b9d127SSheldon Hearn  *    notice, this list of conditions and the following disclaimer.
10f1b9d127SSheldon Hearn  * 2. Redistributions in binary form must reproduce the above copyright
11f1b9d127SSheldon Hearn  *    notice, this list of conditions and the following disclaimer in the
12f1b9d127SSheldon Hearn  *    documentation and/or other materials provided with the distribution.
13f1b9d127SSheldon Hearn  * 3. All advertising materials mentioning features or use of this software
14f1b9d127SSheldon Hearn  *    must display the following acknowledgement:
15f1b9d127SSheldon Hearn  *    This product includes software developed by Boris Popov.
16f1b9d127SSheldon Hearn  * 4. Neither the name of the author nor the names of any co-contributors
17f1b9d127SSheldon Hearn  *    may be used to endorse or promote products derived from this software
18f1b9d127SSheldon Hearn  *    without specific prior written permission.
19f1b9d127SSheldon Hearn  *
20f1b9d127SSheldon Hearn  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21f1b9d127SSheldon Hearn  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22f1b9d127SSheldon Hearn  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23f1b9d127SSheldon Hearn  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24f1b9d127SSheldon Hearn  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25f1b9d127SSheldon Hearn  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26f1b9d127SSheldon Hearn  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27f1b9d127SSheldon Hearn  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28f1b9d127SSheldon Hearn  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29f1b9d127SSheldon Hearn  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30f1b9d127SSheldon Hearn  * SUCH DAMAGE.
31f1b9d127SSheldon Hearn  *
32f1b9d127SSheldon Hearn  * $Id: nb_lib.h,v 1.2 2000/07/17 01:49:27 bp Exp $
33ef29b0f6SBoris Popov  * $FreeBSD$
34f1b9d127SSheldon Hearn  */
35f1b9d127SSheldon Hearn #ifndef _NETSMB_NB_LIB_H_
36f1b9d127SSheldon Hearn #define	_NETSMB_NB_LIB_H_
37f1b9d127SSheldon Hearn 
38f1b9d127SSheldon Hearn /*
39f1b9d127SSheldon Hearn  * Error codes
40f1b9d127SSheldon Hearn  */
41f1b9d127SSheldon Hearn #define NBERR_INVALIDFORMAT	0x0001
42f1b9d127SSheldon Hearn #define NBERR_SRVFAILURE	0x0002
43f1b9d127SSheldon Hearn #define NBERR_NAMENOTFOUND	0x0003
44f1b9d127SSheldon Hearn #define NBERR_IMP		0x0004
45f1b9d127SSheldon Hearn #define NBERR_REFUSED		0x0005
46f1b9d127SSheldon Hearn #define NBERR_ACTIVE		0x0006
47f1b9d127SSheldon Hearn #define NBERR_HOSTNOTFOUND	0x0101
48f1b9d127SSheldon Hearn #define NBERR_TOOMANYREDIRECTS	0x0102
49f1b9d127SSheldon Hearn #define NBERR_INVALIDRESPONSE	0x0103
50f1b9d127SSheldon Hearn #define NBERR_NAMETOOLONG	0x0104
51f1b9d127SSheldon Hearn #define	NBERR_NOBCASTIFS	0x0105
52f1b9d127SSheldon Hearn #define NBERR_MAX		0x0106
53f1b9d127SSheldon Hearn #define NBERROR(e)		((e) |  SMB_NB_ERROR)
54f1b9d127SSheldon Hearn 
55f1b9d127SSheldon Hearn #define	NBCF_RESOLVED	0x0001
56f1b9d127SSheldon Hearn 
57f1b9d127SSheldon Hearn /*
58f1b9d127SSheldon Hearn  * nb environment
59f1b9d127SSheldon Hearn  */
60f1b9d127SSheldon Hearn struct nb_ctx {
61f1b9d127SSheldon Hearn 	int		nb_flags;
62f1b9d127SSheldon Hearn 	int		nb_timo;
63f1b9d127SSheldon Hearn 	char *		nb_scope;	/* NetBIOS scope */
64f1b9d127SSheldon Hearn 	char *		nb_nsname;	/* name server */
65f1b9d127SSheldon Hearn 	struct sockaddr_in	nb_ns;	/* ip addr of name server */
66f1b9d127SSheldon Hearn 	struct sockaddr_in	nb_lastns;
67ef29b0f6SBoris Popov 	long		nb_nmbtcpport;	/* default: NMB_TCP_PORT = 137 */
68ef29b0f6SBoris Popov 	long		nb_smbtcpport;	/* default: SMB_TCP_PORT = 139 */
69f1b9d127SSheldon Hearn };
70f1b9d127SSheldon Hearn 
71f1b9d127SSheldon Hearn /*
72f1b9d127SSheldon Hearn  * resource record
73f1b9d127SSheldon Hearn  */
74f1b9d127SSheldon Hearn struct nbns_rr {
75f1b9d127SSheldon Hearn 	u_char *	rr_name;	/* compressed NETBIOS name */
76f1b9d127SSheldon Hearn 	u_int16_t	rr_type;
77f1b9d127SSheldon Hearn 	u_int16_t	rr_class;
78f1b9d127SSheldon Hearn 	u_int32_t	rr_ttl;
79f1b9d127SSheldon Hearn 	u_int16_t	rr_rdlength;
80f1b9d127SSheldon Hearn 	u_char *	rr_data;
81f1b9d127SSheldon Hearn };
82f1b9d127SSheldon Hearn 
83f1b9d127SSheldon Hearn #define NBRQF_BROADCAST		0x0001
84f1b9d127SSheldon Hearn /*
85f1b9d127SSheldon Hearn  * nbns request
86f1b9d127SSheldon Hearn  */
87f1b9d127SSheldon Hearn struct nbns_rq {
88f1b9d127SSheldon Hearn 	int		nr_opcode;
89f1b9d127SSheldon Hearn 	int		nr_nmflags;
90f1b9d127SSheldon Hearn 	int		nr_rcode;
91f1b9d127SSheldon Hearn 	int		nr_qdcount;
92f1b9d127SSheldon Hearn 	int		nr_ancount;
93f1b9d127SSheldon Hearn 	int		nr_nscount;
94f1b9d127SSheldon Hearn 	int		nr_arcount;
95f1b9d127SSheldon Hearn 	struct nb_name*	nr_qdname;
96f1b9d127SSheldon Hearn 	u_int16_t	nr_qdtype;
97f1b9d127SSheldon Hearn 	u_int16_t	nr_qdclass;
98f1b9d127SSheldon Hearn 	struct sockaddr_in nr_dest;	/* receiver of query */
99f1b9d127SSheldon Hearn 	struct sockaddr_in nr_sender;	/* sender of response */
100f1b9d127SSheldon Hearn 	int		nr_rpnmflags;
101f1b9d127SSheldon Hearn 	int		nr_rprcode;
102f1b9d127SSheldon Hearn 	u_int16_t	nr_rpancount;
103f1b9d127SSheldon Hearn 	u_int16_t	nr_rpnscount;
104f1b9d127SSheldon Hearn 	u_int16_t	nr_rparcount;
105f1b9d127SSheldon Hearn 	u_int16_t	nr_trnid;
106f1b9d127SSheldon Hearn 	struct nb_ctx *	nr_nbd;
107f1b9d127SSheldon Hearn 	struct mbdata	nr_rq;
108f1b9d127SSheldon Hearn 	struct mbdata	nr_rp;
109f1b9d127SSheldon Hearn 	struct nb_ifdesc *nr_if;
110f1b9d127SSheldon Hearn 	int		nr_flags;
111f1b9d127SSheldon Hearn 	int		nr_fd;
112f1b9d127SSheldon Hearn };
113f1b9d127SSheldon Hearn 
114f1b9d127SSheldon Hearn struct nb_ifdesc {
115f1b9d127SSheldon Hearn 	int		id_flags;
116f1b9d127SSheldon Hearn 	struct in_addr	id_addr;
117f1b9d127SSheldon Hearn 	struct in_addr	id_mask;
118f1b9d127SSheldon Hearn 	char		id_name[16];	/* actually IFNAMSIZ */
119f1b9d127SSheldon Hearn 	struct nb_ifdesc * id_next;
120f1b9d127SSheldon Hearn };
121f1b9d127SSheldon Hearn 
122f1b9d127SSheldon Hearn struct sockaddr;
123f1b9d127SSheldon Hearn 
124f1b9d127SSheldon Hearn __BEGIN_DECLS
125f1b9d127SSheldon Hearn 
126f1b9d127SSheldon Hearn int nb_name_len(struct nb_name *);
127f1b9d127SSheldon Hearn int nb_name_encode(struct nb_name *, u_char *);
128f1b9d127SSheldon Hearn int nb_encname_len(const char *);
129f1b9d127SSheldon Hearn 
130f1b9d127SSheldon Hearn int  nb_snballoc(int namelen, struct sockaddr_nb **);
131f1b9d127SSheldon Hearn void nb_snbfree(struct sockaddr*);
132f1b9d127SSheldon Hearn int  nb_sockaddr(struct sockaddr *, struct nb_name *, struct sockaddr_nb **);
133f1b9d127SSheldon Hearn 
134ef29b0f6SBoris Popov int  nb_resolvehost_in(const char *, struct sockaddr **, long);
135f1b9d127SSheldon Hearn int  nbns_resolvename(const char *, struct nb_ctx *, struct sockaddr **);
136f1b9d127SSheldon Hearn int  nb_getlocalname(char *name);
137f1b9d127SSheldon Hearn int  nb_enum_if(struct nb_ifdesc **, int);
138f1b9d127SSheldon Hearn 
139f1b9d127SSheldon Hearn const char *nb_strerror(int error);
140f1b9d127SSheldon Hearn 
141f1b9d127SSheldon Hearn int  nb_ctx_create(struct nb_ctx **);
142f1b9d127SSheldon Hearn void nb_ctx_done(struct nb_ctx *);
143f1b9d127SSheldon Hearn int  nb_ctx_setns(struct nb_ctx *, const char *);
144f1b9d127SSheldon Hearn int  nb_ctx_setscope(struct nb_ctx *, const char *);
145f1b9d127SSheldon Hearn int  nb_ctx_resolve(struct nb_ctx *);
146f1b9d127SSheldon Hearn int  nb_ctx_readrcsection(struct rcfile *, struct nb_ctx *, const char *, int);
147f1b9d127SSheldon Hearn 
148f1b9d127SSheldon Hearn __END_DECLS
149f1b9d127SSheldon Hearn 
150f1b9d127SSheldon Hearn #endif /* !_NETSMB_NB_LIB_H_ */
151