@@ -12,6 +12,7 @@ import (
1212)
1313
1414func TestParseTCP (t * testing.T ) {
15+ const isBE = false
1516 procNetTCP := ` sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
1617 0: 0100007F:8AEF 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 28152 1 0000000000000000 100 0 0 10 0
1718 1: 0103000A:0035 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 31474 1 0000000000000000 100 0 0 10 5
@@ -20,7 +21,7 @@ func TestParseTCP(t *testing.T) {
2021 4: 0100007F:053A 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 31430 1 0000000000000000 100 0 0 10 0
2122 5: 0B3CA8C0:0016 690AA8C0:F705 01 00000000:00000000 02:00028D8B 00000000 0 0 32989 4 0000000000000000 20 4 31 10 19
2223`
23- entries , err := Parse (strings .NewReader (procNetTCP ), TCP )
24+ entries , err := ParseWithEndian (strings .NewReader (procNetTCP ), TCP , isBE )
2425 assert .NilError (t , err )
2526 t .Log (entries )
2627
@@ -34,9 +35,10 @@ func TestParseTCP(t *testing.T) {
3435}
3536
3637func TestParseTCP6 (t * testing.T ) {
38+ const isBE = false
3739 procNetTCP := ` sl local_address remote_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
3840 0: 000080FE00000000FF57A6705DC771FE:0050 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 850222 1 0000000000000000 100 0 0 10 0`
39- entries , err := Parse (strings .NewReader (procNetTCP ), TCP6 )
41+ entries , err := ParseWithEndian (strings .NewReader (procNetTCP ), TCP6 , isBE )
4042 assert .NilError (t , err )
4143 t .Log (entries )
4244
@@ -46,12 +48,13 @@ func TestParseTCP6(t *testing.T) {
4648}
4749
4850func TestParseTCP6Zero (t * testing.T ) {
51+ const isBE = false
4952 procNetTCP := ` sl local_address remote_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
5053 0: 00000000000000000000000000000000:0016 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 33825 1 0000000000000000 100 0 0 10 0
5154 1: 00000000000000000000000000000000:006F 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 26772 1 0000000000000000 100 0 0 10 0
5255 2: 00000000000000000000000000000000:0050 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 1210901 1 0000000000000000 100 0 0 10 0
5356`
54- entries , err := Parse (strings .NewReader (procNetTCP ), TCP6 )
57+ entries , err := ParseWithEndian (strings .NewReader (procNetTCP ), TCP6 , isBE )
5558 assert .NilError (t , err )
5659 t .Log (entries )
5760
@@ -61,13 +64,14 @@ func TestParseTCP6Zero(t *testing.T) {
6164}
6265
6366func TestParseUDP (t * testing.T ) {
67+ const isBE = false
6468 procNetTCP := ` sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode ref pointer drops
6569 716: 3600007F:0035 00000000:0000 07 00000000:00000000 00:00000000 00000000 991 0 2964 2 0000000000000000 0
6670 716: 3500007F:0035 00000000:0000 07 00000000:00000000 00:00000000 00000000 991 0 2962 2 0000000000000000 0
6771 731: 0369A8C0:0044 00000000:0000 07 00000000:00000000 00:00000000 00000000 998 0 29132 2 0000000000000000 0
6872 731: 0F05A8C0:0044 00000000:0000 07 00000000:00000000 00:00000000 00000000 998 0 4049 2 0000000000000000 0
6973 1768: 00000000:1451 00000000:0000 07 00000000:00000000 00:00000000 00000000 502 0 28364 2 0000000000000000 0 `
70- entries , err := Parse (strings .NewReader (procNetTCP ), UDP )
74+ entries , err := ParseWithEndian (strings .NewReader (procNetTCP ), UDP , isBE )
7175 assert .NilError (t , err )
7276 t .Log (entries )
7377
@@ -79,6 +83,7 @@ func TestParseUDP(t *testing.T) {
7983func TestParseAddress (t * testing.T ) {
8084 tests := []struct {
8185 input string
86+ bigEndian bool
8287 expectedIP net.IP
8388 expectedPort uint16
8489 expectedErrSubstr string
@@ -88,13 +93,31 @@ func TestParseAddress(t *testing.T) {
8893 expectedIP : net .IPv4 (127 , 0 , 0 , 1 ),
8994 expectedPort : 80 ,
9095 },
96+ {
97+ input : "7F000001:0050" ,
98+ bigEndian : true ,
99+ expectedIP : net .IPv4 (127 , 0 , 0 , 1 ),
100+ expectedPort : 80 ,
101+ },
91102 {
92103 input : "000080FE00000000FF57A6705DC771FE:0050" ,
93104 expectedIP : net .ParseIP ("fe80::70a6:57ff:fe71:c75d" ),
94105 expectedPort : 80 ,
95106 },
107+ {
108+ input : "FE8000000000000070A657FFFE71C75D:0050" ,
109+ bigEndian : true ,
110+ expectedIP : net .ParseIP ("fe80::70a6:57ff:fe71:c75d" ),
111+ expectedPort : 80 ,
112+ },
113+ {
114+ input : "00000000000000000000000000000000:0050" ,
115+ expectedIP : net .IPv6zero ,
116+ expectedPort : 80 ,
117+ },
96118 {
97119 input : "00000000000000000000000000000000:0050" ,
120+ bigEndian : true ,
98121 expectedIP : net .IPv6zero ,
99122 expectedPort : 80 ,
100123 },
@@ -126,7 +149,7 @@ func TestParseAddress(t *testing.T) {
126149
127150 for _ , test := range tests {
128151 t .Run (test .input , func (t * testing.T ) {
129- ip , port , err := ParseAddress (test .input )
152+ ip , port , err := ParseAddressWithEndian (test .input , test . bigEndian )
130153 if test .expectedErrSubstr != "" {
131154 assert .ErrorContains (t , err , test .expectedErrSubstr )
132155 } else {
0 commit comments