A couple of comments would go a long way to making this more understandable. Something like:
```ruby
# Add the route data to the packet, prepended with its length (minus 4 for the ... )
ni_packet << [route_data.length - 4, route_data].pack('NA*')
# Now that we've built the whole packet, prepend its length before writing it to the wire
ni_packet = [ni_packet.length].pack('N') + ni_packet
```

Assuming my comments are not lies, of course.