Xref: utzoo comp.os.os2.misc:30 comp.protocols.tcp-ip:12358 comp.protocols.tcp-ip.ibmpc:3430 Path: utzoo!attcan!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!ncar!ames!excelan!bbaker From: bbaker@na.novell.com (Brad Baker) Newsgroups: comp.os.os2.misc,comp.protocols.tcp-ip,comp.protocols.tcp-ip.ibmpc Subject: REPOST: NBA Netbios Broadcast Agent (1of2) Message-ID: <1606@excelan.COM> Date: 26 Jul 90 17:03:51 GMT Sender: news@excelan.COM Reply-To: bbaker@na.novell.com (Brad Baker) Followup-To: comp.os.os2 Organization: Novell, San Jose, CA. Lines: 300 REPOST: In straight ascii file 1of2 (make+headers) Sources for NBA (OS2 and Unix) Netbios Broadcast Agent Effectively internets the Netbios Name service. This program is useful for effectively combining netbios networks that are separated on the internet. It could also be used to connect to a remote Unix SMB server allowing for file and print services across the internet. Written to the BSD 4.3 sockets interface. It has been compiled and run on 68XXX and SPARC Unix machines, as well as OS/2, with no code changes. Necessary files are: makefile (os2) name.h (os2,unix) nba.h (os2,unix) nba.c (os2,unix) See the documentation header in nba.c for more extensive info. # # makefile for OS/2 NBA # #----------------------------------------------- # Definitions for MSC 5.1 Compiler # /c -- compile only (suppress linking) # /A$(model) -- Specifies memory model # /Gs2 -- Disable stack probes, use 286 instructions # /Zl -- Remove default library info # /DOS2 -- OS/2 environment # /DDDL -- use of DDL # /W3 -- Maximum warning level #----------------------------------------------- # # model can be = lfu - large code, far data, SS != DS # lnu - large code, near data, SS != DS # sfu - small code, far data, SS != DS # snu - small code, near data, SS != DS # # See MTDYNA.DOC for more details on this subject # model=lfu # # include paths - use multi-thread include files # XLNPATH=\xln\toolkit TK_INCL=$(XLNPATH)\include INCLUDE=-I. -I$(TK_INCL) -I\msc51\include\mt # # libpaths should be set in the LIB environment string # XLNLIBS=bsd43.lib crtlib.lib MSLIBS=doscalls.lib ALL_LIBS=$(XLNLIBS) $(MSLIBS) # # compile flags # CFLAGS= /c /A$(model) /Ox /Zli /Gs2 /DDLL /DDEBUG /DOS2 /W3 $(INCLUDE) # # link flags # LFLAGS= /CO /NOD /MAP /NOI LINKCMD=$(LFLAGS) $** + \xln\toolkit\os2lib\crtexe.obj,$@,$*.map,$(ALL_LIBS) .c.obj: cl $(CFLAGS) $*.c > $*.err nba.obj: nba.c nba.h name.h ##### Link commands ###### nba: nba.obj link $(LINKCMD); markexe WINDOWCOMPAT nba.exe /* ---------------------------------------------------------------------------- Copyright (C) 1990 Novell, Inc. This software may be freely copied and distributed, provided the above copyright notice is included. It may not be sold, in whole or in part, without the prior written consent of Novell, Inc. ---------------------------------------------------------------------------- NAME.H header file for nba.c */ #define IP_DGRAM_SZ 576 #define IP_HDR_SZ 20 #define UDP_HDR_SZ 8 #define SZ_BUFFER (IP_DGRAM_SZ - IP_HDR_SZ - UDP_HDR_SZ) #define SZ_MAXPKTDATA 576 /* maximum data in a packet */ /**************************************************************************** * Domain Name Packet Definitions ***************************************************************************/ #define NM_REG_REQ 0x2910 #define NM_RES 0xad80 #define NM_QRY 0x0110 #define NM_QRY_RES 0x8500 #define NM_QRY_RES1 0x8580 #define NODE_STATUS_REQ 0x0010 #define NODE_STATUS_RES 0x8400 #define NM_OVR_REQ 0x2810 #define NM_RLS_REQ 0x3010 #define PKT_MSK 0xfdf0 /* Mask of bits used for packet type. */ #define RCODE_MSK 0x000f /* Mask of bits used for rcode */ /* * Mask values for NM_FLAGS. These values treat the fields, * OPCODE, NM_FLAGS, and RCODE as one word (16 bits). */ #define NS_BROADCAST 0x0001 #define NS_RESRVD1 0x0002 #define NS_RESRVD2 0x0004 #define NS_RA 0x0008 #define NS_RD 0x1000 #define NS_TC 0x2000 /* truncation bit */ #define NS_AA 0x4000 /* error codes for RCODE field in packet header */ #define FMT_ERR 0x1 /* Invalidly Formatted Request */ #define SRV_ERR 0x2 /* Server Failure */ #define IMP_ERR 0x4 /* Unsupported Request */ #define RFS_ERR 0x5 /* Registration Refusal */ #define ACT_ERR 0x6 /* Active erroe, name is owned by another node. */ #define CFT_ERR 0x7 /* Name is in conflict */ /* type values */ #define NS_A 0x0100 /* IP address RR */ #define NS_NS 0x0002 /* Name Server RR */ #define NS_NB 0x0020 /* General Name Service RR */ #define NS_NBSTAT 0x0021 /* Node Status RR */ #define NS_NULL 0x000a /* NULL RR - see WACK definition */ #define NS_IN 0x0001 /* Internet class */ /* values for NB_FLAG field in RR data */ #define NS_GROUP 0x8000 /* Group Bit, 1 == Group Netbios Name */ #define NS_MNODE 0x4000 #define NS_PNODE 0x2000 #define NS_DRG 0x1000 #define NS_BNODE 0x0000 #define NS_CNF 0x0800 #define NS_ACT 0x0400 #define NS_PRM 0x0200 /* masks for NB_FLAG field in name data entry */ #define NS_GROUPMSK ~0x8000 /* Group Name Flag */ #define NS_ONTMSK ~0x6000 /* Owner Node Type */ #define NS_STATEMSK ~0x1d00 /* Name State Bits */ /**************************************************************************** * Question Section trailer: preceded by a compressed Netbios name ***************************************************************************/ struct quest_trailer { unsigned short type; unsigned short class; }; /* 4 bytes long */ /**************************************************************************** * Resource Record trailer: preceded by a compressed Netbios name, followed * by a variable data section ***************************************************************************/ struct rr_trailer { unsigned short type; unsigned short class; unsigned long ttl; unsigned short length; }; /* 10 bytes long */ struct rr_info { struct rr_trailer trailer; unsigned short flags; long nbaddr; }; /* 16 bytes long */ struct nmpkt_hdr { unsigned short nm_tid; /* transaction id */ unsigned short status; /* opcode, flags, return code */ unsigned short qdcount; /* number of question entries */ unsigned short ancount; /* number of answer records */ unsigned short nscount; /* number of authority records */ unsigned short arcount; /* number of additional records */ }; /* 12 bytes long */ struct namepkt { struct nmpkt_hdr header; unsigned char records[SZ_BUFFER - sizeof(struct nmpkt_hdr)]; }; #define NAME_SERVICE_UDP_PORT 137 /* ---------------------------------------------------------------------------- Copyright (C) 1990 Novell, Inc. This software may be freely copied and distributed, provided the above copyright notice is included. It may not be sold, in whole or in part, without the prior written consent of Novell, Inc. ---------------------------------------------------------------------------- NBA.H header file for nba.c */ /******* "ignore" this stuff ******/ #ifndef FD_SET #define NBBY 8 /* number of bits in a byte */ /* * Select uses bit masks of file descriptors in longs. * These macros manipulate such bit fields (the filesystem macros use chars). * FD_SETSIZE may be defined by the user, but the default here * should be >= NOFILE (param.h). */ #ifndef FD_SETSIZE #define FD_SETSIZE 32 #endif typedef long fd_mask; #define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ #ifndef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) #endif #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) #define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) #endif /**************** real stuff below here *****************/ typedef unsigned short USHORT; typedef unsigned long ULONG; typedef unsigned BOOL; #define TRUE 1 #define FALSE 0 #define NBA_WK_PORT 3000 /* an unassigned port */ #define BAQSIZE 100 #define BAPKTLIFE 5 /* packet life */ #define SZ_NCBNAME 16 #define SOCKADDRSIZE sizeof(struct sockaddr_in) #define AGENT_NAME_LEN 11 #define FILE_NAME_LEN 80 /* BA status codes */ #define BA_SEND 0 #define BA_REPLY 1 #define BA_ERROR -1 #define NS_RES_MASK 0x8000 /* mask for the NS response bit */ /* conversion macros */ /* convert network order long to network order short */ #define NLtoNS(x) htons((USHORT)ntohl(x)) /* convert network order short to network order long */ #define NStoNL(x) htonl((ULONG)ntohs(x)) struct ba_header { ULONG status; /* command codes for BA agents */ ULONG time; /* time stamp for packet expiration */ ULONG ns_tid; /* name service transaction id */ ULONG ba_tid; /* BA agent transaction id */ ULONG host_addr; /* BA agent address */ ULONG client_addr; /* NS client address */ ULONG client_port; /* NS client port */ #define BAHEADERSIZE sizeof(struct ba_header) }; struct ba_pkt { struct ba_header baheader; struct namepkt namepkt; #define BAPKTSIZE sizeof(struct ba_header) + SZ_BUFFER };