Slip configuration on linux host

From DOSBoxWiki
Revision as of 20:13, 19 June 2016 by Naszvadi (talk | contribs) (Example slip configuration on ubuntu host)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

DOSBox supports nullmodem connection using tcp sockets. In this page, we describe a simple networking slip configuration on linux (ubuntu) host. With socat or similar tools on host's side, you can connect these sockets with slattach, and the DOSBox guest can access internet as well.

Prerequisities under ubuntu

Internet settings

A working internet connection is essential. 192.168.7.0/30 network must be unused! Otherwise network range collision will happen, causing unpredictable results!

Required ubuntu packages

And also the following packages needs to be installed:

apt-get install bash dosbox iptables socat sudo unzip wget

The main script: slipbox.sh

The content of the slipbox.sh

#! /bin/bash

flushipt() {
  for i in $( iptables -t nat -n --line-numbers -L | awk '/^Chain POSTROUTING/,/^$/{print $0}' \
            | grep '^[0-9]' | grep '192\.168\.7\.' | awk '{ print $1 }' | tac )
  do
    iptables -t nat -D POSTROUTING "$i"
  done

  for i in $( iptables -t nat -n --line-numbers -L | awk '/^Chain PREROUTING/,/^$/{print $0}' \
            | grep ^[0-9] | grep '192\.168\.7\.' | awk '{ print $1 }' | tac )
  do
    iptables -t nat -D PREROUTING "$i"
  done
}

if id -u | grep -q '^0'; then
    :
else
    echo 'dosbox slip setter'
    echo 'Author: Naszvadi Peter'
    echo
    echo "Please run $0 as root!"
    echo
    exit 1
fi

if ! which socat; then
    echo
    echo 'Install socat! It is required.'
    echo
    echo 'e.g. sudo apt-get install socat'
    echo
    exit 1
fi

if ! which slattach; then
    echo
    echo 'Install slattach! It is required.'
    echo
    exit 1
fi

if ! which dosbox; then
    echo
    echo 'Install dosbox! It is required.'
    echo
    exit 1
fi

Uid="$(find "$0" -printf '%U' -quit)"

if [ -z "$(find . -iname ethersl.com)" ]; then
    if ! which unzip; then
        echo
        echo 'Install unzip! It is required.'
        echo
        exit 1
    fi
    if ! which wget; then
        echo
        echo 'Install wget! It is required.'
        echo
        exit 1
    fi
    sudo -u "#$Uid" bash -c 'wget -q http://crynwr.com/drivers/pktd11.zip \
    && unzip -Cj pktd11.zip ethersl.com'
fi

if [ -z "$(find . -iname ethersl.com)" ]; then
    echo
    echo 'Unsuccesful: getting ethersl.com'
    echo
    exit 1
fi

if [ -z "$(find . -iname ircjr.exe)" ]; then
    if ! which unzip; then
        echo
        echo 'Install unzip! It is required.'
        echo
        exit 1
    fi
    if ! which wget; then
        echo
        echo 'Install wget! It is required.'
        echo
        exit 1
    fi
    sudo -u "#$Uid" bash -c 'wget -q -O mtcp.zip http://www.brutman.com/mTCP/mTCP_2013-05-23.zip \
    && unzip -Cj mtcp.zip ircjr.exe'
fi

if [ -z "$(find . -iname ircjr.exe)" ]; then
    echo
    echo 'Unsuccesful: getting ircjr.exe'
    echo
    exit 1
fi

echo Flushing...
flushipt
echo Flushing done

Dev_Pts='/tmp/slip'"$RANDOM"
Slip_Port=8040

if ! [ -e dosslip.cnf ]; then
sudo -u "#$Uid" bash -c 'cat <<END > dosslip.cnf
[sdl]
mapperfile=mapper.map
[serial]
serial1=nullmodem server:localhost port:'"$Slip_Port"' transparent:1
[autoexec]
mount C .
C:
ethersl 0x60 4 0x3f8 9600
SET MTCPSLIP=true
SET MTCPCFG=C:\\MTCP.CFG
ircjr irc.freenode.net #dosbox
END'
fi

if ! [ -e mtcp.cfg ]; then
sudo -u "#$Uid" bash -c 'cat <<END > mtcp.cfg
DHCPVER DHCP Client version Jul 29 2011
TIMESTAMP Mon May 21 13:14:59 2012
packetint 0x60
hostname DOSRules
ircjr_nick dbxij'"$RANDOM"'
ircjr_user dbxij'"$RANDOM"'
ircjr_name McBus Luck
ircjr_connect_timeout 300
ircjr_register_timeout 300
ftpsrv_password_file NUL
ftpsrv_log_file NUL
IPADDR 192.168.7.2
NETMASK 255.255.255.252
GATEWAY 192.168.7.1
NAMESERVER 8.8.8.8
LEASE_TIME 600
END'
fi

socat PTY,link="$Dev_Pts",raw,echo=0 TCP-LISTEN:"$Slip_Port" &
Pid_Saved_3="$!"
sleep 1

sudo -u "#$Uid" dosbox -conf dosslip.cnf &
Pid_Saved="$!"

# setting linux ipv4 forwarding
grep -q 1 /proc/sys/net/ipv4/ip_forward || ( echo 1 1>/proc/sys/net/ipv4/ip_forward )

slattach -d -s 9600 -p adaptive "$Dev_Pts" 1>/dev/null 2>/dev/null &
Pid_Saved_2="$!"

sleep 3

ifconfig sl0 192.168.7.1 dstaddr 192.168.7.2 netmask 255.255.255.252 mtu 576 up 1>/dev/null 2>/dev/null
set -x
iptables -t nat -A POSTROUTING -s 192.168.7.0/30 -j MASQUERADE 1>/dev/null 2>/dev/null

set +x
while ps "$Pid_Saved" 1>/dev/null 2>/dev/null; do
    sleep 5
done 1>/dev/null 2>/dev/null

2>&-
kill -9 "$Pid_Saved_2" "$Pid_Saved_3" 1>/dev/null 2>/dev/null

echo Flushing...
flushipt
echo Flushing done

exit 0
## This is the end of slipbox.sh !

Before invoking the "sudo ./dosslip.sh" from terminal, a mapper.map file should be generated, in which the alt key assigned to right ctrl. See more on Keymapper . Mapperfile creation step is only needed for this specific example, for the running of mTCP irc client "ircjr", which needs alt-[NUM] keycombos for changing between windows.

Launch a networked session under ubuntu

Creating working directory

Create a standalone folder, e.g. mkdir ~/dosslip

Creating files

Only slipbox.sh and mapper.map is needed. slipbox.sh should be saved from this site, and mapper.map could be created by invoking

dosbox -conf /dev/null .

in dosslip folder (ctrl-f1, save). Rename mapper* to mapper.map, then edit it: replace 'key_lalt' line to 'key_lalt "key 305"'

Set attributes of slipbox.sh:

chmod 755 slipbox.sh

Optionally, you can get and place ETHERSL.COM from crynwr packet driver collection and IRCJR.EXE from mTCP collection, but these are downloaded during the running of dosslip, if they don't exist.

Launch ./slipbox.sh

Do it with sudo:

sudo ./slipbox.sh

If everything is okay, you can get similar result like this:

Dosbox slip ircjr.gif

Links