Implement TCP/IP programming (top) KEYWORDS dos, socket, TCP/IP, and wattcp under DOS real model

Source: Internet
Author: User

Implement TCP/IP programming under DOS real model (lower)

Http://blog.csdn.net/dos5gw/archive/2010/03/29/5429582.aspx

 

 

 

There may be very few people using DOS, and fewer people are working on DOS.

There are many reasons.

But in terms of industrial control, there are still a lot of DOS users, especially dos622 and dos71 are still running smoothly on many industrial computer, POS machines, and supermarket cashier terminals.

I didn't have time to study TCP/IP network programming under DOS, but the boss assigned me a task to convert the old Program (using serial communication) into RJ45, that is, Nic communication;

After turning over a lot of information, I finally decided on a general plan,

1. The NIC Driver must comply with the packet driver specification for DOS drivers. The reason will be explained later,

2. Find a suitable TCP function library used in the DOS environment and complete a simple communication program according to readme,

3. Remove the serial port from the old program ,,,,,,,,

4. In order not to affect other modules, the function prototype used by the original serial port should not be changed.

 

For the TCP function library under DOS, four solutions are tentatively set. wattcp, dsock, ertos, and client for DOS finally determine to use wattcp. Because of its open source and concise nature, it can directly achieve the purpose of communicating with the network card;

And because these materials are very old, they are difficult to find, but we still find some clues for reference.

Http://hengch.blog.163.com/blog/static/1078006720083391831884/

Http://www.wangchao.net.cn/bbsdetail_147812.html

The first link mainly describes how to use the djgpp + Watt-32 library, because I do not need to program the protection mode in DOS, so I use the bc31 + wattcp library to implement it; (This Watt-32 is probably an upgraded version of wattcp's protection mode .)

The second one uses Borland C ++ 4.5, which is somewhat different from the BC 3.1 I use, such as creating a project. However, there is a client code instance in this post, some functions in wattcp are used in general. However, what I want to do is to run the client program on the DOS Industrial Computer (lower computer) as the server and XP (upper computer, this is the opposite of this introduction.

 

 

// --- Separator: NIC Driver Installation --------------------------------------------------------------

 

(1) DoS Driver Installation. Dos Nic drivers are classified into two categories: Packet dirver and NDIS. The former specification can be seen at http://blog.hengch.com/specification/packetdriver.htm. Generally, the former driver is generally *. com format. the latter is *. DOS format,

Because the wattcp library is based on Packet driver, you must find the packet driver of your Nic. My IPC is Yanhua 3355, it took a long time to find the driver from a very old forum.

If your Nic unfortunately only has the NDIS Type Driver, refer to the following article, NDIS to PD: http://www.cn-dos.net/forum/viewthread.php? Tid = 33390 & fpage = 1

 

There are several manufacturers of NIC Driver: http://www.cublog.cn/u/15901/showart_204285.html, also introduced the DOS network boot disk practices. It is worth a look

 

The method for installing the dos nic Driver is different from that for Windows. For example, the model of the NIC in Yanhua 3355 is, the amount, and cannot be remembered ,,, boot bios, you can see that the driver is. COM file,

The file name is "e100bpkt. com ", in autoexec. add "@ e100bpkt 0x60" to bat. In this way, 0x60 is the interrupt vector, and 0x62 is commonly used. autoexec of my industrial computer. bat is like this:

Path = C:/; C:/dos7; C:/driver;

@ E100bpkt 0x60


This is probably the case, but it's hard to remember ,,,

 

 

 

// --- Delimiter: creation of the programming environment --------------------------------------------------------------

 

For convenience, I used the vmwarevm, installed DOS 7, and copied a bc31 ,,,,,,,,,,,

It is worth mentioning that there are many people playing dos with Vmware, but they do not know the model of the wmware virtual Nic. I tried to use an Intel driver and the result failed, later I learned that VMware is using an "amd pcnet" Nic. the driver can be downloaded at http://www.cublog.cn/u/15901/showart_204285.html. the loading method has changed somewhat like that mentioned above: @ pcntpk Int = 0x60,

 

Open bc31 and create an empty project (it is not recommended to create a new project here, because the project in bc31 has many options, including Compiler Optimization Options and floating point processing options, so find a project template,)

 

 

The wattcp Library/lib directory is the Library (wattcphg. LIB/wattcplg. LIB/wattcpsm. lib corresponds to the giant/big/micro mode respectively), added to your bc31 project, wattcp provides the C function library, to compile the C ++ program, add the following command before including the header file:
# Ifdef _ cplusplus
Extern "C "{

# Include "wattcp. H"
}
# Endif

 

 

 

 

Next, write the configuration on Vmware. Select host-only as the virtual machine connection method, enable vm8 in XP, set IP: 192.168.221.1, MAS: 255.255.255.0, And the gateway is empty,


The configuration file TCP. cfg of wattcp is as follows:

Myip = 192.168.221.10

Netmask = 255.255.255.0

 

Gateway = 192.168.1.252

 

For specific examples, see TCP. cfg in the/apps directory. This file must be placed in the current directory of the program.

 

 

Wattcp not only provides the source code and makefile of the entire function library, but also provides several examples written using wattcp. In the/apps directory, the commonly used network commands are implemented using C.

Make will automatically compile the link and use the generated ping.exe to try ~~~~~~

 

 

// -- Reference :---------------------------------------------------------------------------------

Some help for people who are not familiar with DOS network applications
Basically and Windows Network support has a similar level, MS client also contains the corresponding "Nic", "protocol" and "network customer" level of content. But the package driver is independent. The network connection in the network boot disk is basically in line with the following structure:

Packet-driven applications are based on internet shared access from Microsoft Network customers.
|
Three protocols provided by dis_pkt.dos MS client and Microsoft Network Customer
|
/------------------- + ---------------------/
|
Proman. EXE and NIC Driver Module


We can see that the package driver supportsIndependent fromThe MS client provides several protocols, that is, it can run without the support of any protocol of the MS Client and can be freely combined with them. In addition, this also means a packet-driven TCP/IP application.CompleteMS Client TCP/IP is not supported. Therefore, if you use MS client's own ping.exe to test the pppoe connection established by the fuse package driver, you will be confused.

In the boot disk, pdping.exe is a packet-driven ping tool. Note that it uses TCP Ping instead of ICMP. Unfortunately, it needs to know its own IP address before it can work, and the Startup Disk establishes a pppoe connection to the ADSL. to simplify the work, the bat script always sets its IP address as a fake 255.255.255.255.254. This object has no impact on many other practical applications, such as Arachne or lynx, but it makes the pdping work abnormal. Therefore, do not use it to test the pppoe connection. We recommend that you directly use Lynx to open a website and check whether it can be used. ADSL. bat is a toggle-type operation method. The first operation is dial-up, and the second operation is a hanging machine. The rest of this article also provides some instructions on pppoe support, which will not be detailed here.

For wattcp applications (a class of packet-driven applications), you can directly modify the environment variable or wattcp if necessary. configuration in the cfg file, in most cases, you do not need to restart the computer, you just need to re-enter the application to use, because the configuration here does not reside in the memory. When the MS Client protocol is used, the configuration must be restarted.

As mentioned earlier, you must use net use to create a ing for network sharing on other machines, or use net share to create a share on the local machine. If necessary, please refer to the simple help provided by net help.

// -- For reference :----------------------------------------------

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.