荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: georgehill (佐治·希尔), 信区: Linux
标  题: TCP/IP over serial line(zz)
发信站: BBS 荔园晨风站 (Fri Jan 21 00:59:27 2000), 站内信件

【 以下文字转载自 georgehill 的信箱 】
【 原文由 georgehill.bbs@bbs.whnet.edu.cn 所发表 】
发信人: wyvern (龙的传人), 信区: UNIX
标  题: TCP/IP over serial line(zz)
发信站: 武汉白云黄鹤站 (Thu Jan 20 12:09:50 2000), 站内信件

简体中文版维护:dfbb, fangh@bepc3.ihep.ac.cn

一、 SLIP


 SLIP在实际应用上分为标准SLIP、封包压缩CSLIP两种。事实上,
所谓的封包压缩只是压缩封包的表头部分,对资料传输上,有部分
提升。然而,在与主机端连线时必须确认对方所使用的协定种类,
否则大部分的功能将无法使用。

 完成SLIP连线共包含三个步骤,调制解调器拨号接通主机、设定硬件
界面、设定route table。这三个步骤可分别执行dial、ifconfig
、route三个指令来完成。这□我们不分别说明这三个程序如何执行
,我们把焦点集中在dip这个程序,它可以自动调用其他程序,完成
整个SLIP连线工作。

 下dip -t指令可以进入测试模式,得到dip所有指令列表,我们也
不对测式模式多作介绍,所有动作都可以写入script中,拨号、签
入、从主机送出的讯息抓出我们的IP一次完成。


  这□是dip所有指令列表:

DIP: Dialup IP Protocol Driver version 3.3.7l-uri (27 Dec 94)
Written by Fred N. van Kempen, MicroWalt Corporation.

DIP> help
DIP knows about the following commands:

        bootp    break    chatkey  config   databits
        dec      default  dial     echo     flush
        get      goto     help     if       inc
        init     mode     modem    netmask  parity
        password proxyarp print    port     quit
        reset    securidf securid  send     skey
        sleep    speed    stopbits term     timeout
        wait


  下面我们通过一个script范例来看整个连线过程:


* dip只有支持四个内部参数,$local存放主机指定给我们的IP,
  $remote存放SLIP主机的IP,$mtu存放最大传输封包大小,
  $errlvl存放指令执行传回值。目前尚没有支持使用者自定参数
    。

* dip的script没有循环的功能,只有简单的if-goto逻辑判断、
    及goto的分支执行

* 在完成slip连线後,我们所拥有的IP及domain皆为主机所指定,
  在执行ftp、telnet等程序不会有问题。特别要注意e-mail时,
  发信人地址是用我们所设的domain,别人在回信时会无法投递,
  因为自设的domain没有注册,对方的信件程序无法从domain找
    出您的IP。如果要测试信件收发,可以用<user>@<ip addr>的
    方式传递。


#
# xxx.dip       Dialup IP connection support script. (dynamic)
#
# Version:      xxx.dip 1.0     08/12/94
#
# Author:       Vincent Chen
#
# Features:     Support multiple phone numbers
#               Redial automatically when busy
#

main:

  #
  # Set serial port and speed.
  #
  port cua1                             # 指定modem连接port (COM2)
  speed 57600                           # RS-232传输速度
  netmask 255.255.0.0

  #
  # Prepare for dialing.
  #
  # send <string>: 传送指令给modem
  # \r代表CR字元,modem在收到CR後开始解释、执行指令
  # \n代表LF+CR
  #
  send AT&FL1S0=0S7=25\r
  if $errlvl != 0 goto modemerr         # modem指令执行失败的处理
  #
  # wait <string> <n>
  # 在<n>秒内从modem取得<string>,成功传回0
  #
  wait OK 3                             # 等待modem传回执行结果
  if $errlvl != 0 goto modemerr
  #
  # print <string>: 在萤幕上显示<string>
  #
  print DIP script for XXX SLIP server by Vincent Chen 08/12/1994
  print ---------------------------------------------------------
  print ............... AutoDial procedure started ..............
  print ................. Press Ctrl-C to abort .................

