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 $ 33f1b9d127SSheldon Hearn */ 34f1b9d127SSheldon Hearn #ifndef _NETSMB_NB_LIB_H_ 35f1b9d127SSheldon Hearn #define _NETSMB_NB_LIB_H_ 36f1b9d127SSheldon Hearn 37f1b9d127SSheldon Hearn /* 38f1b9d127SSheldon Hearn * Error codes 39f1b9d127SSheldon Hearn */ 40f1b9d127SSheldon Hearn #define NBERR_INVALIDFORMAT 0x0001 41f1b9d127SSheldon Hearn #define NBERR_SRVFAILURE 0x0002 42f1b9d127SSheldon Hearn #define NBERR_NAMENOTFOUND 0x0003 43f1b9d127SSheldon Hearn #define NBERR_IMP 0x0004 44f1b9d127SSheldon Hearn #define NBERR_REFUSED 0x0005 45f1b9d127SSheldon Hearn #define NBERR_ACTIVE 0x0006 46f1b9d127SSheldon Hearn #define NBERR_HOSTNOTFOUND 0x0101 47f1b9d127SSheldon Hearn #define NBERR_TOOMANYREDIRECTS 0x0102 48f1b9d127SSheldon Hearn #define NBERR_INVALIDRESPONSE 0x0103 49f1b9d127SSheldon Hearn #define NBERR_NAMETOOLONG 0x0104 50f1b9d127SSheldon Hearn #define NBERR_NOBCASTIFS 0x0105 51f1b9d127SSheldon Hearn #define NBERR_MAX 0x0106 52f1b9d127SSheldon Hearn #define NBERROR(e) ((e) | SMB_NB_ERROR) 53f1b9d127SSheldon Hearn 54f1b9d127SSheldon Hearn #define NBCF_RESOLVED 0x0001 55f1b9d127SSheldon Hearn 56f1b9d127SSheldon Hearn /* 57f1b9d127SSheldon Hearn * nb environment 58f1b9d127SSheldon Hearn */ 59f1b9d127SSheldon Hearn struct nb_ctx { 60f1b9d127SSheldon Hearn int nb_flags; 61f1b9d127SSheldon Hearn int nb_timo; 62f1b9d127SSheldon Hearn char * nb_scope; /* NetBIOS scope */ 63f1b9d127SSheldon Hearn char * nb_nsname; /* name server */ 64f1b9d127SSheldon Hearn struct sockaddr_in nb_ns; /* ip addr of name server */ 65f1b9d127SSheldon Hearn struct sockaddr_in nb_lastns; 66f1b9d127SSheldon Hearn }; 67f1b9d127SSheldon Hearn 68f1b9d127SSheldon Hearn /* 69f1b9d127SSheldon Hearn * resource record 70f1b9d127SSheldon Hearn */ 71f1b9d127SSheldon Hearn struct nbns_rr { 72f1b9d127SSheldon Hearn u_char * rr_name; /* compressed NETBIOS name */ 73f1b9d127SSheldon Hearn u_int16_t rr_type; 74f1b9d127SSheldon Hearn u_int16_t rr_class; 75f1b9d127SSheldon Hearn u_int32_t rr_ttl; 76f1b9d127SSheldon Hearn u_int16_t rr_rdlength; 77f1b9d127SSheldon Hearn u_char * rr_data; 78f1b9d127SSheldon Hearn }; 79f1b9d127SSheldon Hearn 80f1b9d127SSheldon Hearn #define NBRQF_BROADCAST 0x0001 81f1b9d127SSheldon Hearn /* 82f1b9d127SSheldon Hearn * nbns request 83f1b9d127SSheldon Hearn */ 84f1b9d127SSheldon Hearn struct nbns_rq { 85f1b9d127SSheldon Hearn int nr_opcode; 86f1b9d127SSheldon Hearn int nr_nmflags; 87f1b9d127SSheldon Hearn int nr_rcode; 88f1b9d127SSheldon Hearn int nr_qdcount; 89f1b9d127SSheldon Hearn int nr_ancount; 90f1b9d127SSheldon Hearn int nr_nscount; 91f1b9d127SSheldon Hearn int nr_arcount; 92f1b9d127SSheldon Hearn struct nb_name* nr_qdname; 93f1b9d127SSheldon Hearn u_int16_t nr_qdtype; 94f1b9d127SSheldon Hearn u_int16_t nr_qdclass; 95f1b9d127SSheldon Hearn struct sockaddr_in nr_dest; /* receiver of query */ 96f1b9d127SSheldon Hearn struct sockaddr_in nr_sender; /* sender of response */ 97f1b9d127SSheldon Hearn int nr_rpnmflags; 98f1b9d127SSheldon Hearn int nr_rprcode; 99f1b9d127SSheldon Hearn u_int16_t nr_rpancount; 100f1b9d127SSheldon Hearn u_int16_t nr_rpnscount; 101f1b9d127SSheldon Hearn u_int16_t nr_rparcount; 102f1b9d127SSheldon Hearn u_int16_t nr_trnid; 103f1b9d127SSheldon Hearn struct nb_ctx * nr_nbd; 104f1b9d127SSheldon Hearn struct mbdata nr_rq; 105f1b9d127SSheldon Hearn struct mbdata nr_rp; 106f1b9d127SSheldon Hearn struct nb_ifdesc *nr_if; 107f1b9d127SSheldon Hearn int nr_flags; 108f1b9d127SSheldon Hearn int nr_fd; 109f1b9d127SSheldon Hearn }; 110f1b9d127SSheldon Hearn 111f1b9d127SSheldon Hearn struct nb_ifdesc { 112f1b9d127SSheldon Hearn int id_flags; 113f1b9d127SSheldon Hearn struct in_addr id_addr; 114f1b9d127SSheldon Hearn struct in_addr id_mask; 115f1b9d127SSheldon Hearn char id_name[16]; /* actually IFNAMSIZ */ 116f1b9d127SSheldon Hearn struct nb_ifdesc * id_next; 117f1b9d127SSheldon Hearn }; 118f1b9d127SSheldon Hearn 119f1b9d127SSheldon Hearn struct sockaddr; 120f1b9d127SSheldon Hearn 121f1b9d127SSheldon Hearn __BEGIN_DECLS 122f1b9d127SSheldon Hearn 123f1b9d127SSheldon Hearn int nb_name_len(struct nb_name *); 124f1b9d127SSheldon Hearn int nb_name_encode(struct nb_name *, u_char *); 125f1b9d127SSheldon Hearn int nb_encname_len(const char *); 126f1b9d127SSheldon Hearn 127f1b9d127SSheldon Hearn int nb_snballoc(int namelen, struct sockaddr_nb **); 128f1b9d127SSheldon Hearn void nb_snbfree(struct sockaddr*); 129f1b9d127SSheldon Hearn int nb_sockaddr(struct sockaddr *, struct nb_name *, struct sockaddr_nb **); 130f1b9d127SSheldon Hearn 131f1b9d127SSheldon Hearn int nb_resolvehost_in(const char *, struct sockaddr **); 132f1b9d127SSheldon Hearn int nbns_resolvename(const char *, struct nb_ctx *, struct sockaddr **); 133f1b9d127SSheldon Hearn int nb_getlocalname(char *name); 134f1b9d127SSheldon Hearn int nb_enum_if(struct nb_ifdesc **, int); 135f1b9d127SSheldon Hearn 136f1b9d127SSheldon Hearn const char *nb_strerror(int error); 137f1b9d127SSheldon Hearn 138f1b9d127SSheldon Hearn int nb_ctx_create(struct nb_ctx **); 139f1b9d127SSheldon Hearn void nb_ctx_done(struct nb_ctx *); 140f1b9d127SSheldon Hearn int nb_ctx_setns(struct nb_ctx *, const char *); 141f1b9d127SSheldon Hearn int nb_ctx_setscope(struct nb_ctx *, const char *); 142f1b9d127SSheldon Hearn int nb_ctx_resolve(struct nb_ctx *); 143f1b9d127SSheldon Hearn int nb_ctx_readrcsection(struct rcfile *, struct nb_ctx *, const char *, int); 144f1b9d127SSheldon Hearn 145f1b9d127SSheldon Hearn __END_DECLS 146f1b9d127SSheldon Hearn 147f1b9d127SSheldon Hearn #endif /* !_NETSMB_NB_LIB_H_ */ 148