|
jon parise // monday, november 23, 2009
|
|
|
Caching DNS Server in Visual Basic
A while back, I was enrolled in the Information Technology department's Network Programming course. Because the "official" language of the IT department was Visual Basic back then, that was the required programming language for all of the course's projects. I really can't say I'm a big fan of Visual Basic, but it gets the job done (even if the job is network programming ...). One of our projects dealt with the Domain Name Service protocol (as defined by RFC 1035). We were tasked to write a caching name server that would forward unknown requests to a configurable parent name server. The cache was required to honor each entry's expiration (TTL). The most difficult part of the project was crunching the internal DNS packet format. The original creators of the packet format implement a "pointer" method, presumably to save space by reducing redundant strings inside of the packet. For example, if the string example.com appears in the packet before a string that is intended to represent host.example.com is listed, the second string will be shortened to host.offset, where offset is a numeric offset from the start of the packet to the start of the previously listed example.com string. There is no limit to the number of these pointers that can be used in a given packet, so long as they are used correctly. It took me a while to completely grok this problem, but I solved it rather elegantly using a recursive function. I still don't think I have it working perfectly in all case, however, but it is good enough to function correctly under normal use. As stated above, all of the source code is written in Visual Basic. I don't pretend to be a good Visual Basic programmer, but I do have a firm grasp on general programming principles, so the code should be fairly sane. A review of the code will probably uncover various hacks and other assorted ugliness, but I was experiencing a great deal of frustration with Visual Basic throughout most of the project, so I probably let a lot of sloppy yet functional code slip in. You're perfectly free to use this code for anything you like, provided you conform to the terms of the standard BSD license (the text of which is included in each of the source files). I don't offer any support for this software nor do I intend to continue its development. I provide it here as a fairly good example of sockets programming under Windows using Visual Basic. It's more of a learning toy than anything else, and you should treat it as such. Enjoy!
|
|
Copyright © 1997-2009 by
Jon Parise. All rights reserved. |
Last updated: February 12, 2006 15:33 EST Valid XHTML 1.0 // Valid CSS |