Networking

Serge Vakulenko edited this page Feb 8, 2016 · 22 revisions

LiteBSD has a full network support implemented, including a TCP/IP stack and NFS network filesystem, as inherited from 4.4BSD.

Boards with Ethernet port

[Microchip MEB-II board](Microchip MEB II board) can be used as a development platform for Ethernet applications. The kernel configuration file MEBII.pic32 enables the driver for internal pic32mz Ethernet controller:

controller      en0                     # Ethernet controller
pseudo-device   ether                   # generic Ethernet protocol

Supported PHY transceivers currently include SMSC LAN8720A and SMSC LAN8740A. On kernel startup, the connected PHY is automatically detected:

4.4BSD-Lite build 0 compiled 2015-03-18
    sergev@ubuntu-sergev:LiteBSD/sys/compile/MEBII.pic32
cpu: PIC32MZ2048ECH144 rev A4, 200 MHz
. . .
en0 at interrupt 153, MAC address 00:1e:c0:cb:28:35
en0: <SMSC LAN8740A>
. . .
starting network
en0: link up, 100Mbps, full duplex
. . .

Startup and configuration

When Ethernet interface en0 is present in the kernel, the startup script /etc/netstart activates it with predefined IP address 10.0.2.15:

if ifconfig en0 >/dev/null 2>&1; then
    ifconfig en0 inet 10.0.2.15
fi

You can modify the IP address or the whole script to match your desired configuration. By default, the following services are activated. See file /etc/inetd.conf for details.

Service Port Application
biff udp 512 /usr/libexec/comsat
exec tcp 512 /usr/libexec/rexecd
finger tcp 79 /usr/libexec/fingerd
ftp tcp 21 /usr/libexec/ftpd
login tcp 513 /usr/libexec/rlogind
ntalk udp 518 /usr/libexec/ntalkd
shell tcp 514 /usr/libexec/rshd
telnet tcp 23 /usr/libexec/telnetd

In case your network is properly configured and Ethernet cable attached, you can test it with ping utility:

# ping 10.0.2.2
PING 10.0.2.2 (10.0.2.2): 56 data bytes
64 bytes from 10.0.2.2: icmp_seq=0 ttl=255 time=2.104 ms
64 bytes from 10.0.2.2: icmp_seq=1 ttl=255 time=0.194 ms
64 bytes from 10.0.2.2: icmp_seq=2 ttl=255 time=0.169 ms
64 bytes from 10.0.2.2: icmp_seq=3 ttl=255 time=0.14 ms
^C
--- 10.0.2.2 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.14/0.651/2.104 ms

Use netstat utility to view the network interface statistics:

# netstat -i
Name  Mtu   Network     Address            Ipkts Ierrs    Opkts Oerrs  Coll
en0   1500  <Link>      52.54.0.12.34.56       5     0        6     0     0
en0   1500  10          10.0.2.15              5     0        6     0     0
lo0   1536  <Link>                             0     0        0     0     0
lo0   1536  your-net    127.0.0.1              0     0        0     0     0

Telnet service

You can make outgoing or incoming connections using Telnet protocol. An example of incoming connection from remote Linux workstation:

$ telnet 10.0.2.15
Trying 10.0.2.15...
Connected to 10.0.2.15.
Escape character is '^]'.


4.4BSD-Lite (bsd.net) (ttyp0)

login: root
Last login: Mon Mar  2 13:27:31 on console
Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994
        The Regents of the University of California.   All rights reserved.

4.4BSD-Lite UNIX #1: Fri Apr 01 00:00:00 PDT 1994

Welcome to 4.4BSD-Lite!

erase ^H, kill ^U, intr ^C status ^T
Don't login as root, use the su command.
# ps alx
  UID   PID  PPID CPU PRI NI   VSZ  RSS WCHAN  STAT TT       TIME COMMAND
    0     0     0   0 -18  0     0    0 schedu DLs  ??    0:00.08 (swapper)
    0     1     0   1  10  0   168    0 wait   IWs  ??    0:00.26 /sbin/init
    0     2     0  29 -18  0     0    0 -      RL   ??    0:02.97 (pagedaemon)
    0    30     1   0  18  0    20    0 pause  Ss   ??    0:00.53 update
    0    36     1   0   2  0   200    0 select SWs  ??    0:01.11 inetd
    0    58    36   0   2  0   240    0 select S    ??    0:00.72 telnetd
    0    59    58   4  10  0   244    4 wait   Ss   p0    0:01.18 -sh (sh)
    0    61    59   1  28  0   204   92 -      R+   p0    0:00.11 (ps)
    0    40     1   0   3  0   244    0 ttyin  IWs+  1    0:01.85 -sh (sh)
# _

Outgoing connection to remote server:

# telnet rainmaker.wunderground.com
Trying 38.102.137.140...
Connected to rainmaker.wunderground.com.
Escape character is '^]'.
------------------------------------------------------------------------------
*               Welcome to THE WEATHER UNDERGROUND telnet service!           *
------------------------------------------------------------------------------
...

FTP service

FTP service is enabled by default. User root is not allowed to use it, so to try it, you need to create a user, or setup a password for one of predefined users, like "ken":

# passwd ken
Changing local password for ken.
New password: ****
Retype new password: ****
passwd: rebuilding the database...
passwd: done
# _

Now you can connect from remote machine via FTP:

$ ftp 10.0.2.15
Connected to 10.0.2.15 (10.0.2.15).
220- 
220- myname.my.domain -- Ftp server.
220- 
220 bsd.net FTP server (Version 6.00) ready.
Name (10.0.2.15:sergev): ken
331 Password required for ken.
Password:
230- No directory! Logging in with home=/
230- 4.4BSD-Lite UNIX #1: Fri Apr 01 00:00:00 PDT 1994
230- 
230- Welcome to 4.4BSD-Lite!
230- 
230 User ken logged in.
Remote system type is UNKNOWN.
ftp> dir
227 Entering Passive Mode (20,2,2,1,4,1)
150 Opening ASCII mode data connection for '/bin/ls'.
total 96
-rw-rw-r--  1 root  wheel   684 Mar  2 11:45 .cshrc
-rw-rw-r--  1 root  wheel   286 Mar  2 11:45 .profile
-rw-rw-r--  1 root  wheel  3425 Mar  2 11:45 COPYRIGHT
drwxrwxr-x  2 root  wheel   512 Mar  2 12:11 bin
drwxrwxr-x  3 root  wheel  1536 Mar  2 12:11 dev
drwxrwxr-x  3 root  wheel  1024 Mar  2 12:21 etc
drwxrwxr-x  2 root  wheel   512 Mar  2 12:11 home
drwxrwxr-x  2 root  wheel   512 Mar  2 12:26 root
drwxrwxr-x  2 root  wheel  1024 Mar  2 12:11 sbin
drwxrwxrwt  2 root  wheel   512 Mar  2 12:20 tmp
drwxrwxr-x  9 root  wheel   512 Mar  2 12:11 usr
drwxrwxr-x  7 root  wheel   512 Mar  2 12:11 var
226 Transfer complete.
ftp> _

You can also make outgoing FTP connections:

# ftp ftp.gnu.org.
Connected to ftp.gnu.org.
220 GNU FTP server ready.
Name (ftp.gnu.org.:root): ftp
230-...
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 

Application development

TCP/IP protocol and socket API were originally designed at Berkeley, and LiteBSD inherits the most authentic implementation of the networking stack. The classic book "UNIX Network Programming" Volume 1 by W. Richard Stevens is the best guide on network programming. Examples from this book are available on GitHub.

You can find the following articles useful as well:

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.