Programmer's Guide to Netbios HOWARD W SAMS &
Total Page:16
File Type:pdf, Size:1020Kb
NetBIOS Final Return Codes OOh Successful completion, good return Olh Invalid buffer length 03h Invalid command OSh Command timed-out o6h Incomplete received message 07h Local No-Ack command failed OSh Invalid local session number 09h No resource available OAh Session has been closed OBh Command was canceled ODh Duplicate name in local NetBIOS name table OEh NetBIOS name table full OFh Name has active sessions and is now de registered 11h NetBIOS local session table full I2h Session open rejected because no Listen is outstanding I3h Illegal name number I4h Cannot find name called or no answer ISh Name not found, or cannot specify asterisk (*) or OOh as first byte of NcbName, or the name is de registered and cannot be used I6h Name in use on remote adapter I7h Name deleted ISh Session ended abnormally I9h Name conflict detected IAh Incompatible remote device (PC Network) 2Ih Interface busy 22h Too many commands outstanding 23h Invalid number in NcbLanaNum field 24h Command completed while pncel occurring 2Sh Reserved name specified for Add Group Name 26h Command not valid to cancel 30h Name defined by another process (OS/2 Extended Edition only) 34h NetBIOS environment not defined (OS/2 Extended Edition only) 3Sh Required operating system resources (OS/2 Extended Edition only) 36h Maximum applications exceeded (OS/2 Extended Edition only) 37h No SAPs available for NetBIOS (OS/2 Extended Edition only) 38h Requested resources not available (OS/2 Extended Edition only) 40h System error (PC Network) 4Ih Hot carrier from a remote adapter detected (PC Network) 42h Hot carrier from this adapter detected (PC Network) 43h No carrier detected (PC Network) 4Eh Status bit 12, 14, or 15 on longer than one minute (Token-Ring) 4Fh One or more of status bits 8-11 on (Token-Ring) SOh-F6h Adapter malfunction F7h Error on implicit DIR.INITIALIZE F8h Error on implicit DIR.OPEN.ADAPTER F9h IBM LAN Support Program internal error FAh Adapter check FBh NetBIOS program not loaded in PC FCh DIR.OPEN.ADAPTER or DLC.OPEN.SAP failed-check parameters FDh Unexpected adapter close FFh Command-pending status c Programmer's Guide to NetBIOS HOWARD W SAMS &.. COMPANY HAYDEN BOOKS Related Titles C Programmer's Guide to The Waite Group's Turbo C® Serial Communications Bible Joe Campbell Naba Barkakati C with Excellence: The Waite Group's Turbo Cc& Programming Proverbs Programming for the IBM® Henry Ledgard with John Tauer Robert Lafore QuickC ™ Programming for the IBM® Hayden Books Carl Townsend C Library Turbo C® Developer's Library Edward R. Rought and Thomas D. Programming in C, Revised Hoops Edition Stephen G. Kochan C Programmer's Guide to Microsoft® Windows 2.0 Programming in ANSI C Carl Townsend Stephen G. Kochan The Waite Group's Advanced Advanced C: Tips and C Primer++ Techniques Stephen Prata Paul Anderson and Gail Anderson The Waite Group's C++ Portability and the C Programming (Version 2.0) Language Edited by The Waite Group Rex Jaeschke The Waite Group's Microsoft® C Bible Hayden Books UNIX® Naba Barkakati System Library The Waite Group's Microsoft® C Programming for the IBM® Topics in C Programming Robert Lafore Stephen G. Kochan, Patrick H. Wood For the retailer nearest you, or to order directly from the publisher, call800-428-SAMS. In Indiana, Alaska, and Hawaii call 317-298-5699. C Programmer's Guide to NetBIOS w. DAVID SCHWADERER #f HOWARD W. SAMS &,COMPANY A Division of Macm/lJan, Inc. 4300 West 62nd Street Indianapolis, Indiana 46268 USA Send code corrections that may be incorporated into the sample programs, helpful insights, suggestions, and requests for technical assistance to: W. David Schwaderer c/o Howard W. Sams & Company Public Relations Department 4300 West 62nd Street Indianapolis, IN 46268 Please note the author may use and distribute the material you submit in any way he believes is appropriate without incurring any obligation. ©1988 by W. David Schwaderer FIRST EDITION SECOND PRINTING - 1988 All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. International Standard Book Number: 0-672-22638-3 Library of Congress Catalog Card Number: 88-62228 Acquisition Editor: James S. Hill Development Editor: James Rounds Production Coordinator: Marjorie Colvin Editor: Albright Communications, Incorporated Illustrator: Donald B. Clemons Cover Artist: Ned Shaw Keyboarder: Lee Hubbard, Type Connection, Indianapolis Indexer: Brown Editorial Service Compositor: Shepard Poorman Communications Corporation Printed in the United States oj America Trademark Acknowledgments All terms mentioned in this book that are known to be trademarks or service marks are listed below. In addition, terms suspected of being trademarks or service marks have been appropriately capitalized. Howard W. Sams & Company cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. The following are trademarks of International Business Machines Corporation: IBM, Personal System/2, PS/2, Operating System/2, OS/2, Operating System/2 Extended Edition, OS/2 EE, PC-DOS, IBM XT, and IBM AT. Ethernet and Xerox are registered trademarks of Xerox Corporation. Microsoft and Microsoft C are registered trademarks of Microsoft Corporation. UNIX and AT&T are registered trademarks of American Telephone and Telegraph. 1b my family: Barbara, Greg, and Melissa and 1b the incandescent intellects ofjames T Brady and Larry K Raper Contents Foreword xiii Preface xv Part I Introduction to NetBIOS 1 1 Overview 3 Where Does NetBIOS Fit in the Scheme of Things? 3 Where Did NetBIOS Come From? 5 What Is "True NetBIOS"? 6 How Do I Get NetBIOS? 6 What IBM NetBIOS Reference Material Is Available? 9 2 NetBIOS and IBM's LAN Adapters 11 Token-Ring Environment 11 IBM PC Network Broadband Environment 13 IBM PC Network Baseband Environment 14 Ethernet Environment 15 IBM LAN Programming Interfaces 15 3 Application Services 19 NetBIOS Name Support 19 Datagram and Session Support 23 General Commands 30 vii viii C Programmers Guide to NetBIOS Issuing NetBIOS Commands 32 Testing for the Presence of NetBIOS 34 4 Ncb/Mcb Fields 37 Command 39 Return Code 40 Local Session Number 41 Name Number 41 Buffer Address 41 Buffer Length 41 Call (Remote) Name 41 (Local) Name 42 Receive Time Out 42 Send Time Out 42 Post Routine Address 43 LANA Number 43 Command Complete Flag 43 Reserved 43 Sample C Program to Test for NetBIOS Presence 44 5 The IBM PC-DOS LAN Support Program 47 What Is Its Role? 47 NetBIOS Parameter Summary 48 6 NetBIOS Relationships to Other IBM Products 57 IBM PC-DOS Version Requirements 57 IBM PC LAN Program Considerations 57 7 LAN Data Integrity and Security 63 LAN Data Integrity 63 LAN Data Security-A Word to the Wise 63 The Uneasy Conclusion 65 Part II NetBIOS Support Programming 67 8 General Support Programming 69 The NetBIOS RESET Sample Program 69 Contents ix The NetBIOS Adapter Status Sample Program 77 The Adapter Reset and Adapter Status Synergy 86 The NetBIOS Cancel Sample Program 88 The NetBIOS Unlink Sample Program 92 9 Name Support Programming 95 The NetBIOS Name Activity Sample Program 95 10 Datagram Support Programming 101 The main( ) Function 104 InitDatagramNcb( ) and XmitDatagram( ) 104 11 Intermediate Datagram Applications 105 A Date and Time Server Application 105 A Date and Time Client Application 109 12 Real-Time LAN Conferencing Application 119 The main( ) Function 133 EditArgs( ) 134 NetBIOS Add Name Processing Routines 134 Participate( ) 134 ServiceDatagramNcbs( ) 135 ProcessReceivedDatagram( ) 136 ServiceKeyboard( ) 136 SendKeyboardMsg( ) 137 ApplyKeystroke( ) 137 13 C File Transfer Applications 139 Application Overview 152 14 Medialess Workstations, RPL, and Redirectors 155 Clients and Servers 155 Data Layers 156 A Redirector Implementation 159 A Block Device Driver Implementation 159 The INT 13 BIOS Interface 160 x C Programmer's Guide to NetBIOS A NetBIOS RPL Implementation-Or How Does PC-DOS Get in There? 160 Part III A Cyclic Redundancy Check (CRC) Treatise 167 15 CRC Fundamentals 169 The Need for CRC Checking 169 The XMODEM Check Sum 170 CRC Mathematics 170 CRC Calculation 174 Prevalent CRC Polynomials 177 16 CRC-16 and CRC General Mechanics 181 CRC Hardware 183 Generalized CRC-16 Shifting 189 Thble Look-Up Schemes 192 CRC Compatibility Caveats 198 17 CRC-CCITT and Minimum Look-Up Table Sizes 199 The Table Look-Up Approach 200 18 CRC-32-Token-Ring, PC Network, and Ethernet 207 Part IV NetBIOS Technical Reference 219 19 Network Control Block 221 Ncb Fields 221 Command Completion 228 20 NetBIOS Commands 231 The Commands 231 Special Value Summary 260 Complex Hang Up Scenario 261 Return Code Summary 261 Contents xi Appendixes 263 A NetBIOS2.h Listing 265 B C Post Routine Listing· 271 C Error Codes, Reasons, and Actions 275 D Ncb Command and Field Relationship 287 E Send No-Ack and Chain Send No-Ack 291 F OS/2 Extended Edition and LAN Manager 295 Bibliography 301 Index 303 Foreword NetBIOS is an extremely important network programming interface. In the PC-DOS arena NetBIOS provides a consistent interface for communi cation systems using IBM, XNS, TCp, IEEE and OSI protocols, among others. As we networkers migrate our systems to new protocols such as OSI, to new LAN operating systems such as the OS/2 LAN Manager, and to new hardware platforms such as the PS/2 and Macintosh II, NetBIOS's importance expands.