TCP/IP routines for QuickBASIC version 1.1
Written by Mike Chambers, 2006
Last update: 11/28/2006

These routines work with the Trumpet TCP/IP stack for DOS.
I've included NTCPDRV.EXE for you to use. You also need to
first load a packet driver compatible with your network
adapter. See www.crynwr.com for packet drivers, they have
the best.

For examples on how to effectively use my routines, check
the sample programs I wrote in the EXAMPLES directory.

You _MUST_ load QuickBASIC with the QB.QLB quicklibrary for
the routines to work, since it requires the use of
interrupt calls! Load it by running QB like this:

For QuickBASIC 4.x: <i>QB.EXE /L QB.QLB</i>
For QuickBASIC 7.1: <i>QBX.EXE /L QBX.QLB</i>

My routines also support opening a socket for LISTENING!
Can be used to write server apps. Refer to TELNSERV.BAS in
the EXAMPLES directory for an example of opening sockets
for listening.

-----------

it doesn't detect the tcpdrv interrupt right now, you have to initialize it with a function:
tcpInit(&H61) <---- 61h is the usual interrupt. the function returns an integer result, 1 = success, 0 = fail... although it locks the system up if it fails anyway. i will probably work on making it detect automatically, sorry.

use the tcpListen%(port) function to open a listening port. it returns the socket's handle as an integer.

to wait for the listening port to get a connection, just keep checking tcpStatus%(handle) for the sckOpen constant.

for opening an outward socket, the function is:
tcpConnect%(RemoteIP string, RemotePort integer)
it returns a handle too of course.

to send a packet, use this subroutine: (limit the data string to 1500 bytes)
tcpSendData tcpHandle as integer, Data2Send as string

to get any waiting packet data, call this function: (reads from the input queue 1500 bytes at a time)
tcpGetData$(tcpHandle as integer)
it returns a string, of course

tcpStatus%(tcpHandle) function returns a handle's connection status. it'll be one of these constants:
sckOpen
sckClosed (a 0 can also mean it's closed)
sckListening

tcpDoIO is just a subroutine you should call periodically to get TCPDRV to process packets.

it's good to use the tcpClose (tcpHandle as integer)
subroutine after you're done with a handle, because it frees them for reuse.

you can read important info about the network settings with some of these:
tcpDriver.LocalIP (long integer)
tcpDriver.LocalNetmask (long integer)
tcpDriver.LocalGateway (long integer)
tcpDriver.LocalDNS (long integer) - your dns host's IP
tcpDriver.LocalDomain (256 byte string)
tcpDriver.DomainLen (integer) - use this to trim the LocalDomain string.
tcpDriver.Timeserver (long integer)
tcpDriver.ErrorCode (integer) - i made these constants you can use: errBadCall, errCritical, errNoHandles, errTimeout, errBadsession. this gives any error code that the last function you ran may have returned.

to convert any of the long integers to an IPv4 string, use the Conv2IP$(long integer) function.

i've included the source for some example programs i've written to show how to use the routines. i included a telnet client, telnet server, and an HTTP downloader. the routines seem extremely stable and don't lose any packets at all. i downloaded a 240 MB AVI file to my 386 with my HTTP downloader example from the linux box on my LAN, and it came out flawlessly and played fine.

the only thing i might add later and make a version 2.0 for, is hostname dns resolution. i haven't done that yet.

i've never really messed with DNS on such a low level.... i'll need to read up on it. if anybody has some good info, and maybe some example queries/response packets let me know please!
-Mike (half_eaten@yahoo.com)
