| Class | Racket::L3::IPv4 |
| In: |
lib/racket/l3/ipv4.rb
(CVS)
|
| Parent: | RacketPart |
Internet Protcol Version 4 (IPV4)
RFC791 (www.ietf.org/rfc/rfc791.txt)
| Checksum | Checksum | |
| checksum | Checksum | |
| dst_ip | Destination IP address, passed as four octets separated by periods (192.168.1.2) | |
| flags | Flags | |
| foffset | Fragmentation offset | |
| hlen | Header length in multiples of 4 octets (defaults to 5) | |
| id | Identifier | |
| len | Datagram length | |
| payload | Payload | |
| protocol | Protocol | |
| src_ip | Source IP address, passed as four octets separated by periods (192.168.1.2) | |
| tos | Type of Service | |
| ttl | Time-to-live | |
| version | Version (defaults to 4) |
Compute and set the checksum for this IP datagram
# File lib/racket/l3/ipv4.rb, line 85 def checksum! self.checksum = compute_checksum end
Check the checksum for this IP datagram
# File lib/racket/l3/ipv4.rb, line 80 def checksum? self.checksum == compute_checksum end
Perform all the niceties necessary prior to sending this IP datagram out. Append the options, update len and hlen, and fix the checksum.
# File lib/racket/l3/ipv4.rb, line 92 def fix! newpayload = @options.join # pad to a multiple of 32 bits if (newpayload.length % 4 != 0) # fill the beginning as needed with NOPs while (newpayload.length % 4 != 3) newpayload = "\x01#{newpayload}" end # make sure the last byte is an EOL if (newpayload.length % 4 == 3) newpayload += "\x00" end end self.payload = newpayload + self.payload self.hlen += newpayload.length/4 self.len = self.payload.length + self.class.bit_length/8 self.checksum! end