MCPcopy
hub / github.com/windtf/wireproxy / parseCIDRNetIP

Function parseCIDRNetIP

config.go:177–207  ·  view source on GitHub ↗
(section *ini.Section, keyName string)

Source from the content-addressed store, hash-verified

175}
176
177func parseCIDRNetIP(section *ini.Section, keyName string) ([]netip.Addr, error) {
178 key, err := parseString(section, keyName)
179 if err != nil {
180 if strings.Contains(err.Error(), "should not be empty") {
181 return []netip.Addr{}, nil
182 }
183 return nil, err
184 }
185
186 keys := strings.Split(key, ",")
187 var ips = make([]netip.Addr, 0, len(keys))
188 for _, str := range keys {
189 str = strings.TrimSpace(str)
190 if len(str) == 0 {
191 continue
192 }
193
194 if addr, err := netip.ParseAddr(str); err == nil {
195 ips = append(ips, addr)
196 } else {
197 prefix, err := netip.ParsePrefix(str)
198 if err != nil {
199 return nil, err
200 }
201
202 addr := prefix.Addr()
203 ips = append(ips, addr)
204 }
205 }
206 return ips, nil
207}
208
209func parseAllowedIPs(section *ini.Section) ([]netip.Prefix, error) {
210 key, err := parseString(section, "AllowedIPs")

Callers 1

ParseInterfaceFunction · 0.85

Calls 1

parseStringFunction · 0.85

Tested by

no test coverage detected