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
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| ) | |
| type Video struct { | |
| Name string | |
| } |
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
| require 'socket' | |
| BUFFER_SIZE = 1024 | |
| socket = UDPSocket.new | |
| socket.bind('192.168.33.10', 4321) | |
| loop do | |
| message, sender = socket.recvfrom(BUFFER_SIZE) |
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
| socket = Socket.new(:INET, :DGRAM) |
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
| require 'socket' | |
| # Size in bytes of a C `ifreq` structure on a 64-bit system | |
| # http://man7.org/linux/man-pages/man7/netdevice.7.html | |
| # | |
| # struct ifreq { | |
| # char ifr_name[IFNAMSIZ]; /* Interface name */ | |
| # union { | |
| # struct sockaddr ifr_addr; | |
| # struct sockaddr ifr_dstaddr; |
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
| # Receive every packet | |
| ETH_P_ALL = 0x0300 | |
| # Size in bytes of a C `sockaddr_ll` structure on a 64-bit system | |
| # | |
| # struct sockaddr_ll { | |
| # unsigned short sll_family; /* Always AF_PACKET */ | |
| # unsigned short sll_protocol; /* Physical-layer protocol */ | |
| # int sll_ifindex; /* Interface number */ | |
| # unsigned short sll_hatype; /* ARP hardware type */ |
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
| require 'hexdump' | |
| BUFFER_SIZE = 1024 | |
| loop do | |
| data = socket.recv(BUFFER_SIZE) | |
| Hexdump.dump(data) | |
| end |
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
| class EthernetFrame | |
| attr_reader :bytes | |
| def initialize(bytes) | |
| @bytes = bytes | |
| end | |
| def destination_mac | |
| format_mac(bytes[0, 6]) | |
| end |
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
| def data | |
| # Drop the first 14 bytes (MAC Header) and last 4 bytes (CRC Checksum) | |
| IPPacket.new(bytes[14...-4]) | |
| end |
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
| class IPPacket | |
| attr_reader :bytes | |
| def initialize(bytes) | |
| @bytes = bytes | |
| end | |
| def version | |
| bytes[0] >> 4 | |
| end |
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
| def ihl | |
| bytes[0] & 0xF | |
| end |