dialsvr:

  #
  # Now trying the 1st number
 # 先拨第一支电话
  #
  # sleep <n>: 暂停执行n秒
  #
  sleep 3
  print .................... Trying xxx-xxxx ....................
  send ATDTxxx-xxxx\r                   # 拨server电话号码
  if $errlvl != 0 goto modemerr
  wait BUSY 15                          # 判断是否占线
  if $errlvl == 0 goto next
  wait CONNECT 10                       # 等待连线讯息
  if $errlvl != 0 goto next
  goto login                            # 连线成功,开始签入主机

next:

  #
  # Now trying the 2nd number
  # 第一支电话无法连上,改拨第二支
  #
  sleep 3
  print .................... Trying 368-9280 ....................
  send ATDT368-9280\r
  if $errlvl != 0 goto modemerr
  wait BUSY 15
  if $errlvl == 0 goto dialsvr
  wait CONNECT 15
  if $errlvl != 0 goto dialsvr
  goto login

#
# 调制解调器连线成功,开始签入主机
#

login:

  wait login: 10                        # 等主机送出签入的提示讯息
  if $errlvl != 0 goto error
  send slip\r                           # 送出您的帐号
  if $errlvl != 0 goto error
  #wait password: 10                    # 等待主机要求输入密码
  #if $errlvl != 0 goto error
  #send xxxxx\r                         # 送出您的密码
  #if $errlvl != 0 goto error
  #
  # Catch the key word to confirm that IP will show up shortly.
  #
  wait \nEnter 5                      # 等待主机送出我们IP前的字串
  if $errlvl != 0 goto error          # '\n'是专为台大而设的
  #
  # Get dynamic IP from strings that sent by server
  #
  # get $local <remote/ip address> <n>
  # 在<n>秒内取得我们的ip,可指定dip自行抓或由我们直接指定
  # get $local remote <n>: 让dip从server送出的讯息抓我们的ip
  # get $local xxx.xxx.xxx.xxx <n>: 直接告诉dip我们的ip
  #
  # 注意:在下get指令之前必须确定不会有类似ip的字串重复出现
  #       ,否则会造成dip误判,前面之所以要等Enter字串就是
  #       考虑到这一点。
  #
  get $local remote 3                   # 由dip分析我们的IP
  if $errlvl != 0 goto error
  #
  # Get gateway IP from strings that sent by server
  #
  # get $remote <remote/ip address> <n>
  # 在<n>秒内取得server的ip,可指定dip自行抓或由我们直接指定
  # get $remote remote <n>: 让dip从server送出的讯息抓server的ip
  # get $remote xxx.xxx.xxx.xxx <n>: 直接告诉dip server的ip
  #
  get $remote remote 3                  # 由dip分析主机的IP
  if $errlvl != 0 goto error

  #
  # Set up the SLIP operating parameters.
  #
  get $mtu 1024                         # 设封包长度最大值

  #
  # Set Destination net/address as type 'default' (vice an address).
  # This is used by the 'route' command to set the kernel routing
table.
  # Some machines seem to require this be done for SLIP to work
properly.
  #
  default                               # 由dip自行建立route table

#
# Give the connection report !
#

done:

  print ****** Connected ******
  print IP address is $local
  print Remote gateway is $remote
  #
  # mode <SLIP/CSLIP/PPP>
  #
  mode SLIP                             # 进入SLIP传输模式
  goto exit

error:

  print SLIP connection failed.
  goto exit

modemerr:

  print Modem initializing failed.
  goto exit

exit:


 在script完成後,只要输入dip <script filename>,dip根据预
设的流程自动连上主机。以下是整个script执行过程:

bash# dip /etc/xxxxx
DIP: Dialup IP Protocol Driver version 3.3.7l-uri (27 Dec 94)
Written by Fred N. van Kempen, MicroWalt Corporation.

