1.1 A Short Bio of NetBIOS
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
In those days spirits were |
It all started back in the frontier days of the PC when Microsoft was a lot smaller, IBM seemed a whole lot bigger, and Apple owned personal computer territory as far as the eye could see. Back then, you didn't need no dang standards. If you wanted to sell LANs, you just went out and branded yourself a protocol. Apple had AppleTalk, Digital had DECnet and, for their longhorn Mainframes, IBM had Systems Network Architecture (SNA). SNA was a mighty big horse for little PCs, so IBM hired on a company called Sytek and together they rustled up a product they called "PC Network". Not an inspiring name, but it was a simpler time. PC Network was a Local Area Network (LAN) system designed to support about 80 nodes at best, with no provision for routing. NetBIOS (Network Basic Input Output System) was the software interface to the PC Network hardware. It offered a set of commands that could control the hardware, establish and delete sessions, transfer data, etc. 1.1.1 NetBIOS and DOS: The Early YearsStarting with DOS version 3.1, Microsoft used the NetBIOS API to transport SMB file service messages. They created something called a redirector, and its job was to catch disk drive or port references (eg. "C:" or "LPT3:") and look them up in a table. If the device was not in the table, the call was passed along to DOS. If the device was in the table, then the call would be redirected. For example:
These commands are still available from within the DOS shells of contemporary Windows products. It is worth-while to fiddle with them a bit. From the DOS prompt you can type NET HELP for a summary of the NET command and its options1. 1.2 Speaking NetBIOSThe hardware part of IBM's PC Network is no longer in use and
the protocol that actually ran on the wire is all but forgotten, yet
the NetBIOS API remains. Vast untold hoards of programs--including
DOS itself--were written to use NetBIOS. Like COBOL, it may never
die.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Genuine Imitation |
Many vendors, eager for a piece of the Microsoft desktop pie, figured out how to implement the NetBIOS API on top of other protocols. There is NetBIOS over DECnet, NetBIOS over NetWare, NetBIOS over mashed potatoes and gravy with creamed corn, NetBIOS over SNA, NetBIOS over TCP/IP, and more. Of these, the most popular, tasty, and important is NetBIOS over TCP/IP, and that's what this chapter is really all about. NetBIOS over TCP/IP is sometimes called NetBT or NBT. Folks from IBM--for reasons unfathomable--sometimes call it TCPBEUI. NBT is the simplest and most common name, so we'll stick with that. On the 7-layer OSI reference model, NetBIOS is a session-layer (layer 5) API. Under DOS and its offspring, applications talk to NetBIOS by filling in a record structure known as a Network Control Block (NCB) and signaling an interrupt. The NCBs are used to pass commands and messages between applications and the underlying protocol stack. Fortunately, the NetBIOS API is specific to DOS and its kin. Unix and other systems do not need to implement the NetBIOS API, as there is no legacy of programs that use it. Instead, these systems participate in NBT networks by directly handling the TCP and UDP packets described in two Internet Engineering Task Force (IETF) Request for Comments documents: RFC 1001 and RFC 1002 (known collectively as Internet Standard #19). These RFCs describe a set of services which work together to create virtual NetBIOS LANs over IP. 1.2.1 Emulating "NetBIOS LANs"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...there is often confusion in |
At this point, we hit an interesting twist in the terminology. NetBIOS is a driver that presents an API; it is neither a protocol nor a topology. The API does, however, make a number of assumptions about the workings of the underlying network, and it presents some quirky restrictions. The terms "NetBIOS Network" and "NetBIOS LAN" are commonly used to identify the network architecture that is, essentially, defined by the NetBIOS API. RFC 1001 and 1002 list three basic services which must be supported in order to implement NetBIOS LAN emulation. These are:
The Name Service is used to map NetBIOS names (addresses) to IP addresses in the underlying IP network. The Datagram Service provides for the delivery of NetBIOS datagrams via UDP, and the Session Service is used to establish and maintain point-to-point, connection-oriented NetBIOS sessions over TCP. 1.2.1.1 The NetBIOS Name Service
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The NetBIOS name service is the collection of procedures through which nodes acquire, defend, and locate the holders of NetBIOS names. -- RFC 1001, Section 15 |
The NetBIOS LAN architecture is very simple. No routers, no switches--just a bunch of nodes connected to a (virtual) wire. There is no need for separate hardware addresses, network addresses, or even port numbers as there is in IP. Instead, the communications endpoints are identified by 16-byte strings known as "NetBIOS Names". NetBIOS addressing is dynamic. Applications may add names as needed, and remove those names when they are finished. Each node on the LAN will also have a default name, known as the Machine Name or the Workstation Service Name, which is typically added when NetBIOS starts. The process of adding a name is called registration. There are two kinds of names that can be registered: unique and group. Group names may be shared by multiple clients, thus providing a mechanism for multicast. In contrast, unique names may only be used by one client per LAN. Keep in mind, though, that these are virtual LANs which may actually be spread out across different subnets in a routed IP internetwork. The Name Service is supposed to keep track of all of the NetBIOS
names in use within the virtual LAN, and ensure that messages sent to
a given NetBIOS name are directed to the correct underlying IP
address. It does this in two ways:
These are the two basic modes of NetBIOS Name Resolution over NBT. There are, of course, others. The RFCs describe 'M mode' (mixed mode), which combines P and B mode characteristics. 'H mode' (hybrid mode) was introduced later. It is similar to M mode except for the order in which B and P mode behavior is applied. The Name Service runs on UDP port 137. According to the RFCs the use of TCP port 137 can be negotiated for some queries, though few (if any) implementations actually support this. 1.2.1.2 The NetBIOS Datagram Service
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Upon receipt, the duct tape is removed and the paper copy of the datagram is optically scanned into a[n] electronically transmittable form. -- RFC 1149 |
In the IP world, TCP provides connection-oriented sessions in which packets are acknowledged, put in order, and retransmitted if lost. This creates the illusion of a continuous, sequential data stream from one end to the other. In contrast, UDP datagrams are simply sent. Thus, UDP requires less overhead, but it is less reliable than TCP. NetBIOS also provides connection-oriented (session) and connectionless (datagram) communications. Naturally, NBT maps NetBIOS sessions to TCP and NetBIOS datagrams to UDP. The Datagram Distribution Service is the NBT service that handles NetBIOS datagram transport. It runs on UDP port 138, and can handle unicast (also known as "specific"), multicast (group), and broadcast NetBIOS datagrams.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
In theory, theory and practice are the same. In practice, they're not. -- Unknown |
The Datagram Service is probably the second-least well understood aspect of NBT, most likely because correct implementation isn't critical to filesharing. Many implementations get it wrong, and there is much debate over the value of getting it right. 1.2.1.3 The NetBIOS Session ServiceThe Session Service is the traditional transport for SMB, and this is our primary reason for caring about NetBIOS at all. The Session Service runs on TCP port 1393. There is no particular mechanism for multicast or broadcast because each session is, by definition, a one-to-one connection. The RFCs do, however, briefly discuss what might happen if a session setup request were sent to a group name (see RFC 1001, Section 16.1.1.2). We will get to the details of session creation, use, and closure when we discuss Session Service implementation.
1.2.2 Scope: The Final FrontierThis is a good point at which to get up, stretch, make a nice hot cup of tea for yourself, take a soothing bath, play with your cat, go for a long walk in the park, take dance lessons, volunteer in your community, sort and organize your old photographs, or join a United Nations Peace Keeping Force. The Datagram Service was previously described as 'the second-least well understood aspect of NBT'. Guess which bit wins first prize. Scope is an oddity of NBT, not because it was a bad idea (though perhaps it was) but because few have ever bothered to really understand it. In practice this feature is rarely used, in part because it is rarely implemented to its full potential. In the RFCs, the term scope is used as a name for:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Proof by Scope: The proof of this theorem is beyond the scope of this book. -- Jonathan Young, PhD. |
...but the last of these is beyond the scope of this discussion, so let's take a closer look at the first two. Scope is explained in RFC 1001, Section 9, which starts off by saying: A "NetBIOS Scope" is the population of computers across which a registered NetBIOS name is known. NetBIOS broadcast and multicast datagram operations must reach the entire extent of the NetBIOS scope. This basically means all nodes connected to the virtual LAN. So, for B nodes the NetBIOS scope consists of all nodes within the local IP broadcast domain that are running NBT. For P nodes, the NetBIOS scope includes all nodes across the routed internetwork that run NBT and share the same NBNS. For an M or H node, the scope is the union of the local broadcast and the NBNS scopes. This is all quite straight-forward when all NBT nodes are of the same node type, but strange things can happen when you mix modes, particularly in a routed environment.
We now have a good handle on our first definition of scope: "the set of NetBIOS nodes that participate in a virtual LAN". What about the second: "an identifier used to distinguish one virtual LAN from another"? (This is a good point at which to get up, stretch, make a nice hot cup of tea for yourself...) Every scope has a name, called the Scope Identifier (Scope ID). The most common Scope ID is the empty string: "". Indeed, this is the default in Windows, Samba, jCIFS, and every other system encountered so far. The only problem with this name is that it becomes too easy to forget that the Scope ID exists. We have already seen that distinct NetBIOS vLANs can be created
by using the behavior of B, P, M, and H nodes to create separate
scopes. For example, multiple scopes are defined when multiple
independent NBNS's provide service for P nodes. B nodes on separate
IP LANs are also in separate scopes, and so on. The Scope ID provides
another, more refined mechanism for separating scopes.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I can listen, but I can't hear. -- Turn a Deaf Ear Rab Noakes |
Think of an IP LAN with a bunch of B nodes. Some of the B nodes have Scope ID DOG, and others have Scope ID CAT. Only members of scope DOG will listen to messages sent with that ID; the cats will ignore messages sent to the dogs. So, even though all of the B nodes are on the same wire, we have two separate scopes. The same applies to P and M nodes. The Scope IDs identify, and separate, virtual NetBIOS LANs. Note, though, that an NBNS will handle requests from any node regardless of scope. A single NBNS server can, therefore, support multiple scopes. According to RFC 1001/1002, a node may belong to more than one scope. In practice, however, it is much easier to choose a single scope and stick with it. This is particularly true for DOS and Windows systems because NetBIOS itself has no concept of scope. The Scope ID is a feature of NBT, and programs that call the NetBIOS API have no way of telling NBT which scope to use. The RFCs suggest that extensions might be added to NetBIOS to manage scope, but using those extensions would require changes to applications. Further, other NetBIOS transports would not support the extensions which would result in compatibility problems.
1.2.3 Thus Endeth the OverviewNow that you have a clear and precise understanding of the workings of NetBIOS over TCP, go read RFC 1001. That ought to muddy the waters a bit. Clear or not, the next step is to write some code and see what works--and what doesn't. Actual implementation will provide a lot of opportunity to discuss details, bugs, and common errors. 1.3 The Basics of NBT Implementation
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This is where the rubber meets the road. -- Unknown |
Ready? We have identified the three key parts of NBT: the Name Service, the Datagram Service, and the Session Service. This is enough to get us started. We will begin by coding up a simple Name Service Query, just to see what kind of trouble that gets us into. Before we start, though, it's probably a good idea to check our tools.
Ready! In this section, we will implement a broadcast NAME QUERY REQUEST. That is, B mode name resolution. This will allow us to introduce some of the basic concepts and establish a frame of reference. In other words, we have to start somewhere and this seems to be as good a place as any. 1.3.1 You Got the Name, Look Up the Number
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Shirley Shirley Bo Birley Banana Fanna Fo Firley -- The Name Game, Shirley Ellis |
The structure of an NBT name query is similar to that of a Domain Name System query. As RFC 1001, section 11.1.1, explains: The NBNS design attempts to align itself with the Domain Name System in a number of ways. The goal of this attempted alignment was an eventual merger between the NBNS and the DNS system. The NBT authors even predicted dynamic DNS update. With Windows 2000, Microsoft did move CIFS naming services to Dynamic DNS, though the mechanism is not quite what was envisioned by the authors of the NBT RFCs. 1.3.1.1 Encoding NetBIOS NamesRFC 1001 & 1002 reference RFC 883 when discussing domain name syntax rules. RFC 883 was later superseded by RFC 1035, but both give the same preferred4 syntax for domain names: <domain> ::= <subdomain> | " " <subdomain> ::= <label> | <subdomain> "." <label> <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ] <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str> <let-dig-hyp> ::= <let-dig> | "-" <let-dig> ::= <letter> | <digit> <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case <digit> ::= any one of the ten digits 0 through 9 This is the syntax that the NBT authors tried to match. Unfortunately, except for the 16-byte length restriction, there are few syntax rules for NetBIOS names. With a few notable exceptions just about any octet value may be used, so the NBT authors came up with a scheme to force NetBIOS names into compliance. Here's how it works:
This is called First Level Encoding, and is described in RFC 1001, Section 14.1. Using First Level Encoding, the name "Neko" would be converted as follows:
This results in the string:
EOGFGLGPCACACACACACACACACACACACA | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Coding style is very personal... -- Linus Torvalds |
...and here is our first bit of code: This function reads up to 16 characters from the input string
name and converts each to the encoded format, stuffing
the result into the target string dst. The space
character (0x20) always converts to the two-character value "CA" so,
if the source string is less than 16 bytes, we simply pad the target
string with CACA. Note that the target character array must
be at least 33 bytes long--one extra byte to account for the nul
terminator6.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Bedevere: Oooohoohohooo! Lancelot: No, no. 'Aaaauugggh', at the back of the throat. Aaauugh. -- Monty Python And The Holy Grail, Monty Python's Flying Circus |
1.3.1.2 Fully Qualified NBT NamesNow that we've managed to convert the NetBIOS name into a DNS-aligned form, it is time to combine it with the NBT Scope ID. The result will be a fully-qualified NBT address, which we will call the "NBT Name". To be pedantic, when the RFCs talk about First Level Encoding, this fully qualified form is what they really mean. As expected, the syntax of the Scope ID follows the DNS recommendations given in RFC 883 (and repeated in RFC 1035). That is, a Scope ID looks like a DNS name. So, if the Scope ID is cat.org, and the NetBIOS name is Neko, the resultant NBT name would be: EOGFGLGPCACACACACACACACACACACACA.CAT.ORG Imagine typing that into your web browser. This is why the RFC 1001/1002 scheme for merging the NBNS with the DNS never took hold. 1.3.1.3 Second Level EncodingNow that we have an NBT name in a nice familiar format, it is time to convert it into something else. DNS names (and, therefore, NBT names) are made up of labels separated by dots. Dividing the name above into its component labels gives us:
The Second Level Encoded NBT name is a concatenation of the lengths and the labels, as in: '\x20' + "EOGFGLGPCACACACACACACACACACACACA" + '\x03' + "CAT" + '\x03' + "ORG" + '\0' The empty label at the end is important. It is a label of zero
length, and it represents the root of the DNS (and NBT) namespace.
That means that the final nul byte is part of the encoded NBT
name, and not a mere terminator. In practice, you can manipulate
the encoded NBT name as if it were a nul-terminated string, but always
keep in mind that it is really a series of length-delimited strings7.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Any useful piece of code deserves to be rewritten at least once. -- Unknown |
Our second bit of code will convert a NetBIOS name and Scope ID into a Second Level Encoded string: Not the prettiest piece of code, but it does the job. We will run through the function quickly, just to familiarize you with the workings of this particular programmer's twisted little brain. If the code is fairly obvious to you, feel free to skip ahead to the next section. if( NULL == L1_Encode( &dst[1], name ) ) return( -1 ); dst[0] = 0x20; lenpos = 33; Call L1_Encode() to convert the NetBIOS name into its First Level Encoded form, then prefix the encoded name with a length byte. This gives us the first label of the encoded NBT name. Note that we check for a NULL return value. This is paranoia on the programmer's part since this version of L1_Encode() does not return NULL. (An improved version of L1_Encode() might return NULL if it detected an error.) The variable lenpos is set to the offset at which the next length byte will be written. The L1_Encode() function has already placed a nul byte at this location so, if the scope string is empty, the NBT name is already completely encoded. if( '\0' != *scope ) { do { : } while( '.' == *(scope++) ); dst[lenpos] = '\0'; } The processing of scope labels is contained within the do..while loop. If the scope is empty, then we can skip this loop entirely. Note that the root label is added to the end of the target string, dst, following the scope labels. for( i = 0, j = (lenpos + 1); ('.' != scope[i]) && ('\0' != scope[i]); i++, j++) dst[j] = scope[i]; Run through the current label, copying it to the destination string. The variable i keeps track of the length of the label. A dot or a nul will mark the end of the current label. dst[lenpos] = (uchar)i; lenpos += i + 1; scope += i; Write the length byte for the current label, and then move on to the next by advancing lenpos. The variable scope is advanced by the length of the current label, which should leave it pointing to the dot or nul that terminated the label. It will be advanced one more byte within the while clause at the end of the loop. Hopefully that was a nice, short waste of time. As we progress, it will become necessary to move more quickly and provide less code and less analysis of the code. There is a lot of ground to cover. 1.3.1.4 Name Service Packet HeadersOnce again, our attention is drawn to the ancient lore of RFC 883, which was written about four years ahead of RFC 1001/1002 and was eventually replaced by RFC 1035. The comings and goings of the RFCs are a study unto themselves. NBT Name Service packets are an intentional rip-off of DNS Messages. New flag field values, operation codes, and return codes were added but the design was in keeping with the goal of eventually merging NBNS services into the DNS. This, conceptually, is what a Name Service packet header looks like:
...and here is a description of the fields:
So, for a broadcast NAME QUERY REQUEST, our header will look like this:
To make it easier to write the code for the above query, we will hand-convert the header into a string of bytes. We could do this in code (in fact, that will be necessary for a real implementation), but dealing with such details at this point would be an unnecessary tangent. So... unsigned char header[] = { 0x07, 0xAC, /* 1964 == 0x07AC. */ 0x01, 0x10, /* 0 0000 0010001 0000 */ 0x00, 0x01, /* One name query. */ 0x00, 0x00, /* Zero answers. */ 0x00, 0x00, /* Zero authorities. */ 0x00, 0x00 /* Zero additional. */ }; 1.3.1.5 The Query EntryThe query entries follow the header. A query entry consists of a Level 2 Encoded NBT name followed by two additional fields: the QUESTION_TYPE and QUESTION_CLASS. Once again, this is taken directly from the DNS query packet. Under NBT, the QUESTION_TYPE field is limited to two possible values, representing the two types of query that are defined in the RFCs. These are:
Only one QUESTION_CLASS is defined for NBT, and that is the Internet Class: 0x0001. So, our completed NAME QUERY REQUEST packet will consist of:
1.3.1.6 Some Trouble Ahead
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
He felt that if once he went beyond the crown of the pass and took one step veritably down into the land of Mordor, that step would be irrevocable. He could never come back. -- J.R.R. Tolkein The Lord of the Rings |
It would seem that it should now be easy to send a broadcast name query. Just put the pieces together and send them to UDP port 137 at the broadcast address. Yes that should be easy...except that we are now crossing the line between theory and practice, and that means trouble. Be brave.
1.3.1.7 Finally! A Simple Broadcast Name Query
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...almost, but not quite, entirely unlike tea... -- The Hitchhikers Guide To The Galaxy, Douglas Adams |
This next bit of code is full of shortcuts. The packet header is hard-coded, as are the QUESTION_TYPE and QUESTION_CLASS. No syntax checking is done on the scope string. Worst of all, the program sends the query but does not bother to listen for a reply. For that, we will use a sniffer. Tools such as the nmblookup utility that comes with Samba, or Microsoft's nbtstat program, could also be used to send a name query. The goal, however, is to implement these tools on our own, and the next bit of code gives us a start10. The updated L1_Encode() function takes two new parameters: pad and sfx. These allow us to specify the padding character and the suffix, respectively. The L2_Encode() function also takes these additional parameters, so that it can pass them along to L1_Encode(), and both functions make use of toupper() to ensure that the NetBIOS name and Scope ID are in upper case. The function Send_Nbtn_Bcast() does the job of transmitting a block of data via UDP. The destination is port UDP/137 at the universal broadcast address. The program mainline simply strings together the various pieces of the NBT query, taking the NetBIOS name and Scope ID from the command line. Compile the code and give the executable the name namequery. The program takes one or two arguments. The first is the NetBIOS name, and the second is the Scope ID (the Scope ID is optional). For example, on a Unix system the command line (including the $ prompt) might be: $ namequery neko cat.org Start your sniffer with the filter set to capture only packets sent to/from UDP port 137. If you are using TCPDump or Ethereal the filter string is: udp port 137. Depending on your OS, you may need to have Root or Administrator privilege in order to run the sniffer. Run namequery with the input shown above, and then stop the capture. You should get something like this: + Frame 1 (100 on wire, 100 captured) + Ethernet II + Internet Protocol + User Datagram Protocol - NetBIOS Name Service Transaction ID: 0x07ac + Flags: 0x0110 (Name query) Questions: 1 Answer RRs: 0 Authority RRs: 0 Additional RRs: 0 - Queries + NEKO <00>.CAT.ORG: type NB, class inet This example is copied from Ethereal output. Compare the parsed output provided by the sniffer against the hard-coded information in the program. They should match up. Next, try a query using a name on your own network and take a look at the response. If you use the name of a Workgroup or NT Domain, you may get responses from several systems. Another way to get multiple replies is to use a wildcard query. If all NBT nodes on your local LAN use the same Scope ID, and if they are not P nodes, then they will all respond to the wildcard name. To try this, you must first change the call to L2_Encode() within main() so that it passes '\0' as the padding character. That is: total_len += L2_Encode( &bufr[total_len], name, '\0', '\0', scope ); ...then recompile and give the asterisk as the NetBIOS name: $ namequery "*" Try using other tools such as nbtstat in Windows or Samba's nmblookup to generate queries, and spend a bit of time looking at the results of these captures. You can also simply let the sniffer run for a while. If your network is active you will see all sorts of NetBIOS packets fly by (particularly if you are on a shared rather than a switched LAN). 1.3.2 InterludeWe now have method, madness, and a vague sense of the direction. We are ready to head out on the open code. Let us first take a moment to meditate on what we have covered so far. Start by considering this mental image... Imagine a cold, rainy autumn day. Still thinking of summer, you have forgotten to wear a jacket. The chill of the rain runs through your entire body as you hurry along the street. You try to keep your neck dry by pulling up your thin sweater and hunching your shoulders. Down the road you spot a café. It looks warm and bright inside. You quicken your pace, then dash through the door as the drizzly rain becomes more enthusiastic and thunder rumbles in the distance. The shop is cozy, but not too small. There are potted plants scattered about. Light jazz plays over well-hidden speakers. The clientele are trendy urban business types having quiet, serious discussions in pairs at small tables. Paintings by a local artist hang on the walls. You step to the counter. A young woman with a dozen earrings and short-cut hair smiles and asks you what you would like. A nice, hot cup of tea. She reaches down behind the counter and grabs a large white mug. Then she opens a box and pulls out a tea bag that is at least three years old, drops it into the mug, and pours in hot water from the sink. "Three dollars" she says, still smiling. If you are a coffee drinker, you probably don't understand. Replace the words "opens a box and pulls out a tea bag" with "opens a jar and scoops out one spoonful of freeze-dried instant" and you will get the point. The point is that details matter. Certainly, an old tea bag in warm water will make a cup of tea...but not one worth drinking11. Just so, our examples provide some working code but are far from satisfying. If we are going to write something truly enjoyable we need to dig into the details. Let's get to it. 1.4 The Name Service in Detail
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This is gonna hurt me more than it does you. -- common lie |
Think of the Name Service as a database system. The data may be stored in an NBNS server (P mode), distributed across all of the participating nodes in an IP subnet (B mode), or a combination of the two (M or H mode). Name Service messages are the transactions that maintain and utilize the NBT name-to-IP address mapping database. These transactions fall into three basic categories:
These three represent the lifecycle of an NBT name.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Hello, I love you Won't you tell me your name? -- Hello, I Love You The Doors |
The RFCs also specify support for the NetBIOS API Adapter Status Query function. Implementation of the Adapter Status Query is quite similar to that of the Name Query, so it gets lumped in with the Name Service. This is fairly reasonable, since the query packets are almost identical and the most important result of the status query is a list of names owned by the target node. 1.4.1 NBT Names: Once More With FeelingLet's review what we've learned so far:
1.4.1.1 Valid NetBIOS Name CharactersAny octet value can be encoded using the first-level mechanism. In theory, then, any eight-bit value can be part of a NetBIOS name. Keep this in mind and be prepared. There are some very strange names in use in the wild. In practice, implementations do place some restrictions on the characters that may be used in NetBIOS names. These restrictions are implemented at the application layer, and should be considered artificial. Under Windows 9x, for example, the "Network Identity" control panel allows only the following characters in a machine name:
Yet the same Windows 9x system may also register the special-purpose name "\x01\x02__MSBROWSE__\x02\x01", which contains control characters as shown. Note that the set of alpha-numeric characters may include extended characters, such as 'Å' and 'Ü'. Unfortunately, these are often represented by different octet values under different operating systems, or even under different configurations of the same operating system. Some examples:
As you can see, the mapping between character sets can be a bit of a challenge--particularly since there is no standard character set for use in NBT and no mechanism for negotiating a common character set12. One more thing to consider when dealing with NetBIOS name characters: Windows NT will generate a warning--and W2K an error--if the Machine Name is not also a valid DNS name. You may need to do some testing to determine which characters Windows considers valid DNS label characters. 1.4.1.2 NetBIOS Names Within ScopeUnder NBT, NetBIOS names exist within a scope. The scope is the set of all machines which can "see" the name. For B nodes, the scope is limited to the IP broadcast domain. For P nodes, the scope is limited to the set of nodes that share the same NBNS. For M and H nodes, the scope is the union of the broadcast domain and the shared NBNS. Scope can be further refined using a Scope ID. The Scope ID effectively sub-divides a virtual NetBIOS LAN into separate, named vLANs. Unfortunately, few (if any) implementations actually support multiple Scope IDs so this feature is of limited practical use. The syntax of the Scope ID matches the best-practices
recommendations for DNS domain names. (Some Windows flavors allow
almost any character value in a Scope ID string. Sigh.) Scope IDs
should be converted to upper case before use on the wire.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The best way to eliminate the problem is to remove Scopes completely. -- John Terpstra, Samba Team, in a message to the Samba-Technical mailing list. |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1.4.1.3 Encoding and Decoding NBT NamesFirst Level Encoding converts a 16-byte NetBIOS name into a 32-byte encoded name, and then combines it with the Scope ID. For example: "EOGFGLGPCACACACACACACACACACACAAA.CAT.ORG" We have chosen to call this format the NBT Name. Second Level Encoding is applied to the NBT name to create the on-the-wire format, which we will refer to as the Encoded NBT Name: "\x20EOGFGLGPCACACACACACACACACACACAAA\x03CAT\x03ORG\0" As previously described, the maximum length of a label in an NBT name is 63 bytes. This is because the label length field is divided into two sub-fields, the first of which is a two-bit flag field with four possible values:
With both bits clear (zero) the next 6 bits are the label LENGTH. The LENGTH field is an unsigned integer with a value in the range 0..63.
If both flag bits are set, however, then the next fourteen bits are a "Label String Pointer"; the offset at which the real label can be found.
Label string pointers are used to reduce the size of Name Service messages that might otherwise contain two copies of the same NBT name. For example, a NAME REGISTRATION REQUEST message includes both a QUESTION_RECORD and an ADDITIONAL_RECORD, each of which would otherwise contain the same NBT name. Instead of duplicating the name, however, the ADDITIONAL_RECORD.RR_NAME field contains a label string pointer to the QUESTION_RECORD.QUESTION_NAME field. Label string pointers are a prime example of the NBT theory/practice dichotomy, and another throw-back to the DNS system. As it turns out, the only label string pointer value ever used in NBT is 0xC00C. The reason for this is quite simple. The NBT header is a fixed size (12 bytes), and is always followed by a block that starts with an encoded NBT Name. Thus, the offset of the first name in the packet is always 12 (0x0C). Any further name field in the packet will point back to the first. So, the rule of thumb is that the encoded NBT name will always be found at byte offset 0x000C. As a short-cut, some implementations work directly with the encoded name and only bother to decode the name when interacting with a user. Decoding, however, is fairly straight forward: The L2_Decode() function copies the encoded NBT name to the destination buffer, skipping the first label length byte and replacing internal label length bytes with the dot character. That is, given the input string: "\x20EOGFGLGPCACACACACACACACACACACAAA\x03CAT\x03ORG\0" it will produce the string: "EOGFGLGPCACACACACACACACACACACAAA.CAT.ORG" The L1_Decode() function decodes the First Level Encoded NetBIOS name, and hands back the suffix byte as its return value. 1.4.2 NBT Name Service PacketsRFC 1002 lists 17 different Name Service packet types, constructed from three basic building blocks:
These pieces are described in more detail below. 1.4.2.1 Name Service HeadersThe header is an array of six 16-bit values, as follows:
Managing Name Service headers is fairly straight-forward. With the exception of the FLAGS field, all of the fields are simple unsigned integers. The entire thing can be represented in memory as an array of unsigned short int, or whatever is appropriate in your programming language of choice. The FLAGS field is further broken down thus:
Handling the bits in the FLAGS field is fairly trivial for
any seasoned programmer. One simple solution is to shift the values
given in RFC 1002, section
4.2.1.1 into their absolute positions. For example, an OPCODE
value of 0x7 (WACK) would be left shifted 11 bits to align it
properly in the OPCODE subfield:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
It's just a jump to the left -- Time Warp Richard O'Brien |
(0x0007 << 11) = 0x3800 = 0011100000000000(bin) ...which puts it where it's supposed to be:
Listing 1.5 presents nbt_nsHeader.h, a header file that will be referenced as we move forward. It provides a set of re-aligned FLAGS subfield values plus a few extra constants. These values will be covered below, when we explain how to use each of the Name Service message types. The NAME_TRN_ID field is the transaction ID, which should probably be handled by the bit of code that sends and receives the NBT messages. Many implementations use a simple counter to generate new transaction IDs (Samba uses a random number generator), but these should always be checked to ensure that they are not, by chance, the same as the transaction ID of a conversation initiated by some other node. Better yet, the originating node's IP address should be used as an additional key for segregating transactions. The four COUNT fields indicate the number of Question and Resource Records which follow. In theory, each of these fields can contain a value in the range 0..65535. In practice, however, the count fields will contain either 0 or 1 as shown in the record layouts in RFC 1002, section 4.2. It appears as though some implementations either ignore these fields or read them as simple booleans. One final consideration is the byte order of NBT messages. True to
its DNS roots, NBT uses network byte order (big-endian). Some
microprocessors--including Alpha, MIPS, and Intel i386 family--use or
can use little-endian byte order13.
If your target system is little-endian, or if you want your code to be
portable, you will need to ensure that your integers are properly
converted to and from network byte order. Many systems provide the
htonl(), htons(), ntohl(), and
ntohs() functions for exactly this purpose.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
My brain hurts! -- Attributed to Mr. T. F. Gumby Gumby Brain Specialist Monty Python's Flying Circus |
This next bit of code is nbt_nsHeader.c. It shows how to create and parse NBT Name Service headers. As with all of the code presented in this book, it is designed to be illustrative, not efficient. (We know you can do better.) 1.4.2.2 Name Service Question RecordsThe question record is also simple. It consists of an encoded NBT name (in the QUESTION_NAME field) followed by two unsigned 16-bit integer fields: the QUESTION_TYPE and QUESTION_CLASS. The length of an encoded NBT name is at least 34 bytes, but it will be longer if a Scope ID is used, so the QUESTION_NAME field has no fixed length. There is also no padding done to align the integer fields. The QUESTION_TYPE and QUESTION_CLASS follow immediately after the QUESTION_NAME.
There are only two valid values for the QUESTION_TYPE field. These are:
The QUESTION_CLASS field always has a value of:
Go back and take a look at the broadcast name query example presented earlier. In that example, we hard-coded both the NBT Name Service header and the tail-end of the question record. Now that you have a clearer understanding of the fields involved, you should be able to design much more flexible code. Here's a start: 1.4.2.3 Name Service Resource RecordsFor convenience, we will break the Resource Record into three sub-parts:
The Name section has the same structure as a Query Entry record, except that the RR_NAME field may contain a 16-bit label string pointer instead of a complete NBT name.
The RR_TYPE field is used to indicate the type of the resource record, which has an effect on the structure of the resource data section. The available values for this field are:
The values marked "not used in practice" are described in the RFCs, and indicated as valid values, but are never really used in modern implementations. The value of RR_TYPE will be NB except in a NODE STATUS REPLY, in which case NBSTAT is used. As with the question record, the RR_CLASS field always has a value of:
The TTL field follows the name section. It indicates the "Time To Live" value associated with a resource record. Each NBT name-to-IP address mapping in the NBNS database has a TTL value. This allows records to "fade out" if they are not renewed or properly released. The TTL field is an unsigned long integer, measured in seconds. A value of zero indicates infinite TTL.
The last sub-part of the resource record is the resource data section, which is made up of two fields:
The RDLENGTH field is an unsigned 16-bit integer value indicating the length, in bytes, of the RDATA field. The structure of the contents of the RDATA field will vary from message type to message type. The Resource Record structure, as described in section 4.2.1.3 of RFC 1002, looks just like this:
It is always good to have some code to play with. This next set of functions can be used to manipulate Resource Records. 1.4.3 Conversations with the Name ServiceWe will now introduce a simple syntax for describing how to fill network packets. This syntax is neither standard nor rigorous, just something the author whipped up to help explain what goes into a message. If it looks like someone else's syntax (one which perhaps took long hours of study, concentration, and thought to develop) then apologies are probably in order.
A broadcast name query, described using our little syntax, would look like this: NAME QUERY REQUEST (Broadcast) { HEADER { NAME_TRN_ID = <Set when packet is transmitted> FLAGS { OPCODE = 0x0 RD = TRUE B = TRUE } QDCOUNT = 1 } QUESTION_RECORD { QUESTION_NAME = <Encoded NBT Name> QUESTION_TYPE = NB (0x0020) QUESTION_CLASS = IN (0x0001) } } Basically, the rules are these:
It's not a particularly formal syntax, but it will serve the purpose. 1.4.3.1 Name RegistrationNodes send NAME REGISTRATION REQUEST messages when they wish to claim ownership of a name. The messages may be broadcast on the local LAN (B mode), or sent directly to an NBNS (P mode). (M and H mode are combinations of B and P mode with their own special quirks. We will get to those further on.) A NAME REGISTRATION REQUEST message looks like this: NAME REGISTRATION REQUEST { HEADER { NAME_TRN_ID = <Set when packet is transmitted> FLAGS { OPCODE = 0x5 (Registration) RD = TRUE (1) B = <TRUE for broadcast registration, else FALSE> } QDCOUNT = 1 ARCOUNT = 1 } QUESTION_RECORD { QUESTION_NAME = <Encoded NBT name to be registered> QUESTION_TYPE = NB (0x0020) QUESTION_CLASS = IN (0x0001) } ADDITIONAL_RECORD { RR_NAME = 0xC00C (Label String Pointer to QUESTION_NAME) RR_TYPE = NB (0x0020) RR_CLASS = IN (0x0001) TTL = <Zero for broadcast, about three days for unicast> RDLENGTH = 6 RDATA { NB_FLAGS { G = <TRUE for a group name, FALSE for a unique name> ONT = <Owner type> } NB_ADDRESS = <Requesting node's IP address> } } } The NAME REGISTRATION REQUEST includes both a QUESTION_RECORD and an ADDITIONAL_RECORD. In a sense, it is two messages in one. It says "Does anyone own this name?" and "I want to own this name!", both in the same packet. The NAME REGISTRATION REQUEST gives us our first look at a Label String Pointer in its native habitat. In the packet above the QUESTION_NAME and the RR_NAME are the same name, so the latter field contains a pointer back to the former. The size of the header is constant; if there is a QUESTION_NAME in a packet it will always be found at offset 0x000C (12). The field value is 0xC00C because (as is always the case with label string pointers) the first two bits are set in order to indicate that the remainder is a pointer rather than a 6-bit label length. So, Label String Pointers in NBT messages always have the value 0xC00C. The TTL field in the ADDITIONAL_RECORD provides a Time-To-Live value, in seconds, for the name. In B mode, the TTL value is not significant and is generally set to zero. In P mode, the TTL is used by the NBNS to determine when to purge old entries from the database, and is typically set to something on the order of three days in the NAME REGISTRATION REQUEST. The NBNS may override the client's request and reply with a different TTL value, which the client must accept. The ADDITIONAL_RECORD.RDATA field is 6 bytes long (as shown in ADDITIONAL_RECORD.RDLENGTH) and contains two subfields. The first is the NB_FLAGS field, which provides information about the name and its owner. It looks something like this:
The NB_FLAGS.G bit indicates whether the name is a group name or a unique name, and NB_FLAGS.ONT identifies the owner node type. ONT is a two-bit field with the following possible values:
The ADDITIONAL_RECORD.RDATA.NB_ADDRESS holds the 4-byte IPV4 address that will be mapped to the name. This should, of course, match the address of the node registering the name. Take a good look at the structure of the RDATA subrecord in the NAME REGISTRATION REQUEST. This is the most common RDATA format, which gives us an excuse for writing a little more code... 1.4.3.1.1 Broadcast Name RegistrationYou've seen the basic form of NAME REGISTRATION REQUEST packet. When sending a broadcast registration, the following rules apply.
A node sending a broadcast NAME REGISTRATION REQUEST (the requester) may receive a unicast NEGATIVE NAME REGISTRATION RESPONSE from another node that already claims ownership of the name (the owner). That is the only valid message in response to a broadcast registration. NAME REGISTRATION RESPONSE (Negative) { HEADER { NAME_TRN_ID = <Must match REQUEST transaction ID> FLAGS { R = TRUE (1; This is a response packet) OPCODE = 0x5 (Registration) AA = TRUE (1) RD = TRUE (1) RA = TRUE (1) RCODE = ACT_ERR (0x6) B = FALSE (0; Message is unicast back to requester) } ANCOUNT = 1 } ANSWER_RECORD { RR_NAME = <The Encoded NBT Name> RR_TYPE = NB (0x0020) RR_CLASS = IN (0x0001) TTL = 0 (TTL has no meaning in this context) RDLENGTH = 6 RDATA { NB_FLAGS { G = <TRUE for a group name, FALSE for a unique name> ONT = <Owner type> } NB_ADDRESS = <Owner's IP address> } } } When a requester receives a NEGATIVE NAME REGISTRATION RESPONSE, it is obliged to give up. Registration has failed because another node has prior--and conflicting--claim to the name. That is, the name already has an owner. The RCODE field of the response will be ACT_ERR (0x6), indicating that the name is in use. The RDATA field should contain the real owner's name information:
Recall that the NAME REGISTRATION REQUEST contains a name query, so the ANSWER_RECORD in the reply should be constructed as it would be in a POSITIVE NAME QUERY RESPONSE. It is wrong to simply parrot back the information in the request14. NEGATIVE NAME REGISTRATION RESPONSE messages are only sent if a unique name is involved. Owners of a group name will not complain if a requester tries to join the group. If, however, a requester tries to register a unique name that matches an already registered group name, the members of the group will send negative responses. In a broadcast environment, a single unique name registration request can generate a large number of negative replies. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I want it, I want it, I want it... You can't have it! -- Magic Bus The Who |
If there are no conflicts the requesting node will hear no complaints, in which case it must retry the request two more times...just to be sure. The RFCs specify a minimum timeout of 250 milliseconds between broadcast retries (Windows uses 750ms). After the third query has timed out, the requesting node should broadcast a NAME OVERWRITE DEMAND declaring itself the victor and owner of the name. The NAME OVERWRITE DEMAND message is identical to the NAME REGISTRATION REQUEST, except that the RD bit is clear (Recursion Desired is 0). This next program will allow you to play around with broadcast name registration. It uses functions and constants from previous listings to format a NAME REGISTRATION REQUEST and broadcast it on the local IP subnet, then it listens for and reports any replies it receives. The transaction ID in the NAME_TRN_ID field should be the
same for all three registration attempts, for the final NAME
OVERWRITE DEMAND, and for any negative response packets a remote
node may care to send. All of these are part of the same transaction.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...the correct expression is "up and died." -- from the errata for Applied Cryptography, 2nd. Ed., By Bruce Schneier |
1.4.3.1.2 Unicast (NBNS) Name RegistrationUnicast name registrations are subtly different from the broadcast variety.
The NBNS should respond with a NAME REGISTRATION RESPONSE, which will include one of the following RCODE values:
Note that the difference between a positive and negative NAME REGISTRATION RESPONSE is simply the RCODE value. If you get no response then it is correct to assume that the NBNS is "down". If the name cannot be registered then your node does not own it, and your application should recover as gracefully as possible. In P mode, handle a non-responsive NBNS as you would a NEGATIVE NAME REGISTRATION RESPONSE. (If the client is running in H or M mode, then it may--with caution--revert to B mode operation until the NBNS is available again.) There are two other packet types that you may receive when registering a name with an NBNS. These are WACK and END-NODE CHALLENGE NAME REGISTRATION RESPONSE. The WACK message tells the client to wait while the NBNS figures things out. This is typically done so that the NBNS has time to send queries to another node that has claimed ownership of the requested name. A WACK looks like this: WAIT FOR ACKNOWLEDGEMENT (WACK) RESPONSE { HEADER { NAME_TRN_ID = <Must match REQUEST transaction ID> FLAGS { R = TRUE (1; This is a response packet) OPCODE = 0x7 (WACK) AA = TRUE (1) } ANCOUNT = 1 } ANSWER_RECORD { RR_NAME = <The Encoded NBT Name from the request> RR_TYPE = NB (0x0020; note the typo in RFC 1002, 4.2.16) RR_CLASS = IN (0x0001) TTL = <Number of seconds to wait; 0 == Infinite> RDLENGTH = 2 RDATA = <Copy of the two-byte HEADER.FLAGS field of the original request> } } The key field in the WACK is the TTL field, which tells the client how long to wait for a response. This is used to extend the timeout period on the client, and give the NBNS a chance to do a reality check. Samba uses a TTL value of 60 seconds, which provides ample time to generate a proper reply. Unless it is shut down after sending the WACK message, Samba's NBNS service will always send a NAME REGISTRATION RESPONSE (positive or negative) well before the 60 seconds has elapsed. Microsoft's WINS takes a different approach, using a value of only 2 seconds. If the 2 seconds expire, however, the requesting client will simply send another NAME REGISTRATION REQUEST, and then another for a total of three tries. WINS should be able to respond within that total timeframe. WACK messages are sent by honest, hard-working servers that take good care of their clients. In contrast, a lazy and careless NBNS server will send an END-NODE CHALLENGE NAME REGISTRATION RESPONSE. This latter response tells the client that the requested name has a registered owner, but the NBNS is not going to bother to do the work to check that the owner is still up and running and using the name. Once again, the format of this message is so familiar that there is no need to list all of the fields. The END-NODE CHALLENGE NAME REGISTRATION RESPONSE packet is just a NAME REGISTRATION RESPONSE with:
The annoying thing about this packet is that the RCODE
value indicates success, making it look almost exactly like a
POSITIVE NAME REGISTRATION RESPONSE. The RA
bit must be checked to distinguish between the two message
types.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
You might as well ask the cat. -- Basil Fawlty (John Cleese), Fawlty Towers |
When a client receives an END-NODE CHALLENGE, its duty is to query the owner (the owner's IP address will be in the ANSWER_RECORD.RDATA.NB_ADDRESS field) to see if the owner still wants the name. If the owner does not respond, or if it replies with a NEGATIVE NAME QUERY RESPONSE, then the name is available and the requester may send a NAME UPDATE REQUEST to the NBNS. The NBNS will blindly trust the requester, change the entry, and reply with a POSITIVE NAME REGISTRATION RESPONSE. The NAME UPDATE REQUEST is the same as the unicast NAME REGISTRATION REQUEST except that the RD bit is clear (Recursion Desired is 0). There is nothing to stop a client from skipping the name query and sending the update message to the NBNS, effectively stealing the name. This is why the RFCs use the term non-secured when describing this mechanism.
Oh...one more thing. Remember the IMP_ERR return code? It is used to indicate that an NBNS which did not send an END-NODE CHALLENGE is annoyed at having received a NAME UPDATE REQUEST from a client. An NBNS server should never receive unsolicited NAME UPDATE REQUESTs from clients. 1.4.3.1.3 M and H Node Name RegistrationMixed mode (M mode) and Hybrid mode (H mode) are both speed hacks, which combine aspects of Broadcast (B) and Point-to-Point (P) modes to short-cut Name Service operations. M mode was designed in the days when local LAN traffic was likely to be faster than internetwork links, which were typically carried over leased lines or even dial-up connections, tin cans with string, or pigeon (see RFC 1149). Since local broadcasts were both faster and more reliable than traffic to a remote NBNS, M nodes attempt B mode behavior first and try P mode behavior second. When an M node registers a name, for example, it starts by sending a broadcast NAME REGISTRATION REQUEST. If it receives a negative response it tries no further (thus saving some time). If, however, it receives no complaints after three retries, it will attempt to register with the NBNS as a P node would. If and only if the P mode registration succeeds, the M mode will broadcast a NAME OVERWRITE DEMAND. If the unicast registration fails, the NAME OVERWRITE will not be sent and the node will not assume ownership of the name. Hybrid mode (H mode) was introduced (probably by Microsoft) after the RFCs were published. H mode assumes that internetwork links are fast and reliable, in which case it makes sense to try P mode behavior first and revert to B mode behavior only if the NBNS does not respond. Compared with M mode, H mode generates less broadcast traffic on local LANs. H mode is a little trickier than M mode. A node running in H mode will attempt a unicast name registration and, if the NBNS accepts the registration, the H node will assume ownership without generating any broadcast (B mode) traffic at all. If the NetBIOS vLAN is configured properly all of the nodes within the scope will also be registering with the NBNS, thus preventing accidental name conflicts. If the NBNS is down or unreachable, however, an H node will revert to B mode behavior and hope that no conflicts will arise when the NBNS comes back. 1.4.3.1.4 Registering Multi-Homed HostsA multi-homed host is a machine that has multiple network interfaces (physical or virtual), each with its own IP address assigned. RFC 1001 and 1002 do not discuss handling of multi-homed hosts. The annoying thing about multi-homed hosts in an NBT environment is that they try to register their NetBIOS names on each interface, which means multiple IP addresses per name. This is not a problem for group names because group names map to several IP addresses anyway--that's what NBT group names are all about. Unique names are a problem because, from the network's point of view, there is no difference between a multi-homed host and multiple machines. To an NBNS, or to B nodes on a local LAN, multiple registrations for the same name will look like a name conflict. There are three scenarios to consider when working with multi-homed hosts:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Proof by Assignment: The proof of this theorem is part of your homework. -- Jonathan Young, PhD. |
As you might expect, the handling of M and H mode multi-homed hosts is a fairly straight-forward combination of B and P mode behavior. M and H mode name registration for single-homed hosts has already been covered. 1.4.3.2 Name QueryEach NBT node keeps track of its own local name table, which holds the list of the NetBIOS names that the node thinks it owns. NBT nodes may also register their names with a NetBIOS nameserver. Both the local name table and the NBNS database can be used to answer queries. Name queries look like this: NAME QUERY REQUEST { HEADER { NAME_TRN_ID = <Set when packet is transmitted> FLAGS { OPCODE = 0x0 (Query) RD = <Typically TRUE (1); see discussion below> B = <TRUE for broadcast queries, else FALSE (0)> } QDCOUNT = 1 } QUESTION_RECORD { QUESTION_NAME = <Encoded NBT name to be queried> QUESTION_TYPE = NB (0x0020) QUESTION_CLASS = IN (0x0001) } } As you can see from the packet description, name queries are really very simple (just as the eye of a hurricane is calm). The only fiddly bits are the B and RD flags.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
One of the great things about books is sometimes there are some fantastic pictures. -- George W. Bush |
In summary: /* Pseudocode */ if( the B bit is TRUE ) { /* It's a broadcast query. */ if( the receiver is a B, M, or H node ) { entry = lookup name in local name table; if( entry was found ) send( POSITIVE NAME QUERY RESPONSE ); } } else { /* It's a unicast query. */ entry = lookup name in local name table; if( entry was not found & RD is TRUE & receiver is the NBNS ) { entry = lookup name in NBNS database; } if( entry was found ) send( POSITIVE NAME QUERY RESPONSE ); else send( NEGATIVE NAME QUERY RESPONSE ); } Got it? Good. Let's move on... As with other NBT Name Service requests, if there is no response to a Name Query within a reasonable timeout period the query is sent again. This happens twice for a maximum of two retries (that is, three query messages). Timeouts vary from system to system and depend upon the type of query being sent. Query timeouts should be matched to those used for name registration where possible.
Timeout values are a balance between reliability and user annoyance. Too short, and replies will be missed. Too long, and the user goes off to make another pot of tea. 1.4.3.2.1 Negative Query ResponseA negative response looks like this: NEGATIVE NAME QUERY RESPONSE { HEADER { NAME_TRN_ID = <Same as QUERY REQUEST> FLAGS { R = TRUE (1; This is a response packet) OPCODE = 0x0 (Query) AA = TRUE (1) RD = <Copy RD bit from QUERY REQUEST> RA = <TRUE if the reply is from the NBNS> B = FALSE (0) RCODE = <Error code> } ANCOUNT = 1 } ANSWER_RECORD { RR_NAME = <The Encoded NBT Name from the request> RR_TYPE = <NB (0x0020), or possibly NULL (0x000A)> RR_CLASS = IN (0x0001) TTL = 0 RDLENGTH = 0 } }
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
You are in a maze of twisty little passages, all alike. -- Dungeon R. M. Supnik, InfoCom |
RFC 1002 is inconsistent in its descriptions of the RD and RA bits as used in NAME QUERY RESPONSE messages. There is also a small issue regarding the RR_TYPE field. Let's clear things up:
The NEGATIVE NAME QUERY RESPONSE will include an RCODE value, indicating the reason for the negative reply. RFC 1002 lists several possible RCODE values, but at least two of them--IMP_ERR and RFS_ERR--are incorrect as they are never generated in response to a query. The valid values or a NEGATIVE NAME QUERY RESPONSE are:
1.4.3.2.2 Positive Query ResponseThe POSITIVE NAME QUERY RESPONSE is similar to the negative response, with the following exceptions:
POSITIVE NAME QUERY RESPONSE { HEADER { NAME_TRN_ID = <Same as QUERY REQUEST> FLAGS { R = TRUE (1; This is a response packet) OPCODE = 0x0 (Query) AA = TRUE (1) RD = <Copy RD bit from QUERY REQUEST> RA = <TRUE if the reply is from the NBNS> B = FALSE (0) RCODE = 0x0 } ANCOUNT = 1 } ANSWER_RECORD { RR_NAME = <The Encoded NBT Name from the request> RR_TYPE = NB (0x0020) RR_CLASS = IN (0x0001) TTL = <Time To Live> RDLENGTH = <6 × number of entries> RDATA { ADDR_ENTRY[] { NB_FLAGS { G = <TRUE for a group name, FALSE for a unique name> ONT = <Owner type> } NB_ADDRESS = <Owner's IP address> } } } } If the packet is sent by the NBNS, the TTL field will contain the number of seconds until the entry's Time-To-Live expires (the remaining TTL). End nodes responding to verification queries will typically use the default TTL value which, as we described earlier, is something around 3 days. 1.4.3.2.3 The Redirect Name Query ResponseThe RFCs provide a mechanism whereby one NBNS can redirect a client to another NBNS. That is, the NBNS can return a message saying "I don't know, ask someone else". No living examples of this mechanism have been seen in the wild. It is probably extinct. Fossil remains may be found in RFC 1001, section 15.1.5.3, and RFC 1002, section 4.2.15. 1.4.3.2.4 A Simple Name Query RevisitedRemember Listing 1.3? In that example we provided code for generating a simple broadcast name query. Listing 1.11, below, provides an updated version which is a bit more flexible. In particular, the BuildQuery() function takes several parameters, allowing you to customize the query you want to send. The program mainline, as given, sends only broadcast queries. It can, however, be easily hacked to create a more versitile command-line tool. This new version also listens for replies. The sweet and chewey center of a POSITIVE NAME QUERY RESPONSE is the RDATA section, which contains an array of address entries. In most cases there will be only one entry, but a group name or a multi-homed host name may have several associated IP addresses. The contents of the ADDR_ENTRY records should be fairly familiar by now, so we won't dwell on them. Here are some quick functions which can be used to display the IP addresses and NB_FLAGS of an ADDR_ENTRY array: 1.4.3.3 Name RefreshThe refresh has two purposes. The first is to remind the NBNS that the client exists, thus ensuring that the name entry in the NBNS database does not expire. The second is to rebuild the NBNS database in the event of an NBNS crash. NAME REFRESH REQUEST messages are not needed in B mode since each node keeps track of its own names. NAME REFRESH REQUEST { HEADER { NAME_TRN_ID = <Set when packet is transmitted> FLAGS { OPCODE = <0x8 or 0x9> (Refresh) RD = FALSE (0) B = FALSE (0) } QDCOUNT = 1 ARCOUNT = 1 } QUESTION_RECORD { QUESTION_NAME = <Encoded NBT name to be refreshed> QUESTION_TYPE = NB (0x0020) QUESTION_CLASS = IN (0x0001) } ADDITIONAL_RECORD { RR_NAME = 0xC00C (Label String Pointer to QUESTION_NAME) RR_TYPE = NB (0x0020) RR_CLASS = IN (0x0001) TTL = <Client's default TTL value (3 days)> RDLENGTH = 6 RDATA { NB_FLAGS { G = <TRUE for a group name, FALSE for a unique name> ONT = <Owner type> } NB_ADDRESS = <Requesting node's IP address> } } } This message is almost identical to the unicast NAME REGISTRATION REQUEST, with a few small exceptions. Note, in particular, the following:
From watching packets on the wire18, it seems that Windows systems use the following formula to determine how frequently a refresh message should be sent: Refresh_Time = minimum( 40 minutes, (TTL/2) ) Based on the above formula, and considering that the default TTL value used by most clients is about three days, Windows NBNS clients typically send NAME REFRESH REQUEST messages every 40 minutes. This is a fairly high frequency, and it suggests a general lack of faith in the stability of the NBNS19. The NBNS handles a NAME REFRESH REQUEST in exactly the same manner that it handles a NAME REGISTRATION REQUEST. There is little reason to distinguish between the two message types. Indeed, there is no multi-homed variant of the refresh message so multi-homed hosts perform the refresh operation by sending MULTI-HOMED NAME REGISTRATION REQUEST messages. 1.4.3.4 Name ReleaseBoth B and P nodes (and their hybrid offspring, the M and H nodes) send NAME RELEASE messages to announce that they are giving up ownership of a name. A NAME RELEASE sent in B mode is a NAME RELEASE DEMAND, as no response is expected. Any node receiving the release message will flush the released name from its local cache (if it has one20). In P mode, the release message sent by a node is a NAME RELEASE REQUEST, and it is always unicast to the NBNS. The message structure is the same in both cases: NAME RELEASE REQUEST or NAME RELEASE DEMAND { HEADER { NAME_TRN_ID = <Set when packet is transmitted> FLAGS { OPCODE = 0x6 (Release) B = <FALSE (0) for REQUEST, TRUE (1) for DEMAND> } QDCOUNT = 1 ARCOUNT = 1 } QUESTION_RECORD { QUESTION_NAME = <Encoded NBT name to be released> QUESTION_TYPE = NB (0x0020) QUESTION_CLASS = IN (0x0001) } ADDITIONAL_RECORD { RR_NAME = 0xC00C (Label String Pointer to QUESTION_NAME) RR_TYPE = NB (0x0020) RR_CLASS = IN (0x0001) TTL = 0 (zero) RDLENGTH = 6 RDATA { NB_FLAGS { G = <TRUE for a group name, FALSE for a unique name> ONT = <Owner type> } NB_ADDRESS = <Releasing node's IP address> } } } 1.4.3.4.1 Name Release ResponseThe NBNS will always respond to a NAME RELEASE REQUEST. The response packet looks like this: NAME RELEASE RESPONSE { HEADER { NAME_TRN_ID = <Must match REQUEST transaction ID> FLAGS { R = TRUE (1; This is a response packet) OPCODE = 0x6 (Release) AA = TRUE (1) RCODE = <See discussion> B = FALSE (0) } ANCOUNT = 1 } ANSWER_RECORD { RR_NAME = <The Released Name, encoded as usual> RR_TYPE = NB (0x0020) RR_CLASS = IN (0x0001) TTL = 0 (TTL has no meaning in this context) RDLENGTH = 6 RDATA = <Same as request packet> } } Possible values for RCODE are:
1.4.3.5 Node StatusThe Node Status Request operation goes by many names: "Node Status Query", "Adapter Status Query", "NBSTAT", etc. This NBT message is used to implement the old NetBIOS Adapter Status command, which was used to retrieve information from LAN Adapter cards (LANAs, in PC Network terms). NODE STATUS REQUEST { HEADER { NAME_TRN_ID = <Set when packet is transmitted> FLAGS { OPCODE = 0x0 (Query) B = FALSE (0) } QDCOUNT = 1 } QUESTION_RECORD { QUESTION_NAME = <Encoded NBT name to be queried> QUESTION_TYPE = NBSTAT (0x0021) QUESTION_CLASS = IN (0x0001) } } Note that these queries are sent from one end node to another. The NBNS is never involved. This is because the NBNS itself is not connected to an NBT virtual LAN Adapter. The NBNS is part of the infrastructure that creates the NetBIOS virtual LAN. Only the end nodes are actually members of the LAN. 1.4.3.5.1 Node Status ResponseThe response is not as simple as the query. The format of the reply depends upon the type of card and/or virtual adapter used to build the network. In the old days, different implementations of NetBIOS were built on top of different LANAs, or emulated on top of a variety of underlying transport protocols. Each implementation kept track of its own set of status information, so the reply to the Adapter Status command was vendor-specific. The RFC authors developed their own reply structure, probably based in part on existing samples. The NODE STATUS RESPONSE looks like this: NODE STATUS RESPONSE { HEADER { NAME_TRN_ID = <Same as request ID.> FLAGS { R = TRUE (1) OPCODE = 0x0 (Query) AA = TRUE (1) } ANCOUNT = 1 } ANSWER_RECORD { RR_NAME = <The queried name, copied from the request> RR_TYPE = NBSTAT (0x0021) RR_CLASS = IN (0x0001) TTL = 0 (TTL has no meaning in this context) RDLENGTH = <Total length of following fields> RDATA { NUM_NAMES = <Number of NODE_NAME[] entries> NODE_NAME[] { NETBIOS_NAME = <16-octet NetBIOS name, unencoded> NAME_FLAGS = <See discussion below> } STATISTICS = <See discussion below> } } } This packet will need some tearing apart. The RDATA.NUM_NAMES field is one octet in length. The RDATA.NODE_NAME array represents the responding node's local name table: the list of names the end node believes it owns. Each entry in the array contains a NETBIOS_NAME field and a NAME_FLAGS field. The NETBIOS_NAME field is 16 bytes in length. The 16-byte name includes the suffix byte and any required padding, and is not encoded. The wildcard name (an asterisk followed by 15 nul bytes) is never included in the name list, which contains only registered names. The list of NetBIOS names all exist within the same NBT scope. The Scope ID will have been sent as part of the original query, and will be stored as part of the RR_NAME field in the reply. Recall that the empty string, "", is a valid Scope ID. Along with each NETBIOS_NAME there is a NAME_FLAGS field, which provides name status information. It looks like this:
The above is the same as an NB_FLAGS field with four extra bits defined.
These flag values are displayed by Samba's nmblookup program. For example:
The above shows that all of the names are ACTIVE, as they should be. The name ZATHRAS<00>, however, has been disabled due to a name conflict. From the column of B's, it is apparent that Zathras is operating in B mode. Now let's take a look at the RDATA.STATISTICS field. This is where things really fall apart. Microsoft's STATISTICS blob is quite different from what is specified in the RFCs, and most likely for good reason. At the time the RFCs were published, Microsoft already had at least one NetBIOS implementation. Over time they built a few others, and they had software written to use those implementations. It probably made more sense to stick with familiar layouts than adopt the new one specified in the RFCs. Fortunately, the data in the STATISTICS record is not particularly interesting, and current systems often fill most of it with zeros anyway. Only the first six bytes are commonly used now. Windows systems will attempt to place an Ethernet MAC address into this space. Samba leaves it zero filled.
Time for another chunk of code. This next listing sends a NODE STATUS REQUEST message and then parses and displays the reply. As usual, it uses and builds upon functions presented in previous listings. 1.4.3.6 Name Conflict DemandThe name conflict demand is a simple message. It looks exactly like the NEGATIVE NAME REGISTRATION RESPONSE that we covered earlier, except that the RCODE field contains CFT_ERR (0x7). To review: NAME CONFLICT DEMAND { HEADER { NAME_TRN_ID = <Whatever you like> FLAGS { R = TRUE (1) OPCODE = 0x5 (Registration) AA = TRUE (1) RD = TRUE (1) RA = TRUE (1) RCODE = CFT_ERR (0x7) B = FALSE (0) } ANCOUNT = 1 } ANSWER_RECORD { RR_NAME = <An NBT name owned by the target node> RR_TYPE = NB (0x0020) RR_CLASS = IN (0x0001) TTL = 0 RDLENGTH = 6 RDATA { NB_FLAGS { G = <TRUE for a group name, FALSE for a unique name> ONT = <Owner type> } NB_ADDRESS = <Owner's IP address> } } } Once you've got NAME REGISTRATION RESPONSE packets coded up this one will be easy. The question is, what does it do? The NAME CONFLICT DEMAND is sent whenever the NBNS or an end node discovers a name conflict somewhere on the NBT network. The goal is to make the offending node aware of the fact that it has stolen another node's name. An NBNS might send one of these if it finds an inconsistency in its database, possibly as a result of synchronizing with another NBNS21. An end node will send a NAME CONFLICT DEMAND if it gets conflicting replies to a NAME QUERY REQUEST, working under the assumption that the first response is the correct one. When a node receives a NAME CONFLICT DEMAND it is supposed
to disable the offending name. Any existing connections that were
made using that name are unaffected, but the node will no longer
respond to name queries for the disabled name, nor will it allow the
disabled name to be used for new connections. It's as if the name no
longer exists.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...the moral equivalent of Internet cow-tipping. -- David Farmer III |
There is an obvious security problem with this behavior. An evildoer can easily disable a name on, say, a file server or other important node. That alone could cause a Denial of Service condition but the evildoer can go further by registering the same name itself, thus assuming the identity of the disabled node. For this reason, Samba and most (but not all) Windows systems ignore NAME CONFLICT DEMAND messages. 1.4.3.6.1 Name Release Demand RevisitedThere are actually two messages that can be used to force a node to give up a name. In addition to the NAME CONFLICT DEMAND, there is the NAME RELEASE DEMAND. You may recall that a node operating in B (or M or H) mode will broadcast a release announcement when it wants to release one of its own names. The same message can be unicast to another node to force the node to give up a name it holds. NAME RELEASE DEMAND (unicast) { HEADER { NAME_TRN_ID = <Set when packet is transmitted> FLAGS { OPCODE = 0x6 (Release) B = FALSE (0) } QDCOUNT = 1 ARCOUNT = 1 } QUESTION_RECORD { QUESTION_NAME = <Encoded NBT name to be released> QUESTION_TYPE = NB (0x0020) QUESTION_CLASS = IN (0x0001) } ADDITIONAL_RECORD { RR_NAME = 0xC00C (Label String Pointer to QUESTION_NAME) RR_TYPE = NB (0x0020) RR_CLASS = IN (0x0001) TTL = 0 (zero) RDLENGTH = 6 RDATA { NB_FLAGS { G = <TRUE for a group name, FALSE for a unique name> ONT = <Target node's owner type> } NB_ADDRESS = <Target node's IP address> } } } As with the NAME CONFLICT DEMAND most (but not all) systems ignore this message. Play around... see what you find. 1.4.4 Enough AlreadyWe could dig deeper. We could provide finer detail. We could, for instance, discuss the design, implementation, care, and feeding of a full-scale NBNS. ...but not now. It's getting late and we still have a lot of NBT ground to cover. Go ahead and take a quick break. Hug the spouse, make a fresh pot of tea, visit the facilities, scratch the dog, and then we'll move on to the Datagram Service. When you get back, we will start by overstating one of the key points of this section: that the purpose of the Name Service is to create a virtual NetBIOS LAN on top of a TCP/IP (inter)network. 1.5 The Datagram Service in DetailLet's drill home this key concept one more time:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Oh no no, not again -- Oh No, Not Again Alan Hull, Lindisfarne |
NBT provides a set of services which combine to create a virtual NetBIOS LAN over TCP/UPD/IP transport. This would be a senseless thing to do except for the fact that lots of software uses (or used to use) the NetBIOS API. The whole point is to maintain the form and function of the API while completely replacing the guts and machinery which lie beneath. This point gets lost, however, when we deal with systems that are not derived from MS-DOS and have no use for NetBIOS itself. On these systems we work directly with the guts of NBT and, therefore, are easily confused by the odd behavior of the machinery. So, to provide a little context, here are the four NetBIOS API functions which the Datagram Service was designed to support:
Let's start by looking at the two Send Datagram functions. These two API calls provide us with three transmission options: unicast, multicast, and broadcast. Here's how they work:
That was easy. Now let's look at what happens when we map those functions onto UDP/IP at the NBT layer...
As you can see from the description, unicast datagrams are easy, B mode is easy, but handling multicast or broadcast in P, or M, or H mode is a bit more complicated. We'll give that topic a section heading all its own, just to show that it is a fairly hefty chunk of tofu. 1.5.1 Datagram Distribution over Routed IP InternetworksThe NetBIOS Datagram Distribution Server (NBDD) compliments the NBNS. It assists in extending the virtual NetBIOS LAN across a routed IP internetwork by relaying multicast and broadcast NetBIOS datagrams to nodes on remote subnets. The NBDD's job is to make sure that the datagrams get to where they're supposed to go. It works something like a lawn sprinkler--one input leads to a spray of outputs. Here's what happens:
That seems simple enough, but we claimed earlier that the Datagram
Service is the second-least well understood aspect of NBT. What are
we missing?
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
For best results, avoid doing stupid things. -- Acme Klein Bottle, Inc. |
A closer inspection reveals an obvious problem. If the number of destination nodes is large, a whole bigbunch of traffic will be generated--possibly enough to bring the NBT virtual LAN to its knees (which might really, really annoy people). The NBDD design will work well enough for small, trusted networks but it simply does not scale. Another problem is that RFC 1001 offers a loophole for implementors: the NBDD is permitted to silently ignore requests to relay datagrams. If, for any reason (including laziness on the implementor's part) the NBDD will not or can not relay a datagram, it simply discards the message without sending any sort of error message back to the originating node. This loophole might make the NBDD so unreliable as to be useless, except that the Datagram Service also supports a query operation that allows the client to ask the NBDD whether or not it will relay a message. If the NBDD answers the query with a "yes", then the client can send the datagram with the assurance that it will be relayed to all intended recipients. A negative reply means that the NBDD will not relay the message.
One more monkey-wrench to throw into the works... Given a multicast (not broadcast) datagram, if the NBDD will not relay the message the client can give it another shot. The client has already performed a Name Service NAME QUERY REQUEST operation, and received a NAME QUERY RESPONSE from the NBNS. It did this to determine that the destination name was, in fact, a group name rather than a unique name. If the NBNS is RFC-compliant, then the NAME QUERY RESPONSE will contain a list of all of the IP addresses of the group members. If the NBDD won't relay the message, then the client can unicast the datagram to each entry in the list. To summarize:
Confused? Don't be surprised if you are. It isn't a pretty system...and it gets worse. Because of the potential network problems and the awkwardness of the design, very few implementations even try to match the RFC specification. Unfortunately, no one has come up with a better solution...which means that what actually exists in the wild is worse than what was just described. 1.5.2 The NBDD and the Damage Done
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Further, I believe [RFC] 1001/1002 in general to be overspecified. --Paul Leach, Microsoft |
To be blunt, Microsoft messed up the Datagram Service. Their NBNS implementation (WINS) does not report all of the IP addresses associated with a group name. Instead, group names are mapped to a single IP address--the limited broadcast address: 255.255.255.255. This is contrary to the RFCs, and it causes a few problems. Without a list of IPs for each group name, the NBDD cannot be implemented at all. With no NBDD and no IP list, there is no way to ensure that multicast and broadcast datagrams will be sent to all group members. This breaks the continuity of the NetBIOS virtual LAN. On a "real" NetBIOS LAN, a message sent to a group name would actually reach all members of that group. That is what should happen under NBT as well, but it doesn't. The best that can be done is to broadcast on the local subnet, in which case some members of the group may get the message. Microsoft must have realized their mistake, because they later created what they call "Internet Group" names (also called "Special Group" names). For names in this category, WINS comes close to behaving like a proper NBNS; it will store up to 25 IP addresses per name, deleting the oldest entry to make room if necessary. For these names, a POSITIVE NAME QUERY RESPONSE from a WINS server will list up to 25 valid IP addresses. Internet Group names are identified by their suffix. Originally
only group names with the 0x1C suffix were given special
treatment, but more recently (with W2K?) group names with a suffix
value of 0x20 can be defined as having Internet Group status.
Note that unique names may also have these suffixes but, since they
are not group names, no special handling is required.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Who's more foolish, the fool or the fool who follows him? -- Obi Wan Kenobi (Sir Alec Guinness) Star Wars |
Sadly, most non-Microsoft implementations (including Samba) follow Microsoft's example. They map group names to the 255.255.255.255 IP address, store only 25 IPs for Special Group names, and fail to implement the NBDD22. This can cause trouble for some clients (OS/2, for example) which expect RFC behavior. 1.5.3 Implementing a Workable Datagram ServiceThat last section was a bit of a rant. Sorry. Time to pick up the pieces and move on. Let's talk about how the parts that work actually work. As with the Name Service, each Datagram Service packet has a header. The datagram header is 10 bytes long, arranged as follows:
Here is a quick rundown of the fields:
The above fields are common to all Datagram Service messages. RFC 1002 includes two more fields in its header layout: the DGM_LENGTH and PACKET_OFFSET fields. It is kind of silly to have those fields in the header, as they are specific to the messages which actually carry a data payload: the DIRECT_UNIQUE, DIRECT_GROUP, and BROADCAST DATAGRAM message types. Since the DGM_LENGTH and PACKET_OFFSET fields are associated with the datagram transport messages, we will break with tradition and put those fields together with the message structure. Here is a record layout:
That's basically all there is to it, with the exception of fragmentation. The example packet below describes an unfragmented message. DATAGRAM_HEADER (unfragmented) { MSG_TYPE = <10 = unicast, 11 = multicast, 12 = broadcast> FLAGS { SNT = <Node type, as shown above> F = TRUE (This is the first in the series) M = FALSE (No additional fragments follow) } DGM_ID = <Datagram identifier> SOURCE_IP = <IP address of the originating node> SOURCE_PORT = <Originating UDP port> } DATAGRAM_DATA { DGM_LENGTH = <Name lengths plus USER_DATA length> PACKET_OFFSET = 0 SOURCE_NAME = <Fully encoded NBT name of the sender> DESTINATION_NAME = <Fully encoded NBT name of the receiver> USER_DATA = <Datagram payload> } Some quick notes:
1.5.3.1 Fragmenting DatagramsA little way back, we mentioned the NetBIOS API Send Specific Datagram and Send Broadcast Datagram functions. These functions each accept up to 512 bytes of data on input. Given that number, the maximum on-the-wire size of an NBT Datagram is: 10 bytes (Header) + 2 bytes (DGM_LENGTH) + 2 bytes (PACKET_OFFSET) + 255 bytes (maximum size of SOURCE_NAME) + 255 bytes (maximum size of DESTINATION_NAME) + 512 bytes (maximum size of USER_DATA) ----------- 1036 bytes ...and that, of course, does not include the UDP and IP headers. The whole thing is fairly chunky--easily more than double the size of the data actually being sent. The RFC authors were concerned that the UDP transport might not carry datagrams that big, so they provided a mechanism for breaking the USER_DATA into smaller fragments, like so:
The value of the PACKET_OFFSET field is the sum of the lengths of all previous fragments. This value is included in the message so that the receiver can keep the fragments in sync as it rebuilds the original USER_DATA. This is necessary, because datagrams do not always arrive in the order in which they were sent. Now that you have learned all of that, you can forget most of it. As is typical for the Datagram Service, the fragmentation feature is rarely--if ever--used. The IP layer has its own mechanism for handling large packets so NBT datagram fragmentation is redundant. It is possible that someone, somewhere, has implemented fragmentation, so an NBT implementation should be prepared to deal with it. One simple option is to discard fragments. This can be considered valid because the Datagram Service is considered "unreliable". Something else to keep in mind: The 512-byte maximum size for the USER_DATA field is required at the NetBIOS layer, but not the NBT layer. Since the NetBIOS API is not required for implementing NBT, you mustn't expect that the datagrams you receive will fit within the limit. Code defensively. 1.5.3.2 Receiving Datagrams
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
If a tree falls in the forest, and no one is there to hear it... |
NBT receives datagram messages on UDP port 138, so clients must listen on that port at the UDP level. When a message datagram is received (MSG_TYPE is one of 0x10, 0x11, or 0x12) the DESTINATION_NAME is checked against the local name table. If the name is not found, the client should reply with a DATAGRAM ERROR MESSAGE. The available error codes are: 0x82 == DESTINATION NAME NOT PRESENT 0x83 == INVALID SOURCE NAME FORMAT 0x84 == INVALID DESTINATION NAME FORMAT The first value is used whenever the DESTINATION_NAME is not in the local name table at the receiving end. The other two codes are sent whenever the source or destination NBT names, respectively, cannot be parsed. If the name is found in the local table, then the Datagram may be passed to any application or service that is listening for the given DESTINATION_NAME. The NetBIOS API provides the Receive Specific Datagram and Receive Broadcast Datagram calls for this purpose. If there are no Receive Datagram requests waiting, the datagram is quietly discarded. NBDD processing (for those bold enough to want to implement an NBDD) is similar. When the NBDD receives a datagram it will search the NBNS database instead of the local name table. Error messages are returned as above for missing or malformed names. One more note: As a safety precaution, the receiving node should probably verify that the SOURCE_IP field in the datagram header matches either the source address in the IP header, or the NBDD address (if there is one). 1.5.3.3 Querying the NBDDThe NBDD query message is simply an NBT Datagram Service header with the DESTINATION_NAME appended: DATAGRAM_HEADER { MSG_TYPE = 0x14 (DATAGRAM QUERY REQUEST) FLAGS { SNT = <Node type> F = TRUE M = FALSE } DGM_ID = <Datagram identifier> SOURCE_IP = <IP address of the originating node> SOURCE_PORT = <Originating UDP port> } DATAGRAM_DATA { DESTINATION_NAME = <Encoded NBT name of the intended receiver> } If there is an NBDD, and if it can relay the request, it will change the MSG_TYPE field to 0x15 (POSITIVE QUERY RESPONSE) and echo the packet back to the sender. If the NBDD is unwilling or unable to relay the message it will set MSG_TYPE to 0x16 (NEGATIVE QUERY RESPONSE) before sending the reply. 1.5.3.4 The Second-least Well Understood Aspect of NBTIt really should have been much simpler, but given the design flaws and implementation errors it is no wonder people have trouble with the Datagram Service. Our hope is that this section has cleared things up a bit, and explained the problems well enough to make them easier to solve. Just to finish up, here are a few tips:
1.6 The Session Service in DetailThis is the last big chunk of NBT. It is also the easiest, which should bring a great sigh of relief. We have already covered all of the background material we need to cover, so there is no need to waste any time with preliminaries. Let's dive right in... 1.6.1 Session Service HeaderThe Session Service header, as presented in RFC 1002, is as follows:
The FLAGS field breaks down further into:
The reserved bits are always supposed to be zero, and the E bit is an additional high-order bit which is prepended to the LENGTH field. Another way to look at the layout is like this:
We will stick with the latter, simpler format and ignore the FLAGS field, which is never really used. The LENGTH field contains the number of bytes of payload, and the TYPE field is used to distinguish between the six different Session Service message types, which are: 0x00 == Session Message 0x81 == Session Request 0x82 == Positive Session Response 0x83 == Negative Session Response 0x84 == Retarget Session Response 0x85 == Session Keepalive ...each of which are explained below. 1.6.2 Creating an NBT SessionThe first step in setting up an NBT session is to discover the IP address of the remote node. The IP address is, of course, required in order to create the TCP session that will carry the NBT Session. The NBT Name Service is generally used to find the remote host's IP address, though several implementations support kludges which bypass the Name Service. Once the TCP session is established (something we assume you know how to do) the NBT session is initiated using a SESSION REQUEST message, which looks like this: SESSION REQUEST { HEADER { TYPE = 0x81 (Session Request) LENGTH = 68 (See discussion below) } CALLED_NAME = <Destination Level 2 Encoded NetBIOS name> CALLING_NAME = <Source Level 2 Encoded NetBIOS name> } One oddity of the Session Service is that the Scope ID is dropped
from the name fields in the SESSION REQUEST message. That
results in a fixed length of 34 bytes per name. That's one byte for
the leading label (always 0x20), 32 bytes for the level-one encoded
NetBIOS name, and one more byte for the trailing label (always 0x00).
The payload of a SESSION REQUEST message is, therefore, fixed
at 2 × 34 = 68 bytes.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
You don't have to call me darlin', darlin' You never even call me by my name. -- You Never Even Call Me By My Name, Steve Goodman |
There are three possible replies to the SESSION REQUEST message:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Who ya gonna call? -- Ghostbusters |
1.6.3 Maintaining an NBT SessionThere are two more Session Service message types to cover:
1.6.4 Closing an NBT SessionNothing to it. Once all activity across the session has stopped, simply shut down the TCP connection. At the NBT level, there are no special messages to send when closing the session. 1.7 Where it All Went Wrong
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Danger, Will Robinson! -- Robot Lost In Space |
Implementation is the journey from Theory to Practice. The two extremes, as we have shown, are divided by a vast chasm wherein dwell all the evil monsters from all the cheesy SCI-FI TV shows ever produced. For NBT implementors the journey can be perilous, and those who have gone before have blazed a somewhat twisted trail. Here are some of the dangers you will encounter along the way... 1.7.1 The 0x1Dirty Little SecretMaster Browser Servers (which are described later in the book) register unique names with the suffix 0x1D. The WINS server will happily acknowledge such registrations--and then drop them into a black hole and forget about them. When queried, the WINS server denies the existence of any 0x1D unique names. Nodes from one subnet can never know about the Master Browsers on other subnets, and there may be multiple nodes using the same unique 0x1D name. B nodes are immune to this behavior, since they do not make use of NBNS services. If the NBT vLAN is operating in M or H mode, however, the Master Browser names will be unique within the local IP subnet only. The same name may be registered by another Master Browser on a separate subnet. Since the WINS server does not keep any record of 0x1D names, Master Browsers can only be located using a broadcast query, which means that P nodes can never find 0x1D names. The strange handling of 0x1D names may be related to the lack of NBDD functionality. As you can see, an implementation that strays from the path will quickly find itself lost in a jungle of exceptions, special cases, and other yucky stuff from an old episode of "Outer Limits". 1.7.2 Twenty-five IPs or LessAn NBNS is supposed to keep a complete list of all IPs associated with each NBT name (group or multi-homed). If the list is too large to fit in a single UDP Name Query Reply datagram then, according to the RFCs, the NBNS is supposed to send a partial list with the TRuncation bit set. The client may then repeat the query using TCP port 137. ...but that never happens. If anyone ever did provide support for NBT Name Service over TCP, the code is now lost in space. As explained earlier, when WINS sends a NAME QUERY RESPONSE it will contain a maximum of 25 IPs per name. 1.7.3 Special Handling Required for 0x1B NamesA Domain Master Browser (a special kind of Master Browser, which is described later on in the book) will register unique names with a suffix of 0x1B. These names get special treatment in WINS. Whenever a 0x1B name is registed in WINS, the WINS server will look for a matching 0x1C group name and modify the entry. As you may recall from our diatribe in the Datagram section, 0x1C group names are "Internet Group" or "Special Group" names, and WINS will keep track of 25 IP addresses per 0x1C group name. The weird thing is that WINS also sorts this IP list so that the IP address associated with the 0x1B name is at the top of the list. Why?
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Billions of bilious blistering blue barnacles! -- Captain Haddock The Adventures of Tintin Hergé |
Well, see, the 0x1C names represent the set of Domain Controllers for a given NT Domain. Only the Primary Domain Controller is allowed to run the Domain Master Browser service and register the 0x1B name. So, by sorting the IP list, WINS ensures that the IP address of the Primary Domain Controller is always the first IP address in the 0x1C list of Domain Controllers. 1.7.4 Alternate Name ResoultionThere are several ways to bypass the NBT Name Service. The simplest is the use of an LMHOSTS file, which provides NetBIOS name to IP address mappings. LMHOSTS is similar in concept to the /etc/hosts file commonly used by Unix-y systems to provide TCP/IP name mappings. Another Name Service bypass trick involves using DNS names or IP addresses instead of using NetBIOS names to find remote services. This trick is generally used when connecting to an SMB server via the NBT Session Service. The obvious problem here is that the Session Service expects that the CALLED NAME in the SESSION MESSAGE be correct. There are several work-arounds to the naming problem.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1.7.5 The Awful TruthThe awful truth is that an NBT implementation must accommodate--and often comply with--the errors, kludges, omissions, and fumbles of the past. The installed base is simply too big to try and get it right. Not to worry. You now have enough information to build a working NBT implementation. Writing an NBNS and NBDD server should also be within reach, and you can pull code from some of the many Open Source projects that are out there (as long as you respect the licenses). We have covered all of the major pitfalls, and NBT is a resilient little system. Making it work is a lot easier than getting it right. |
2 Microsoft calls their NBNS implementation "Windows Internet Name Service" (WINS). The term WINS is now commonly used instead of NBNS, but we will be pedantic and stick with the latter.
3 If the NBT authors had used TCP/138 instead of 139 for the Session Service, they could have saved a couple of ports. Instead, TCP/138 and UDP/139 are wasted.
4 Note the use of the term "preferred". A close read of RFCs 883, 1034, 1035, and 2181 shows that the idea of using binary data in DNS records has been around for some time.
5 Some call this a "half-ASCII"-ed encoding scheme.
6 Such considerations are important when programming in C and its ilk.
7 "Pedantic" is the politically correct way to say "anal retentive".
8 Samba's behavior may change if no reason can be found to compare the decoded names. Decoding costs a few cycles, which could be significant in an NBNS implementation.
9 The lab in the basement is rather sparse, and not all versions of MS Windows can be tested. The reported behavior appears on those variants that were available. We leave it as an exercise for the reader to verify that the behavior is consistent. Please let us know of any contradictory results.
10 The program in listing 1.3 has been tested on Debian GNU/Linux and OpenBSD. You may have to fiddle a bit to get it to work on other platforms. Under older versions of NetBSD, OpenBSD, Miami for Amiga, and possibly other BSD-derived TCP stacks, messages sent to the limited broadcast address (255.255.255.255) may not actually be sent as Ethernet broadcasts. On these systems, it will be necessary to change the value of NBT_BCAST_ADDR to the directed broadcast address of the local subnet (the local subnet broadcast address). This bug has been fixed in both NetBSD and in OpenBSD. See the original NetBSD bug report (#7682) for more information.
11 With a few notable exceptions, this is the way that tea is prepared in American cafés. Ick.
12 To further complicate matters Microsoft has registered its own character sets, such as the Windows-1252 character set. Windows-1252 is a superset of ISO Latin-1. It uses octets in the range 0x80..0x9F (normally reserved for control characters) to represent some additional display characters, such as the trademark symbol (TM). This is why non-Microsoft web browsers on non-Microsoft platforms often display question marks all over the screen when they load web pages generated by Microsoft products.
13 Big-endian byte order is also known as "normal", "intuitive", or "obvious" byte order. Little-endian is sometimes referred to as "annoying", "dysfunctional", or "stupid". These designations do not, of course, reflect any bias or preference.
14 It is easy, but wrong, to simply copy back the information from the ADDITIONAL_RECORD of the NAME REGISTRATION REQUEST. The NEGATIVE NAME REGISTRATION RESPONSE should identify the node that currently owns the name. (...and yes, some day I may fix this in Samba.)
15 |
3 days 00:00:00 == 259,200 seconds == 0x0003F480 (Samba) 3 days 11:20:00 == 300,000 seconds == 0x000493E0 (Windows) 3 days 19:01:20 == 327,680 seconds == 0x00050000 |
16 Many thanks to Monyo for providing packet captures.
17 For example, when an NBNS is processing a multi-homed registration it should send name queries with the RD bit clear, yet all Windows systems that were tested set the RD bit. It may not matter, however, unless the multi-homed host is also the node running the NBNS, in which case the problem would likely be solved using internal mechanisms (because the NBNS would be sending the query to itself). The right thing to do is to send verification queries with the RD flag turned OFF.
18 Many thanks to Jean François for all of his work on WINS behavior and TTL gymnastics.
19 Microsoft may be assuming that the NBNS service is being provided by their own WINS implementation. Samba's NBNS, which is part of the nmbd daemon, periodically writes the contents of its database to a file called wins.dat. The wins.dat file is re-read at startup, and any non-expired names are placed back into the database. This prevents data loss due to system restart. Samba sends refreshes every TTL/2 seconds, and there have been reports of Samba server names "disappearing" from WINS databases following a Windows system crash. It is likely that newer versions of Samba (V3.0 and beyond) will use Microsoft's formula for calculating name refresh time.
20 Windows systems typically cache resolved names for about seven minutes. Use the nbtstat -c command from the DOS prompt to see the cache contents.
21 Microsoft's WINS servers can be configured to replicate with one another, simultaneously distributing the database for greater reliability and increasing the risk of conflicts and other corruption. WINS replication takes place over TCP port 42, should you care to observe. The replication protocol is fairly straight-forward and has been untangled. There are plans to add WINS replication support to Samba sometime after version 3.0 is released.
22 Network Telesystems, which has since been acquired by Efficient Networks, used to have an NBNS implementation that handled group names correctly and worked quite well with IBM's OS/2. Brian Landy has also written a set of patches for Samba's nmbd daemon which provide more complete NBDD support. See: http://www.landy.cx/
23 This field is probably not even used by most implementations. For a long time, Samba miscalculated the DGM_LENGTH field by including the 14-byte RFC header length. This bug (fixed as of 2.2.4) did not seem to cause any trouble.
Copyright © 1999-2003 Christopher R. Hertel All rights reserved. $Revision: 1.260 $ |