Created
September 27, 2017 12:38
-
-
Save nonylene/4360c9be3495fcfee24cfeb025506fe4 to your computer and use it in GitHub Desktop.
raw-socket.nim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import net | |
| import system | |
| import strutils | |
| import nativesockets | |
| proc main(): int = | |
| let socket = net.newSocket(AF_INET, SOCK_RAW, IPPROTO_TCP) | |
| socket.bindAddr(address="127.0.0.1") | |
| # IPPROTO_IP, IP_HDRINCL, true | |
| socket.getFd.setSockOptInt(0, 3, 1) | |
| while true: | |
| let str = socket.recv(size=1)[0] | |
| discard socket.sendTo("127.0.0.1", net.Port(0), "1111111111111111") | |
| echo $strutils.toBin(ord(str), 8) & " " & $ord(str) | |
| return 0 | |
| system.quit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Linux
windows