DIP script for xxx SLIP server by Vincent Chen 08/12/1994
---------------------------------------------------------
................ AutoDial procedure started ..............
.................. Press Ctrl-C to abort .................
..................... Trying xxx-xxxx ....................
****** Connected ******
IP address is xxx.xxx.xxx.xxx
Remote gateway is yyy.yyy.yyy.yyy


 从上面可看到在拨第一支电话後,成功的连上主机。主机指定给
我们的IP是xxx.xxx.xxx.xxx,Server的IP是yyy.yyy.yyy.yyy。本
□例会在忙线时,接著拨第二支电话,直到连线完成,只要稍作修
改可以支持第三、第四支电话。

  连线完成後我们可以用ifconfig指令看到dip已经为我们设定好
sl0这个slip channel,在1.1.78版之前的核心只支持4个channel,
目前新的核心可以支持到16个channel,对外连线不论您同时ftp、
telnet几部主机都只占用一个channel。这表示如果您把linux当作
一部slip server的话,您还有15个channel提供dial-in的服务。


 接著我们先用ifconfig指令检查dip是否已经设好slip界面。

bash# ifconfig

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Bcast:127.255.255.255  Mask:255.0.0.0
          UP BROADCAST LOOPBACK RUNNING  MTU:2000  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0
          TX packets:20 errors:0 dropped:0 overruns:0

sl0       Link encap:VJ Serial Line IP
          inet addr:xxx.xxx.xxx.xxx  P-t-P:yyy.yyy.yyy.yyy  Mask:255.
255.0.0
          UP POINTOPOINT RUNNING  MTU:1024  Metric:1
          RX packets:0 errors:0 dropped:0 compressed:0
          TX packets:0 errors:0 dropped:0 compressed:0

eth0      Link encap:10Mbps Ethernet  HWaddr 00:00:C0:00:02:F1
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.
0
          UP BROADCAST RUNNING  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0
          TX packets:0 errors:0 dropped:0 overruns:0
          Interrupt:15 Base address:0x340


  在下表我们可以看到除了原有的loop back、ethernet之外又多了
xxx.xxx.xxx.xxx及default这两个dip为我们设好的封包传输路径。
default route是一个特殊的封包传输路径,所有目的地不在传输路
径表上的封包都通过这个管道对外传送,我们可以看到default route
是以xxx.xxx.xxx.xxx为getway,因此必须另外指定送往xxx.xxx.xxx
..xxx的封包是透过sl0□面传送。


bash# route

Kernel routing table
Destination     Gateway         Genmask         Flags MSS    Window
Use Iface
xxx.xxx.xxx.xxx *               255.255.255.255 UH    960    0
0 sl0
192.168.1.0     *               255.255.255.0   U     1436   0
0 eth0
loopback        *               255.0.0.0       U     1936   0
20 lo
default         xxx.xxx.xxx.xxx *               UG    960    0
0 sl0


 要结束连线时只要下dip -k指令,dip会帮我们挂断电话、清除传
输路径表、关闭sl0传输界面等所有工作,回复未连线前的系统状况
。当然用kill -9 <dip process id>也有同样的效果。


bash# dip -k

DIP: Dialup IP Protocol Driver version 3.3.7l-uri (27 Dec 94)
Written by Fred N. van Kempen, MicroWalt Corporation.

DIP: process 115 killed.



SLIP CHECKLIST:


1. /etc/HOSTNAME及/etc/hosts档内有定义您自已的linux主机吗?
2. /etc/resolv.conf档内有定义您的nameserver吗?
3. dip script内mode <protocol>指令和主机端所用的协定相符吗?
4. 连线後所显示□


--
※ 来源:.武汉白云黄鹤站 bbs.whnet.edu.cn.[FROM: 202.114.1.155]
--
※ 转寄:.武汉白云黄鹤站 bbs.whnet.edu.cn.[FROM: 210.39.3.50]
--
※ 转载:·BBS 荔园晨风站 bbs.szu.edu.cn·[FROM: 192.168.1.115]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店