The article is pasted from my blog. The pictures may not come through. For the complete content, please visit my blog:
Click to enter "DOS Programming Technology"
Network programming under Windows is not a very difficult task, but it's not easy at all under DOS. For many people, it's even hard to start. This article elaborates in detail the methods of network programming under DOS, and the next article will give a specific example.
To carry out network programming under DOS, first of all, there should be a Packet Driver. It's a hardware-related driver that conforms to the PC/TCP Packet Driver specification proposed by FTP Software. Readers who are interested can download this specification at the following address:
http://blog.hengch.com/specification/packetdriver.pdf
The network chip on the motherboard of the machine I use is rt8139. The corresponding Packet Driver is rtspkt.exe. The method of driving is to add the following line in autoexec.bat:
@rtspkt 0x62
Among them, 0x62 is the interrupt vector. If this interrupt vector is already occupied on your machine, you can change it to other unoccupied interrupt vector numbers. According to the PC/TCP specification, it should be between 0x60----0x80.
After having the Packet Driver, we also need a useful function library that can provide TCP/IP Socket programming interfaces. Under DJGPP, we suggest using the WATT-32 library. This library has more abundant content than the WATTCP library provided on the DJGPP official website, and it has complete documents and rich sample programs. It can be downloaded at the following website:
http://www.bgnett.no/~giva/
WATT-32 is released in the form of source code, so it needs to be compiled and linked by yourself before use. The whole process is as follows (the following steps are based on the fact that you have correctly installed DJGPP and RHIDE according to the previous blog article "Installation and Implementation of DJGPP + RHIDE under DOS"):
First, download WATT-32 from the above website. There are 3 zip packages, as follows:
watt32b*.zip, watt32s*.zip, watt32d*.zip
Among them, "*" will be different with different version numbers.
Copy the 3 files to the machine to be configured through a U disk or other media. Since DOS does not support long file names, the three files need to be renamed respectively: watt32b.zip, watt32s.zip and watt32d.zip
Unzip the three files to a subdirectory, for example: c:\net\watt
c:\>md net
c:\>md net\watt
c:\>unzip32 watt32b.zip -d c:\net\watt
c:\>unzip32 watt32s.zip -d c:\net\watt
c:\>unzip32 watt32d.zip -d c:\net\watt
During the unzipping process, some shared files will be overwritten. It doesn't matter, overwrite all the files.
Add the variable WATT_ROOT in the environment variable.
Need to modify autoexec.bat and add the following line:
set WATT_ROOT=c:\net\watt
Then restart the computer.
Generate the make file
c:\>cd\net\watt\src
c:\net\watt\src>configur djgpp
After this step, you will see a prompt asking you to execute make -f djgpp.mak, just do it.
Generate the WATT-32 library
Follow the prompt of the previous step
c:\net\watt\src>make -f djgpp.mak
This step takes a long time, and you need to be patient. There will be some "warnings" during the compilation process, just ignore them.
Configure the environment variables for using the WATT-32 library
After the compilation is completed, we also need to add four environment variables in autoexec.bat. The WATT_ROOT environment variable added in step 4 is only useful during the compilation process, and it is not needed in actual use, so it can be removed (of course, it doesn't matter if you don't remove it).
Add the following four lines in autoexec.bat:
set WATTCP.CFG=c:\net\watt\bin
set ETC=c:\net\watt\bin
set C_INCLUDE_PATH=c:/net/watt/inc
set LIBRARY_PATH=c:/net/watt/lib
WATTCP.CFG is the location of the configuration file wattcp.cfg of WATT-32. You can also put wattcp.cfg in other directories, such as: c:\net\cfg directory, but remember to change the line set WATTCP.CFG=c:\net\watt\bin to:
set WATTCP.CFG=c:\net\cfg
So far, the installation has been completed. You should be able to see the file libwatt.a in the c:\net\watt\lib directory, which is the network function library we need.
At this time, network programming may still not be possible. It is also necessary to actually configure the wattcp.cfg file. As mentioned earlier, this file is placed in the c:\net\watt\bin directory. We can see the sample of this file in this directory. At least we need to configure the IP address and address mask in the configuration file, similar to the following form:
my_ip=192.168.0.10
mask=255.255.255.0
Sometimes, it is also necessary to configure the gateway and the resolver, similar to the following:
gateway=192.168.0.1
nameserver=202.106.134.133
There can be one or more nameservers, and each resolver occupies one line.
Generally speaking, configuring these four parameters is enough. If you want to configure more parameters, you can refer to the instructions in wattcp.cfg.
To learn network programming under DOS, there is an article that is very worth reading, "Beej's Guide to Network Programming Using internet Sockets". When this article was written, its latest version was already 2.4.5, completed on August 5, 2007. The version I initially saw of this article was still 1.5.5, written on January 13, 1999. It seems that the author is still updating it continuously. The homepage of this article is: http://beej.us/guide/bgnet/
The 1.5.5 version of this article has multiple Chinese translations on the Internet. The following is one of them:
http://www.chinalinuxpub.com/doc/pro/is.html
You can also download the 2.4.5 version of this article written on August 5, 2007 in PDF format at the following address:
http://blog.hengch.com/article/bgnet_A4_2.pdf
The data structures and functions mentioned in this article are all the data structures and functions for network programming under the BSD specification, and they are all applicable in the WATT-32 library.
In addition, readers can download the usage instructions for all functions in the WATT-32 library at the following address:
http://blog.hengch.com/Manual/watt-32.chm
In fact, WATT-32 has not produced a complete and easy-to-use manual, but has continued to use the manual of WATTCP. But since the manual of WATTCP is chargeable, it is not convenient to disclose it here. Readers who are interested in this manual can visit the following website and request it:
http://www.erickengelke.com/wattcp/docs.shtml
There are also many subdirectories in the bin directory of WATT-32, and there are many sample programs in them. Before starting network programming, you can first look at these sample programs. Let's take one of the samples to illustrate how to compile a program containing the WATT-32 library under RHIDE.
We take the ftpsrv sample to illustrate how to compile under RHIDE. First, enter the directory of this sample and open the sample program with RHIDE:
c:\>cd\net\watt\bin\ftpsrv
c:\net\watt\bin\ftpsrv>rhide ftpsrv
In this way, RHIDE will automatically create a project of ftpsrv. At present, there are no items in this project. Follow the steps below to add the program ftpsrv.c to the project:
alt+p-->select Add Item-->select ftpsrv.c-->press Enter-->press Esc key to exit
In this way, we can see an item: ftpsrv.c in the Project Window at the bottom of the screen. At this time, if you choose to compile and link (press ALT+C and then select Make), some errors will occur during the linking process. This is because we have not linked the WATT-32 library. Operate as follows:
ALT+O-->select Libraraies-->enter watt-->press SHIFT+TAB (at this time, the cursor should stop on the before watt-->press space (see )-->press Enter
Then compile and link according to the following steps, and ftpsrv.exe can be generated.
ALT+C-->select Make-->press Enter
So far, we have learned the process of installing and configuring WATT-32 under DJGPP, and also learned how to compile a program using the WATT-32 library under DJGPP with RHIDE. We are ready for network programming.
For more articles about DOS programming, please visit my blog
Click to enter "DOS Programming Technology"
[ Last edited by whowin on 2008-5-9 at 11:50 AM ]
Click to enter "DOS Programming Technology"
Network programming under Windows is not a very difficult task, but it's not easy at all under DOS. For many people, it's even hard to start. This article elaborates in detail the methods of network programming under DOS, and the next article will give a specific example.
To carry out network programming under DOS, first of all, there should be a Packet Driver. It's a hardware-related driver that conforms to the PC/TCP Packet Driver specification proposed by FTP Software. Readers who are interested can download this specification at the following address:
http://blog.hengch.com/specification/packetdriver.pdf
The network chip on the motherboard of the machine I use is rt8139. The corresponding Packet Driver is rtspkt.exe. The method of driving is to add the following line in autoexec.bat:
@rtspkt 0x62
Among them, 0x62 is the interrupt vector. If this interrupt vector is already occupied on your machine, you can change it to other unoccupied interrupt vector numbers. According to the PC/TCP specification, it should be between 0x60----0x80.
After having the Packet Driver, we also need a useful function library that can provide TCP/IP Socket programming interfaces. Under DJGPP, we suggest using the WATT-32 library. This library has more abundant content than the WATTCP library provided on the DJGPP official website, and it has complete documents and rich sample programs. It can be downloaded at the following website:
http://www.bgnett.no/~giva/
WATT-32 is released in the form of source code, so it needs to be compiled and linked by yourself before use. The whole process is as follows (the following steps are based on the fact that you have correctly installed DJGPP and RHIDE according to the previous blog article "Installation and Implementation of DJGPP + RHIDE under DOS"):
First, download WATT-32 from the above website. There are 3 zip packages, as follows:
watt32b*.zip, watt32s*.zip, watt32d*.zip
Among them, "*" will be different with different version numbers.
Copy the 3 files to the machine to be configured through a U disk or other media. Since DOS does not support long file names, the three files need to be renamed respectively: watt32b.zip, watt32s.zip and watt32d.zip
Unzip the three files to a subdirectory, for example: c:\net\watt
c:\>md net
c:\>md net\watt
c:\>unzip32 watt32b.zip -d c:\net\watt
c:\>unzip32 watt32s.zip -d c:\net\watt
c:\>unzip32 watt32d.zip -d c:\net\watt
During the unzipping process, some shared files will be overwritten. It doesn't matter, overwrite all the files.
Add the variable WATT_ROOT in the environment variable.
Need to modify autoexec.bat and add the following line:
set WATT_ROOT=c:\net\watt
Then restart the computer.
Generate the make file
c:\>cd\net\watt\src
c:\net\watt\src>configur djgpp
After this step, you will see a prompt asking you to execute make -f djgpp.mak, just do it.
Generate the WATT-32 library
Follow the prompt of the previous step
c:\net\watt\src>make -f djgpp.mak
This step takes a long time, and you need to be patient. There will be some "warnings" during the compilation process, just ignore them.
Configure the environment variables for using the WATT-32 library
After the compilation is completed, we also need to add four environment variables in autoexec.bat. The WATT_ROOT environment variable added in step 4 is only useful during the compilation process, and it is not needed in actual use, so it can be removed (of course, it doesn't matter if you don't remove it).
Add the following four lines in autoexec.bat:
set WATTCP.CFG=c:\net\watt\bin
set ETC=c:\net\watt\bin
set C_INCLUDE_PATH=c:/net/watt/inc
set LIBRARY_PATH=c:/net/watt/lib
WATTCP.CFG is the location of the configuration file wattcp.cfg of WATT-32. You can also put wattcp.cfg in other directories, such as: c:\net\cfg directory, but remember to change the line set WATTCP.CFG=c:\net\watt\bin to:
set WATTCP.CFG=c:\net\cfg
So far, the installation has been completed. You should be able to see the file libwatt.a in the c:\net\watt\lib directory, which is the network function library we need.
At this time, network programming may still not be possible. It is also necessary to actually configure the wattcp.cfg file. As mentioned earlier, this file is placed in the c:\net\watt\bin directory. We can see the sample of this file in this directory. At least we need to configure the IP address and address mask in the configuration file, similar to the following form:
my_ip=192.168.0.10
mask=255.255.255.0
Sometimes, it is also necessary to configure the gateway and the resolver, similar to the following:
gateway=192.168.0.1
nameserver=202.106.134.133
There can be one or more nameservers, and each resolver occupies one line.
Generally speaking, configuring these four parameters is enough. If you want to configure more parameters, you can refer to the instructions in wattcp.cfg.
To learn network programming under DOS, there is an article that is very worth reading, "Beej's Guide to Network Programming Using internet Sockets". When this article was written, its latest version was already 2.4.5, completed on August 5, 2007. The version I initially saw of this article was still 1.5.5, written on January 13, 1999. It seems that the author is still updating it continuously. The homepage of this article is: http://beej.us/guide/bgnet/
The 1.5.5 version of this article has multiple Chinese translations on the Internet. The following is one of them:
http://www.chinalinuxpub.com/doc/pro/is.html
You can also download the 2.4.5 version of this article written on August 5, 2007 in PDF format at the following address:
http://blog.hengch.com/article/bgnet_A4_2.pdf
The data structures and functions mentioned in this article are all the data structures and functions for network programming under the BSD specification, and they are all applicable in the WATT-32 library.
In addition, readers can download the usage instructions for all functions in the WATT-32 library at the following address:
http://blog.hengch.com/Manual/watt-32.chm
In fact, WATT-32 has not produced a complete and easy-to-use manual, but has continued to use the manual of WATTCP. But since the manual of WATTCP is chargeable, it is not convenient to disclose it here. Readers who are interested in this manual can visit the following website and request it:
http://www.erickengelke.com/wattcp/docs.shtml
There are also many subdirectories in the bin directory of WATT-32, and there are many sample programs in them. Before starting network programming, you can first look at these sample programs. Let's take one of the samples to illustrate how to compile a program containing the WATT-32 library under RHIDE.
We take the ftpsrv sample to illustrate how to compile under RHIDE. First, enter the directory of this sample and open the sample program with RHIDE:
c:\>cd\net\watt\bin\ftpsrv
c:\net\watt\bin\ftpsrv>rhide ftpsrv
In this way, RHIDE will automatically create a project of ftpsrv. At present, there are no items in this project. Follow the steps below to add the program ftpsrv.c to the project:
alt+p-->select Add Item-->select ftpsrv.c-->press Enter-->press Esc key to exit
In this way, we can see an item: ftpsrv.c in the Project Window at the bottom of the screen. At this time, if you choose to compile and link (press ALT+C and then select Make), some errors will occur during the linking process. This is because we have not linked the WATT-32 library. Operate as follows:
ALT+O-->select Libraraies-->enter watt-->press SHIFT+TAB (at this time, the cursor should stop on the before watt-->press space (see )-->press Enter
Then compile and link according to the following steps, and ftpsrv.exe can be generated.
ALT+C-->select Make-->press Enter
So far, we have learned the process of installing and configuring WATT-32 under DJGPP, and also learned how to compile a program using the WATT-32 library under DJGPP with RHIDE. We are ready for network programming.
For more articles about DOS programming, please visit my blog
Click to enter "DOS Programming Technology"
[ Last edited by whowin on 2008-5-9 at 11:50 AM ]
