a_test NetworkStackTests:android.net.apf.ApfTest

https://en.wikipedia.org/wiki/Internet_Protocol_version_4

IPv4 header format
+---------+-------+---------------------------------------+---------------------------------------+---------------------------------------+---------------------------------------+
| Offsets | Octet |                   0                   |                   1                   |                   2                   |                   3                   |
|  Octet  |  Bit  |  0 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+---------+-------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|    0    |   0   | Version [4]       | IHL [>=5]         | DSCP                        | ECN     | Total length [>=20, >=4*IHL]                                                  |
+---------+-------+-------------------+-------------------+-----------------------------+---------+----+----+----+----------------------------------------------------------------+
|    4    |  32   | Identification                                                                |  0 | DF | MF | Fragment offset                                                |
+---------+-------+---------------------------------------+---------------------------------------+----+----+----+----------------------------------------------------------------+
|    8    |  64   | Time to Live                          | Protocol                              | Header checksum                                                               |
+---------+-------+---------------------------------------+---------------------------------------+-------------------------------------------------------------------------------+
|   12    |  96   | Source address                                                                                                                                                |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
|   16    | 128   | Destination address                                                                                                                                           |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
|   20    | 160   | Options (if IHL > 5)                                                                                                                                          |
|   ..    | ...   |                                                                                                                                                               |
|   56    | 448   |                                                                                                                                                               |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+

https://en.wikipedia.org/wiki/IPv6_packet

Fixed header format
+---------+-------+---------------------------------------+---------------------------------------+---------------------------------------+---------------------------------------+
| Offsets | Octet |                   0                   |                   1                   |                   2                   |                   3                   |
|  Octet  |  Bit  |  0 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+---------+-------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|    0    |   0   | Version [6]       | Traffic class (DSCP 6 + ECN 2 bits)   | Flow label                                                                                        |
+---------+-------+-------------------+---------------------------------------+-------------------+---------------------------------------+---------------------------------------+
|    4    |  32   | Payload length                                                                | Next header                           | Hop limit                             |
+---------+-------+-------------------------------------------------------------------------------+---------------------------------------+---------------------------------------+
|    8    |  64   | Source Address                                                                                                                                                |
|   12    |  96   |                                                                                                                                                               |
|   16    | 128   |                                                                                                                                                               |
|   20    | 160   |                                                                                                                                                               |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
|   24    | 192   | Destination address                                                                                                                                           |
|   28    | 224   |                                                                                                                                                               |
|   32    | 256   |                                                                                                                                                               |
|   36    | 288   |                                                                                                                                                               |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+

https://en.wikipedia.org/wiki/ICMPv6

ICMPv6 header (4 bytes): u8 type, u8 code, u16 checksum
(4 bytes in) Message body...  (but note in practice it's actually 4 bytes reserved, then 'real' message body at 8 bytes in)

https://en.wikipedia.org/wiki/Transmission_Control_Protocol

TCP segment header
+---------+-------+---------------------------------------+---------------------------------------+---------------------------------------+---------------------------------------+
| Offsets | Octet |                   0                   |                   1                   |                   2                   |                   3                   |
|  Octet  |  Bit  |  0 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+---------+-------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|    0    |   0   | Source port                                                                   | Destination port                                                              |
+---------+-------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------+
|    4    |  32   | Sequence number                                                                                                                                               |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
|    8    |  64   | Acknowledgment number (if ACK set)                                                                                                                            |
+---------+-------+-------------------+-------------------+----+----+----+----+----+----+----+----+-------------------------------------------------------------------------------+
|   12    |  96   | Data Offset       | Reserved (zero)   | CWR| ECE| URG| ACK| PSH| RST| SYN| FIN| Window size                                                                   |
+---------+-------+-------------------+-------------------+----+----+----+----+----+----+----+----+-------------------------------------------------------------------------------+
|   16    | 128   | Checksum                                                                      | Urgent pointer (if URG set)                                                   |
+---------+-------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------+
|   20    | 160   | Options (if data offset > 5. Padded at the end with "0" bits if necessary.)                                                                                   |
|   ..    | ...   |                                                                                                                                                               |
|   56    | 448   |                                                                                                                                                               |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+

https://en.wikipedia.org/wiki/User_Datagram_Protocol

UDP datagram header (8 bytes): be16 source port, destination port, length, checksum
+---------+-------+---------------------------------------+---------------------------------------+---------------------------------------+---------------------------------------+
| Offsets | Octet |                   0                   |                   1                   |                   2                   |                   3                   |
|  Octet  |  Bit  |  0 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+---------+-------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
|    0    |   0   | Source port                                                                   | Destination port                                                              |
+---------+-------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------+
|    4    |  32   | Length                                                                        | Checksum                                                                      |
+---------+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+

root@athina:~# tcpdump -i eth0 -c 1 -s 65536 -ee -vv -XX 2>/dev/null | sed -r $'s@^\t0x[0-9a-f]{4}:  (([0-9a-f]{4} ){0,7}[0-9a-f]{2,4}) .*$@\\1@'

64:87:88:fd:6d:f0 (oui Unknown) > a0:8c:fd:e1:f3:70 (oui Unknown), ethertype IPv6 (0x86dd), length 86: (class 0x20, flowlabel 0xaaab2, hlim 108, next-header TCP (6) payload length: 32) dl-in-f168.1e100.net.5031 > 2620:15c:211:200:7981:81a3:c51b:662c.35954: Flags [.], cksum 0x4d75 (correct), seq 3375638517, ack 3821395769, win 379, options [nop,nop,TS val 4243925517 ecr 1682148025], length 0

a08c fde1 f370 6487 88fd 6df0 86dd 620a
aab2 0020 066c 2607 f8b0 4023 0c0d 0000
0000 0000 00a8 2620 015c 0211 0200 7981
81a3 c51b 662c 13a7 8c72 c934 27f5 e3c5
df39 8010 017b 4d75 0000 0101 080a fcf5
2a0d 6443 8ab9

tcpdump -i eth0 -c 1 -s 65536 -ee -vv -XX 2>/dev/null | sed -r $'s@^\t0x[0-9a-f]{4}:  (([0-9a-f]{4} ){0,7}[0-9a-f]{2,4}) .*$@\\1@' | sed -r '/:/!s@ @@g'

Change-Id: I35d23556a0e864c9f2d3982f39f6b32db87d0eb6
4 files changed