{"id":18163910,"url":"https://github.com/terassyi/gotcp","last_synced_at":"2025-05-08T20:38:25.497Z","repository":{"id":53784401,"uuid":"286265495","full_name":"terassyi/gotcp","owner":"terassyi","description":"tcp/ip protocol stack implememtation with golang for learning purpose","archived":false,"fork":false,"pushed_at":"2021-03-14T15:49:22.000Z","size":208,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T18:04:27.727Z","etag":null,"topics":["golang","network","protocol-stack","tcp"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/terassyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-09T15:37:06.000Z","updated_at":"2025-01-19T01:13:03.000Z","dependencies_parsed_at":"2022-09-02T08:42:37.681Z","dependency_job_id":null,"html_url":"https://github.com/terassyi/gotcp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terassyi%2Fgotcp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terassyi%2Fgotcp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terassyi%2Fgotcp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terassyi%2Fgotcp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/terassyi","download_url":"https://codeload.github.com/terassyi/gotcp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253146893,"owners_count":21861488,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","network","protocol-stack","tcp"],"created_at":"2024-11-02T11:06:30.990Z","updated_at":"2025-05-08T20:38:25.471Z","avatar_url":"https://github.com/terassyi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gotcp\nGotcp is user space tcp/ip protocol stack implementation by golang for learing purpose.\nThis project is inspired by [microps](https://github.com/pandax381/microps)\n\n## Features\nGotcp work on Linux only. To run this, You have to be root.\nSupported protocol is berow.\n- Ethernet\n\t- tuntap\n\t- ap_packet\n- ARP\n- IPv4\n- ICMP\n- TCP\n\n## Tutorial\nYou can run Gotcp with virtual machines or docker containers.\n\n### Environment\n#### Virtual machine\nI prepare the virtual machines in `vm/`. You can setup vm via Vagrant.\n\n#### Container\nI also prepare `docker-compose.yml`. This way is easier than using virtual machines.\n\n### Run\nTo buil this, execute `go build .`\n\nI prepare some command to run sample application.\n```shell\n./gotcp help\nUsage: gotcp \u003cflags\u003e \u003csubcommand\u003e \u003csubcommand args\u003e\n\nSubcommands:\n        commands         list all command names\n        dump             dump\n        flags            describe all known top-level flags\n        help             describe subcommands and their syntax\n        ids              ids\n        ping             ping\n        tcpclient        tcp client\n        tcpserver        tcp server\n```\n\n#### ping\n```shell\n# ./gotcp ping -h\ngoctp ping -i \u003cinterface name\u003e -dest \u003cdestination address\u003e:\n        send icmp echo request packets and receive reply packets  -debug\n        output debug messages\n  -dest string\n        destination address\n  -i string\n        interface\n```\n```shell\n# ./gotcp ping -i eth0 -dest 172.20.0.3\n172.20.0.3\n47 bytes from 172.20.0.3: icmp_seq=0 ttl=64 time=%!f(int64=6953) ms\n47 bytes from 172.20.0.3: icmp_seq=0 ttl=64 time=%!f(int64=1011073) ms\n47 bytes from 172.20.0.3: icmp_seq=0 ttl=64 time=%!f(int64=2013006) ms\n47 bytes from 172.20.0.3: icmp_seq=0 ttl=64 time=%!f(int64=3018657) ms\n47 bytes from 172.20.0.3: icmp_seq=0 ttl=64 time=%!f(int64=4019847) ms\n47 bytes from 172.20.0.3: icmp_seq=0 ttl=64 time=%!f(int64=5020866) ms\n\n```\n\n#### tcp client\nYou can run a sample tcp client application.\n```shell\n# ./gotcp tcpclient -h\ngotcp tcpclient -i \u003cinterface name\u003e -addr \u003cip address\u003e -port \u003cport\u003e\n        tcp client to destination host  -addr string\n        destination host address\n  -debug\n        output debug message\n  -i string\n        interface name\n  -port int\n        destination host port\n```\nBefore running this application, you have to execute these commands on the client and server side.\n\n- server\n\t```shell\n\t$ ethtool -K eth0 tso off gso off # stop kernel nic offloading\n\t$ cd app/standard/tcp-server-big\n\t$ go run main.go # run server program\n\t```\n- client\n\t```shell\n\t$ mkdir data\n\t$ head -c 20000 /dev/urandom \u003e data/random-data # generate random data\n\t$ iptables -A OUTPUT -p tcp --dport 8888 -j DROP # stop processing packets by kernel\n\t$ ./gotcp tcpclient -debug -i eth0 -addr 172.20.0.3 -port 8888 # run gotcp tcpclient\n\t```\nlog\n```\nINFO[0000] tcp server running at 8888                    command=\"tcp client\"\nINFO[0000] [start to listen]                             protocol=tcp\nDEBU[0000] [LISTEN]                                      protocol=tcp\nDEBU[0003] [SYN_RECVD]                                   protocol=tcp\nDEBU[0003] [ESTABLISHED]                                 protocol=tcp\nDEBU[0003] [retransmission routine start ]               protocol=tcp\nServer\u003e Connection from 172.20.0.3:8888\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 208 bytes\nServer\u003e recv all buf 21720 bytes\nServer\u003e Write 20272 bytes\nDEBU[0008] [CLOSE_WAIT]                                  protocol=tcp\nDEBU[0008] [LAST_ACK]                                    protocol=tcp\nDEBU[0008] [CLOSED]                                      protocol=tcp\nINFO[0008] [received packet is not handled. invalid peer.]  protocol=tcp\nServer\u003e close\n```\n\n#### tcp server\nYou can run a sample tcp server application.\n```shell\n$ ./gotcp tcpserver -h\ngotcp tcpserver -i \u003cinterface name\u003e -port \u003cport\u003e\n        tcp server binding port  -debug\n        output debug message\n  -i string\n        interface\n  -port int\n        binding port\n```\nBefor you run this application, you have to execute these commands.\n- server\n\t```shell\n\t$ iptables -A INPUT -p tcp --dport 4000:65000 -j DROP # stop packets processing by kernel\n\t$ ./gotcp tcpserver -debug -i eth0 -port 8888\n\t```\n- client\n\t```shell\n\t$ ethtool -K eth0 tso off gso off # stop kernel nic offloading\n\t$ cd app/standard/tcp-client-big\n\t$ go run main.go # run client program\n\t```\n\nlog\n```\nINFO[0000] tcp server running at 8888                    command=\"tcp client\"\nINFO[0000] [start to listen]                             protocol=tcp\nDEBU[0000] [LISTEN]                                      protocol=tcp\nDEBU[0004] [SYN_RECVD]                                   protocol=tcp\nDEBU[0005] [ESTABLISHED]                                 protocol=tcp\nDEBU[0005] [retransmission routine start ]               protocol=tcp\nServer\u003e Connection from 172.20.0.3:8888\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 1448 bytes\nServer\u003e Read 208 bytes\nServer\u003e recv all buf 21720 bytes\nServer\u003e Write 20272 bytes\nDEBU[0015] [CLOSED]                                      protocol=tcp\nServer\u003e close\n```\n\n## License\nGotcp is under the MIT License: See [LICENSE](./LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterassyi%2Fgotcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterassyi%2Fgotcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterassyi%2Fgotcp/lists"}