MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / parseIPCIDR

Function parseIPCIDR

pkg/api/network_interfaces.go:262–285  ·  view source on GitHub ↗

parseIPCIDR parses an IP address string with CIDR notation.

(ipCIDR string, ipType string)

Source from the content-addressed store, hash-verified

260
261// parseIPCIDR parses an IP address string with CIDR notation.
262func parseIPCIDR(ipCIDR string, ipType string) (IPAddress, bool) {
263 if ipCIDR == "" {
264 return IPAddress{}, false
265 }
266
267 parts := strings.Split(ipCIDR, "/")
268 if len(parts) == 0 {
269 return IPAddress{}, false
270 }
271
272 ipAddr := IPAddress{Type: ipType}
273 ipAddr.Address = parts[0]
274
275 if len(parts) == 2 {
276 prefix, err := parseInt(parts[1]) // Assuming you have a helper like strconv.Atoi or similar
277 if err == nil {
278 ipAddr.Prefix = prefix
279 }
280 // Could log an error here if prefix parsing fails but IP is present
281 // For now, we still consider it a valid IP, just without a prefix
282 }
283
284 return ipAddr, true
285}
286
287// Helper function to parse int, assuming it might be missing in this context
288// For a real scenario, use strconv.Atoi.

Callers 1

GetLxcInterfacesMethod · 0.85

Calls 1

parseIntFunction · 0.85

Tested by

no test coverage detected