lemontree55 / packetgen

Ruby library to easily generate and capture network packets
MIT License
98 stars 13 forks source link

Header::Base.bind_header is messy #88

Closed sdaubert closed 6 years ago

sdaubert commented 6 years ago

Current beahviour is merely broken: :op keyword change how to handle multiple fields. But adding others bindings through others calls to .bind_header breaks that as these calls use first defined :op, and not operator define by these calls.

sdaubert commented 6 years ago

.bind_header is messy but cannot break compatibility out of major version.

An idea is to deprecate it and create a new API to bin headers to other ones. This new API should be simpler. First idea:

Examples:

IP.bind IGMP, protocol: 2, frag: 0, ttl: 1, tos: ->(v) { v.nil? 0 : v != 0xc0 }

Will bind IGMP to IP if, and only if, IP protocol is 2, IP frag field is 0, IP TTL is 1 and TOS is not 0xc0.

TCP.bind DNS, dport: 53
TCP.bind DNS, sport: 53

Will bind DNS to TCP if TCP destionation port is 53 or TCP source port is 53.

UDP.bind BOOTP, sport: 67, dport: 68
UDP.bind BOOTP, sport: 68, dport: 67

Will bind BOOTP to UDP if UDP source port is 67 and UDP destination port is 68. Will also bind BOOTP to UDP if UDP source port is 68 and UDP destination port is 67.