在 DOS 下要如何寫 TCP IP 的程式 |
|
jackkcg
站務副站長 ![]() ![]() ![]() ![]() ![]() 發表:891 回覆:1050 積分:848 註冊:2002-03-23 發送簡訊給我 |
http://alumni.caltech.edu/~dank/trumpet/ MS-DOS TCP/IP Programming
(Note: this page is a bit stale. Not sure if WATTCP has an official home anymore.)
Packet Drivers
Many DOS TCP/IP packages rely on these. You can pick them up from Crynwr Software, the home of the Packet Driver spec. Alternatives to packet drivers, along with some WATTCP debugging info for end-users, are mentioned in an FAQ I wrote for a game that uses WATTCP and KLOS PPP.
WATTCP
Wattcp is very popular. Printed programmer's guide available. Statically linked library; uses Packet Driver interface.
Official WATTCP Home Page
WATTCP archives
Gisle Vanem's Watt-32 , a port of WATTCP to four different 32 bit C compilers. Very good! Looks like Gisle is carrying on the Wattcp flame! New as of 1/2000
A few Usenet posts with bugfixes are archived below.
Other TCP/IP packages for DOS programmers
FTP Software's PC/TCP Software Development Kit (Commercial)
Asynch Systems' TCP/IP for DOS (Commercial)
DOS Trumpet
DOS Trumpet is a TSR with a fairly well defined API (called ABI to emphasise that it's a binary application interface, not just a source level interface).
The official home page for DOS Trumpet ABI is http://www.trumpet.com.au/dosapps/. Version 3.01 (aka ntcpdrv) is referred to as "using less memory" on the official home page, but it is the first version to properly implement several features, for example, the ability to find the address of sender of a UDP packet. Mike Durkin has written a great C wrapper for the trumpet ABI; you can download it from Tsoft's site. I have ported his C wrapper to 32 bit Watcom C. (It still compiles under 16 bit Borland, too.) You can download my port from here until Mike picks it up. (Note: I only ported the DNS and UDP parts-- the TCP part still needs porting, but it should be very easy.)
A few Usenet posts with bugfixes are archived below. The wrapper comes with working DNS routines and an example finger client, but no UDP examples. To remedy that, I have written ports of a perl UDP example: Perl versions:
udp-send.pl
udp-recv.pl
DOS C versions:
udpsend.c
udprecv.c
UNIX C versions:
uudpsend.c
uudprecv.c
We can be fairly sure that this ABI works, because Tsoft's NFS based on it. (See http://www.tsoft.net/software/nfs-client.html)
The trick to receiving UDP packets is revealed in the DNS code: you can use the same handle to get DNS responses as you used to send them! That means that the 'srcport' and 'destport' parameters to udp_open are really 'localport' and 'remoteport'. Pages about RARP
RFC903: RARP The definition.
Mike Wright's RARPSET -- Includes source. Works well with Etherppp. Fails with KLOS PPP.
Frank Mohlzahn's IPRARP
Other pages of interest to TCP/IP programmers
See also Guy Lancaster's pages about small TCP/IP stacks
DOS Boa - a simple but fast web server for DOS
Vladimir Alexiev's ftp archive of DOS internet software and links page
Realmspace for DOS - collection of DOS internet apps
FDISK.COM's DOS Internet Pages (Good!)
TCP/IP Resources List
Arachne - a real-mode DOS web browser
DOSPPPD- a port of Linux's PPPD to DOS
tvdog's DOS TCP/IP apps page
tvdog's ftp archive ftp://ftp.agate.net/users/01935/internet/
Nigel's (unfinished) list of PPP Applications for DOS
http://www.paxnet.com.au/~nigel/dos.html
The PC-Mac TCP/IP & NFS FAQ list
Dos and Windows Network Software
How I Learned To Stop Worrying About Network Management and Love BOOTP
DHCP FAQ
Game Programming
KALI -- IPX games over TCP/IP (based on WATTCP)
ftp://ftp.syd.dit.csiro.au/pub/ken/NIC/index.html
http://www.well.com/user/peterh/dcbwpktd.html
http://adserver.cis.yale.edu/pclt/WINWORLD/NDIS.HTM
http://www.teleport.com/~shrew/kali.html
ftp://ftp.syd.dit.csiro.au/pub/ken/htget095.zip
Winsock Programming (For comparison)
Another Winsock Programming site (For comparison)
DOS TCP/IP integrated software suites (no TSR's)
NetTamer
Related Usenet postings
Subject: TCPDRV C ABI bug fixed --- tcpabi_udp_status
Date: Fri, 03 Apr 1998 20:19:25 -0600
From: dszhou@cs.sdu.edu.cn
Newsgroups: comp.protocols.tcp-ip.ibmpc, comp.protocols.tcp-ip I found a bug in Trumpet TCP ABI in C interface TABI9605, and
fixed it. The bug is caused by an omitted line in specification
file TCP201.SPE. To fix this bug, add the following line in
udp_status segment just after line "ah = 24H" in file TCP201.SPE
first. bx = handle Then rewrite C function tcpabi_udp_status as following: int tcpabi_udp_status(unsigned handle, unsigned char flags,
unsigned *size_next, tcpabi_session_info_t far **info )
{
union REGS r;
struct SREGS s; segread(&s);
r.h.ah = 0x24;
r.h.al = flags;
r.x.bx = handle; /* Added by dszhou@cs.sdu.edu.cn, 98.03.24 */
int86x( _tcpabi_vector, &r, &r, &s );
_tcpabi_errno = r.h.dl;
if( size_next ) *size_next = r.x.cx;
if( info ) *info = MK_FP( s.es, r.x.di );
return ( _tcpabi_errno ? -1 : r.x.ax );
/* return number of packets avail */
/* or -1 if error */
} Subject: WATTCP UDP passive socket bug fixed
Date: Fri, 03 Apr 1998 20:22:17 -0600
From: dszhou@cs.sdu.edu.cn
Newsgroups: comp.protocols.tcp-ip.ibmpc, comp.protocols.tcp-ip I found a bug in WATTCP9609 UDP part, and fixed it. The bug is, if
you open a passive UDP socket for a UDP server(such as TFTP server),
the server can gets first datagram from a client, and then discards
all successive datagrams from the same client. If you set debug on
(using tcp_set_debug_state), you can see "discarding..." when a
datagram arrives. The bug is due to the cross effect of function udp_handler in file
PCTCP.C and function _arp_resolve in file PCARP.C, and some more.
When first datagram reaches the server, the server records client's
IP address and port, then sends an ARP request to find client's MAC
address(really need here?). Unfortunately, the ARP answer packet
overwrites the head of the first datagram buffer, myaddr CHANGES.
So successive datagrams are discarded. There are several ways to remedy this error. I simply move the
_arp_resolve function call to the end of function udp_handler,
the datagram buffer is useless there. By the way, it's fortune that we can get first datagram's content,
because ARP packet length is just the same as normal IP head length
plus UDP head length. For your convenience, I list the corrected function here. Dashui Zhou, Dept. of CS, Shandong Univ., China. /*
* Handler for incoming packets.
*/
static void udp_handler( in_Header *ip )
{
udp_Header *up;
tcp_PseudoHeader ph;
word len;
byte *dp;
longword temp;
udp_Socket *s;
int need_arp = 0; /* must be auto, 98.04.03 */ temp = intel( ip->destination ); // temp = ip number
// or 255.255.255.255
// or sin_mask.255.255 if ( ((~temp & ~sin_mask) != 0) && /* not a broadcast packet*/
((( temp - my_ip_addr) > multihomes ) /* not my address */
&& my_ip_addr)) /* and I know my address */
return; len = in_GetHdrlenBytes(ip);
up = (udp_Header *)((byte *)ip + len); /* udp segment pointer */
len = intel16( up->length ); /* demux to active sockets */
for ( s = udp_allsocs; s; s = s->next ) {
if ( s->safetysig != SAFETYUDP ) {
if (debug_on) outs("chain error in udp\r\n");
}
if ( (s->hisport != 0) &&
(intel16( up->dstPort ) == s->myport) &&
(intel16( up->srcPort ) == s->hisport) &&
((temp & sin_mask) == (s->myaddr & sin_mask)) &&
(intel( ip->source ) == s->hisaddr )) break;
}
if (_dbugrecv) (*_dbugrecv)( (sock_type*)s, ip, up, 0);
if ( !s ) {
/* demux to passive sockets */
for ( s = udp_allsocs; s; s = s->next )
if ( ((s->hisaddr == 0) || (s->hisaddr == 0xffffffffuL))
&& intel16( up->dstPort ) == s->myport ) { // do we record this information ???
if ( s->hisaddr == 0 ) {
s->hisaddr = intel( ip->source );
s->hisport = intel16( up->srcPort ); /* dszhou@cs.sdu.edu.cn found a bug and fixed here, Apr. 3, 1998 */
need_arp = 1; /* remember we need arp */
/* and postpone arp action */ // take on value of expected destination unless
// it is broadcast
if ( (~temp & ~sin_mask) != 0 )
s->myaddr = temp;
}
break;
}
}
if ( !s ) {
/* demux to broadcast sockets */
for ( s = udp_allsocs; s; s = s->next )
if ( (s->hisaddr == 0xffffffffuL) &&
(intel16( up->dstPort ) == s->myport )) break;
} if ( !s ) {
if (debug_on) outs("discarding...");
return;
} // these parameters are used for things other than just checksums
ph.src = ip->source; /* already INTELled */
ph.dst = ip->destination;
ph.mbz = 0;
ph.protocol = UDP_PROTO;
ph.length = up->length;
if ( up->checksum ) {
ph.checksum = checksum(up, len);
if (checksum(&ph, sizeof( tcp_PseudoHeader)) != 0xffff)
return;
} /* process user data */
if ( (len -= UDP_LENGTH ) > 0) {
dp = (byte *)( up );
if (s->dataHandler)
s->dataHandler( s, &dp[ UDP_LENGTH ], len , &ph, up);
else {
if (len > s->maxrdatalen ) len = s->maxrdatalen;
movmem( &dp[ UDP_LENGTH ], s->rdata, len );
s->rdatalen = len;
}
} if( need_arp ) /* get his MAC address before return,
98.04.03 */
_arp_resolve(intel(ip->source), &s->hisethaddr, 0); } // End of udp_handler Subject: WATTCP UDP Client/Server Example
Date: 8 Apr 1998 20:01:37 GMT
From: "Michael Temari" temari@ix.netcom.com
Newsgroups: comp.protocols.tcp-ip.ibmpc I've been seeing some questions regarding WATTCP UDP programming lately and
thought I would share my UDP client/server test program. Basically run the program with no arguments and it is a server that listens
on UDP port 812 and echoes back whatever it receives. Pass the argument of
the IP address of the server and the program becomes the client allowing
you the enter data that will be sent to the server and get bounced back. Hope this helps those who are trying to do UDP programming with WATTCP. Michael Temari
temari@ix.netcom.com attached file: Wtest.c --------------------------------------------------------------------------------
Dan Kegel dank@alumni.caltech.edu
*********************************************************************
------
********************************************************** 哈哈&兵燹 最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好 Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知 K.表Knowlege 知識,就是本站的標語:Open our mind |
jackkcg
站務副站長 ![]() ![]() ![]() ![]() ![]() 發表:891 回覆:1050 積分:848 註冊:2002-03-23 發送簡訊給我 |
此篇已經有80人來觀看過 dos下的老玩意 也許是許多人認定不再ㄘ回頭路 請問有人有試玩看看嗎? 聽天使站長說 健保ic卡也是用 WATTCP 你知道它能用在那嗎? 希望有人能討論 若有範例分享更好 嵌入式系統 將慢慢搶浮現台面 不再神秘 研究是 程式師 的最大挑戰 不知專於bios設計的 lcsboy 版主 是否有新的資訊 可以告訴大家 3q 先謝了
------
********************************************************** 哈哈&兵燹 最會的2大絕招 這個不會與那個也不會 哈哈哈 粉好 Delphi K.Top的K.Top分兩個字解釋Top代表尖端的意思,希望本討論區能提供Delphi的尖端新知 K.表Knowlege 知識,就是本站的標語:Open our mind |
flyup
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:280 回覆:508 積分:385 註冊:2002-04-15 發送簡訊給我 |
WATTCP 相關參考網站: http://www.wattcp.com/
http://www.smashco.com/wattcp.asp
http://www.programmersheaven.com/zone3/cat531/17005.htm Getting Started with WatTCP使用手冊:
http://www.jkmicro.com/newsite/documentation/pdf/wattcp_start.pdf FDSMTPOP 0.1 - WATTCP based SMTP/POP3 client implementation for DOS
http://www.progsoc.uts.edu.au/lists/FreeDOS/1997/07 Jul/0001.html ----------------
局局棋盤步步新,
變化無常平常待。
人生相處平常心,
無憂無慮心事成。
----------------
|
flyup
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:280 回覆:508 積分:385 註冊:2002-04-15 發送簡訊給我 |
應用範例: 用ghost在30分鐘內將電腦教室所有的電腦灌好! GHOSTSRV 產生影像檔 操作方法
範例:
以NT 或 98 執行 GhostSrv Windows版
若是WIN95則須至微軟下載WINSOCK2 步驟如下:
1.至http://www.microsoft.com/windows/downloads/contents/Updates/W95Sockets2/
下載
2.執行 WS2SETUP.EXE
3.重新開機
設定如下:
Session Name : WORK Dump From Client
Image File : D:\test.gho 選partition (你要放影像檔的位置)
Auto Start Time : 10:00 Timeout : 30
按Accept Clients 以DOS端執行GHOST CLIENT版
1.製作空白開機片
2.設定packet driver
如執行 DE22XPD.COM(DELINK 22X)
3.拷貝ghost.exe 及 WATTCP.CFG
4.編輯WATTCP.CFG
內容如下:
IP=192.168.0.1
NETMASK=255.255.255.0
GATEWAY=192.168.0.2
RECEIVE_MODE=6
(RECEIVE_MODE 如果允許最好選4(GHOST專用Multicast模式),若4不行則選5(一般型
Multicast封包,再由GHOST自己過濾),若還不行則只好用6(所有封包全部送到網路上
,可能無法做Multicast拷貝).
5.編輯AUTOEXEC.BAT
DE22XPD
GHOST -CLONE,src=1,dst=@MCWORK -sure -z3 (此為第一顆硬碟,若是其第一個PARTI
TION,則src=1:1 -z3為壓縮參數)
6.開機執行GHOST
選 MULTICAST
SESSION NAME 輸入 WORK
選擇你要複製的PARTITION
選OK.... 若網路上有DHCP SERVER 則WATTCP.CFG可為空白檔,或根本不用,所有網路基本資料由DHCP直
接給. --------------------------------------------------------------------------------
--------
GHOSTSRV 多投式(Multicast)硬碟對拷 操作方法
範例:
以NT 或 98 執行 GhostSrv Windows版
若是WIN95則須至微軟下載WINSOCK2 步驟如下:
1.至http://www.microsoft.com/windows/downloads/contents/Updates/W95Sockets2/
下載
2.執行 WS2SETUP.EXE
3.重新開機
設定如下:
Session Name : WORK Load To Client
Image File : D:\test.gho 選partition (你要放影像檔的位置)
Auto Start Time : 10:00 Timeout : 30
按Accept Clients 以DOS端執行GHOST CLIENT版
1.製作空白開機片
2.設定packet driver
如執行 DE22XPD.COM(DELINK 22X)
3.拷貝ghost.exe 及 WATTCP.CFG
4.編輯WATTCP.CFG
內容如下:
IP=192.168.0.1
NETMASK=255.255.255.0
GATEWAY=192.168.0.2
RECEIVE_MODE=6
(RECEIVE_MODE 如果允許最好選4(GHOST專用Multicast模式),若4不行則選5(一般型
Multicast封包,再由GHOST自己過濾),若還不行則只好用6(所有封包全部送到網路上
,可能無法做Multicast拷貝).
5.編輯AUTOEXEC.BAT
DE22XPD
GHOST C-CLONE,SRC=@MCWORK,dst=1 -sure (此為第一顆硬碟,若是其第一個PARTITI
ON,則dst=1:1 -z3為壓縮參數)
6.開機執行GHOST
選 MULTICAST
SESSION NAME 輸入 WORK
選擇你要複製的PARTITION
選OK.... 若網路上有DHCP SERVER 則WATTCP.CFG可為空白檔,或根本不用,所有網路基本資料由DHCP直接給. ----------------
局局棋盤步步新,
變化無常平常待。
人生相處平常心,
無憂無慮心事成。
----------------
|
flyup
資深會員 ![]() ![]() ![]() ![]() ![]() 發表:280 回覆:508 積分:385 註冊:2002-04-15 發送簡訊給我 |
使用WATTCP技術之 Ghost廣播快速複製多台電腦的方法 參考實作教學網址: http://www.yhps.tn.edu.tw/doc/GHOST¼s¼½.htm ----------------
局局棋盤步步新,
變化無常平常待。
人生相處平常心,
無憂無慮心事成。
----------------
|
brian741022
一般會員 ![]() ![]() 發表:7 回覆:9 積分:3 註冊:2006-07-19 發送簡訊給我 |
|
brian741022
一般會員 ![]() ![]() 發表:7 回覆:9 積分:3 註冊:2006-07-19 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |