Skip to content

anyu/tcp-in-a-weekend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tcp-in-a-weekend

Implementation of the following in Go:

  • ping utility
  • UDP protocol
  • TCP protocol

Setup

From a Linux VM (eg. OrbStack - ubuntu)

  1. Install dependencies

    # Install tools
    $ sudo apt install -y iptables lsof
    
    # Install Go
    $ wget -O /tmp/go.tar.gz $LINK_TO_GO_BINARY (https://go.dev/dl)
    
    # Untar, add to path
    $ tar -C /usr/local -xzf /tmp/go.tar.gz
    $ export PATH=$PATH:/usr/local/go/bin
    
    # Confirm installation successful
    $ go version
    
  2. Run a local server at: 192.0.2.1:8080

    $ python3 -m http.server --bind 192.0.2.1 8080
  3. Run setup script to create a network tunnel (tun0) and set up NAT

    bash setup.sh

Usage

Ping

go run cmd/ping/main.go 192.0.2.1

go run cmd/ping/main.go -c 3 192.0.2.1

UDP

go run cmd/udp/main.go 8.8.8.8

TCP

go run cmd/tcp/main.go 192.0.2.1

Linux VM options

Debugging

  1. tcpdump

    sudo tcpdump -ni tun0
    
    sudo tcpdump -ni tun0 host 192.0.2.1
  2. tshark (terminal Wireshark)

    sudo tshark -f "tcp port 12345" -i tun0 -w dump.pcap

    Open dump.pcap in Wireshark.

  3. nc

    nc -l 192.0.2.1 8080

About

ping, UDP, TCP implementations in Go

Resources

Stars

Watchers

Forks