MCPcopy Create free account
hub / github.com/prometheus/procfs / parseIP

Function parseIP

net_ip_socket.go:140–160  ·  view source on GitHub ↗

the /proc/net/{t,u}dp{,6} files are network byte order for ipv4 and for ipv6 the address is four words consisting of four bytes each. In each of those four words the four bytes are written in reverse order.

(hexIP string)

Source from the content-addressed store, hash-verified

138// the /proc/net/{t,u}dp{,6} files are network byte order for ipv4 and for ipv6 the address is four words consisting of four bytes each. In each of those four words the four bytes are written in reverse order.
139
140func parseIP(hexIP string) (net.IP, error) {
141 var byteIP []byte
142 byteIP, err := hex.DecodeString(hexIP)
143 if err != nil {
144 return nil, fmt.Errorf("%w: Cannot parse socket field in %q: %w", ErrFileParse, hexIP, err)
145 }
146 switch len(byteIP) {
147 case 4:
148 return net.IP{byteIP[3], byteIP[2], byteIP[1], byteIP[0]}, nil
149 case 16:
150 i := net.IP{
151 byteIP[3], byteIP[2], byteIP[1], byteIP[0],
152 byteIP[7], byteIP[6], byteIP[5], byteIP[4],
153 byteIP[11], byteIP[10], byteIP[9], byteIP[8],
154 byteIP[15], byteIP[14], byteIP[13], byteIP[12],
155 }
156 return i, nil
157 default:
158 return nil, fmt.Errorf("%w: Unable to parse IP %s: %v", ErrFileParse, hexIP, nil)
159 }
160}
161
162// parseNetIPSocketLine parses a single line, represented by a list of fields.
163func parseNetIPSocketLine(fields []string, isUDP bool) (*netIPSocketLine, error) {

Callers 1

parseNetIPSocketLineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…