water/params.json
2013-03-25 19:03:33 -07:00

1 line
No EOL
3.2 KiB
JSON

{"name":"Water","tagline":"A simple TUN/TAP library written in native Go.","body":"# water\r\n`water` is a native Go library for [TUN/TAP](http://en.wikipedia.org/wiki/TUN/TAP) interfaces.\r\n\r\n`water` is designed to be simple and efficient. It\r\n\r\n* wraps almost only syscalls and uses only Go standard types;\r\n* exposes standard interfaces; plays well with standard packages like `io`, `bufio`, etc..\r\n* does not handle memory management (allocating/destructing slice). It's up to user to decide how to deal with buffers; whether to use GC.\r\n\r\n`water/waterutil` has some useful functions to interpret MAC farme headers and IP packet headers. It also contains some constants such as protocol numbers and ethernet frame types.\r\n\r\n## Installation\r\n```\r\ngo get -u github.com/songgao/water\r\ngo get -u github.com/songgao/water/waterutil\r\n```\r\n\r\n## Documentation\r\n[http://godoc.org/github.com/songgao/water](http://godoc.org/github.com/songgao/water)\r\n\r\n[http://godoc.org/github.com/songgao/water/waterutil](http://godoc.org/github.com/songgao/water/waterutil)\r\n\r\n## Example\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"github.com/songgao/water\"\r\n\t\"github.com/songgao/water/waterutil\"\r\n\t\"fmt\"\r\n)\r\n\r\nconst BUFFERSIZE = 1522\r\n\r\nfunc main() {\r\n\tifce, err := water.NewTAP(\"\")\r\n\tfmt.Printf(\"%v, %v\\n\\n\", err, ifce)\r\n\tbuffer := make([]byte, BUFFERSIZE)\r\n\tfor {\r\n\t\t_, err = ifce.Read(buffer)\r\n\t\tif err != nil {\r\n\t\t\tbreak\r\n\t\t}\r\n\t\tethertype := waterutil.MACEthertype(buffer)\r\n\t\tif ethertype == waterutil.IPv4 {\r\n\t\t\tpacket := waterutil.MACPayload(buffer)\r\n\t\t\tif waterutil.IsIPv4(packet) {\r\n\t\t\t\tfmt.Printf(\"Source: %v [%v]\\n\", waterutil.MACSource(buffer), waterutil.IPv4Source(packet))\r\n\t\t\t\tfmt.Printf(\"Destination: %v [%v]\\n\", waterutil.MACDestination(buffer), waterutil.IPv4Destination(packet))\r\n\t\t\t\tfmt.Printf(\"Protocol: %v\\n\\n\", waterutil.IPv4Protocol(packet))\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\nThis piece of code creates a `TAP` interface, and prints some header information for every IPv4 packet. After pull up the `main.go`, you'll need to bring up the interface and assign IP address. All of these need root permission.\r\n\r\n```bash\r\nsudo go run main.go\r\n```\r\n\r\n```bash\r\nsudo ip link set dev tap0 up\r\nsudo ip addr add 10.0.0.1/24 dev tap0\r\n```\r\n\r\nNow, try sending some ICMP broadcast message:\r\n```bash\r\nping -b 10.0.0.255\r\n```\r\n\r\nYou'll see the `main.go` print something like:\r\n```\r\n<nil>, &{true 0xf84003f058 tap0}\r\n\r\nSource: 42:35:da:af:2b:00 [10.0.0.1]\r\nDestination: ff:ff:ff:ff:ff:ff [10.0.0.255]\r\nProtocol: 1\r\n\r\nSource: 42:35:da:af:2b:00 [10.0.0.1]\r\nDestination: ff:ff:ff:ff:ff:ff [10.0.0.255]\r\nProtocol: 1\r\n\r\nSource: 42:35:da:af:2b:00 [10.0.0.1]\r\nDestination: ff:ff:ff:ff:ff:ff [10.0.0.255]\r\nProtocol: 1\r\n```\r\n\r\n## TODO\r\n* IPv6 Support in `waterutil`\r\n* Darwin(Mac) Support\r\n\r\n## LICENSE\r\nGNU LESSER GENERAL PUBLIC LICENSE Version 3\r\n\r\n## Alternatives\r\n`tuntap`: [https://code.google.com/p/tuntap/](https://code.google.com/p/tuntap/)\r\n","google":"UA-39596175-1","note":"Don't delete this file! It's used internally to help with page regeneration."}