MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / FindProtocol

Function FindProtocol

packet/decoder.go:12–33  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

10)
11
12func FindProtocol(p []byte) (layers.IPProtocol, error) {
13 version, err := FindIPVersion(p)
14 if err != nil {
15 return 0, err
16 }
17 switch version {
18 case 4:
19 if len(p) < ipv4MinHeaderLen {
20 return 0, fmt.Errorf("IPv4 packet should have at least %d bytes, got %d bytes", ipv4MinHeaderLen, len(p))
21 }
22 // Protocol is in the 10th byte of IPv4 header
23 return layers.IPProtocol(p[9]), nil
24 case 6:
25 if len(p) < ipv6HeaderLen {
26 return 0, fmt.Errorf("IPv6 packet should have at least %d bytes, got %d bytes", ipv6HeaderLen, len(p))
27 }
28 // Next header is in the 7th byte of IPv6 header
29 return layers.IPProtocol(p[6]), nil
30 default:
31 return 0, fmt.Errorf("unknown ip version %d", version)
32 }
33}
34
35func FindIPVersion(p []byte) (uint8, error) {
36 if len(p) == 0 {

Callers

nothing calls this directly

Calls 2

FindIPVersionFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected