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

Function parseIPPort

ipvs.go:209–241  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

207}
208
209func parseIPPort(s string) (net.IP, uint16, error) {
210 var (
211 ip net.IP
212 err error
213 )
214
215 switch len(s) {
216 case 13:
217 ip, err = hex.DecodeString(s[0:8])
218 if err != nil {
219 return nil, 0, err
220 }
221 case 46:
222 ip = net.ParseIP(s[1:40])
223 if ip == nil {
224 return nil, 0, fmt.Errorf("%w: Invalid IPv6 addr %s: %w", ErrFileParse, s[1:40], err)
225 }
226 default:
227 return nil, 0, fmt.Errorf("%w: Unexpected IP:Port %s: %w", ErrFileParse, s, err)
228 }
229
230 portString := s[len(s)-4:]
231 if len(portString) != 4 {
232 return nil, 0,
233 fmt.Errorf("%w: Unexpected port string format %s: %w", ErrFileParse, portString, err)
234 }
235 port, err := strconv.ParseUint(portString, 16, 16)
236 if err != nil {
237 return nil, 0, err
238 }
239
240 return ip, uint16(port), nil
241}

Callers 4

parseIPVSBackendStatusFunction · 0.85
TestParseIPPortFunction · 0.85
TestParseIPPortInvalidFunction · 0.85
TestParseIPPortIPv6Function · 0.85

Calls

no outgoing calls

Tested by 3

TestParseIPPortFunction · 0.68
TestParseIPPortInvalidFunction · 0.68
TestParseIPPortIPv6Function · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…