C Programmer's Guide to NetBIOS, IPX, and SPX

W. David Schwaderer

J^TT,JpT 11uf A Division of Prentice Hall Publishing rUBLIbnlNb 11711 North College, Carmel, Indiana46032 USA Table of Contents

Foreword xi Preface xiii Acknowledgments xv Part I - Introduction to NetBIOS

Overview 3 Where Does NetBIOS Fit in the Scheme of Things? 4 Where Did NetBIOS Come From? 5 What Is "True NetBIOS"? 6 How Do I Get NetBIOS? 7 What IBM NetBIOS Reference Material Is Available? 9

NetBIOS and IBM's LAN Adapters 13 Token-Ring Environment 14 IBM PC Network Broadband Environment 15 IBM PC Network Baseband Environment 16 Environment 17 IBM LAN Programming Interfaces 17

Application Services 21 NetBIOS Name Support 21 and Session Support 26 General Commands 34 Issuing NetBIOS Commands 36 Testing for the Presence of NetBIOS 38

Ncb/Mcb Fields 41 Command 44 Return Code 45 Local Session Number 45 Name Number 45 C Programmer's Guide to NetBIOS, IPX, and SPX

Buffer Address 46 Buffer Length 46 Call (Remote) Name 46 (Local) Name 46 Receive Time Out 47 Send Time Out 47 Post Routine Address 47 LANA Number 47 Command Complete Flag 48 Reserved 48 Sample C Program to Test for NetBIOS Presence 48

5 The IBM PC DOS LAN Support Program 53 What Is Its Role? 54 NetBIOS Parameter Summary 54

6 NetBIOS Relationships to Other IBM Products 65 IBM PC DOS Version Requirements 65 IBM PC LAN Program Considerations 66

7 LAN Data Integrity and Security 73 LAN Data Integrity 73 LAN Data Security—A Word to the Wise 74 The Uneasy Conclusion 75 Part II - NetBios Supporting Programming

8 General Support Programming 79 The NetBIOS RESET Sample Program 80 The NetBIOS Adapter Status Sample Program 88 The Adapter Reset and Adapter Status Synergy 99 The NetBIOS Cancel Sample Program 99 The NetBIOS Unlink Sample Program 105

VI Table of Contents

9 Name Support Programming 109 The NetBIOS Name Activity Sample Program 109

10 Datagram Support Programming 115 The main() Function 118 InitDatagramNcb() and XmitDatagram() 119

11 Intermediate Datagram Applications 121 A Date and Time Server Application 122 A Date and Time Client Application 126

12 Real-Time LAN Conferencing Application 137 The main() Function 154 EditArgs() 155 NetBIOS Add Name Processing Routines 155 Participate() 155 ServiceDatagramNcbs() 156 ProcessReceivedDatagram() 157 ServiceKeyboard() 157 SendKeyboardMsg() 158 ApplyKeystroke() 158

13 C File Transfer Applications 159 Application Overview 174

14 Medialess Workstations, RPL, and Redirectors 177 Clients and Servers 178 Data Layers 179 A Redirector Implementation 181 A Block Device Driver Implementation 182 The INT 13 BIOS Interface 182 A NetBIOS RPL Implementation—Or How Does PC DOS Get in There? 183

VII C Programmer's Guide to NetBIOS, IPX, and SPX

Part III • A Cyclic Redundancy Check (CRC) Treatise

15 CRC Fundamentals 191 The Need for CRC Checking 191 The XMODEM Checksum 192 CRC Mathematics 192 CRC Calculation 197 Prevalent CRC Polynomials 200

16 CRC-16 and CRC General Mechanics 203 CRC Hardware 205 Generalized CRC-16 Shifting 213 Table Look-Up Schemes 216 CRC Compatibility Caveats 222

17 CRC-CCITT and Minimum Look-Up Table Sizes 225 The Table Look-Up Approach 227

18 CRC-32—Token-Ring, PC Network, and EtherNet 235 Part IV - NetBIOS Technical Reference

19 Network Control Block 249 Neb Fields 249 Command Completion 258

20 NetBIOS Commands 261 The Commands 261 Special Value Summary 294 Complex Hang Up Scenario 295 Return Code Summary 296

VIII Table of Contents

21 IPX/SPX Overview 297 NetWare Background 297 IPX 297 SPX 299 Detecting the Presence of IPX and SPX 300 Novell NetWare Concepts 303 Why Do I Need To Know This? 308 TheECB 317 The IPX Packet Header 320 The SPXPacket Header 322 Conclusion 323

22 IPX Programming 325 Beware of Structure Alignment "Help" 325 Program Execution 326 Packet Send 327 AES Demonstration 328 Canceling an ECB 328 Receiving a Packet 329 Conclusion 329

23 SPX Programming 361 Program Execution 361 Sending Packets 362 Receiving Packets 364 Conclusion 364 Appendixes

A NetBI0S2.h Listing 405

B C Post Routine Listing 413

C Error Codes, Reasons, and Actions 417

IX C Programmer's Guide to NetBIOS, IPX, and SPX

D Neb Command and Field Relationship 433

E Send No-Ack and Chain Send No-Ack 437

F OS/2 Extended Edition and LAN Manager 441

G IPX-SPX.h Listing 447

H Novell NetWare Communication Programming Reference 453

Bibliography 475

Index 477