Debian Codegraph @

lang/core/net/cidr_to_ip_func.go

raw symbols SCIP
1 // Mgmt
2 // Copyright (C) 2013-2024+ James Shubin and the project contributors
3 // Written by James Shubin <[email protected]> and the project contributors
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <https://www.gnu.org/licenses/>.
17 //
18 // Additional permission under GNU GPL version 3 section 7
19 //
20 // If you modify this program, or any covered work, by linking or combining it
21 // with embedded mcl code and modules (and that the embedded mcl code and
22 // modules which link with this program, contain a copy of their source code in
23 // the authoritative form) containing parts covered by the terms of any other
24 // license, the licensors of this program grant you additional permission to
25 // convey the resulting work. Furthermore, the licensors of this program grant
26 // the original author, James Shubin, additional permission to update this
27 // additional permission if he deems it necessary to achieve the goals of this
28 // additional permission.
29
30 package corenetscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/core/net`/
31
32 import (
33 "contextscip-go gomod github.com/golang/go/src go1.21 context/"
34 "netscip-go gomod github.com/golang/go/src go1.21 net/"
35 "stringsscip-go gomod github.com/golang/go/src go1.21 strings/"
36
37 "github.com/purpleidea/mgmt/lang/funcs/simplescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/"
38 "github.com/purpleidea/mgmt/lang/typesscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/"
39 )
40
41 func initscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/core/net`/init().() {
42 simplescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/.ModuleRegisterscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/ModuleRegister().(ModuleNamescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/core/net`/ModuleName., "cidr_to_ip", &simplescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/.Scaffoldscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/Scaffold#{
43 Tscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/Scaffold#T.: typesscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/.NewTypescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/NewType().("func(a str) str"),
44 Fscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/Scaffold#F.: CidrToIPscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/core/net`/CidrToIP().,
45 })
46 simplescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/.ModuleRegisterscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/ModuleRegister().(ModuleNamescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/core/net`/ModuleName., "cidr_to_mask", &simplescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/.Scaffoldscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/Scaffold#{
47 Tscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/Scaffold#T.: typesscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/.NewTypescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/NewType().("func(a str) str"),
48 Fscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/funcs/simple`/Scaffold#F.: CidrToMaskscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/core/net`/CidrToMask().,
49 })
50 }
51
52 // CidrToIP returns the IP from a CIDR address.
53 func CidrToIPscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/core/net`/CidrToIP().(ctx contextscip-go gomod github.com/golang/go/src go1.21 context/.Contextscip-go gomod github.com/golang/go/src go1.21 context/Context#, input []typesscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/.Valuescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/Value#) (typesscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/.Valuescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/Value#, error) {
54 cidr := input[0].Strscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/Value#Str.()
55 ip, _, err := netscip-go gomod github.com/golang/go/src go1.21 net/.ParseCIDRscip-go gomod github.com/golang/go/src go1.21 net/ParseCIDR().(stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.21 strings/TrimSpace().(cidr))
56 if err != nil {
57 return nil, err
58 }
59 return &typesscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/.StrValuescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/StrValue#{
60 Vscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/StrValue#V.: ip.Stringscip-go gomod github.com/golang/go/src go1.21 net/IP#String().(),
61 }, nil
62 }
63
64 // CidrToMask returns the subnet mask from a CIDR address.
65 func CidrToMaskscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/core/net`/CidrToMask().(ctx contextscip-go gomod github.com/golang/go/src go1.21 context/.Contextscip-go gomod github.com/golang/go/src go1.21 context/Context#, input []typesscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/.Valuescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/Value#) (typesscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/.Valuescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/Value#, error) {
66 cidr := input[0].Strscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/Value#Str.()
67 _, ipnet, err := netscip-go gomod github.com/golang/go/src go1.21 net/.ParseCIDRscip-go gomod github.com/golang/go/src go1.21 net/ParseCIDR().(stringsscip-go gomod github.com/golang/go/src go1.21 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.21 strings/TrimSpace().(cidr))
68 if err != nil {
69 return nil, err
70 }
71 return &typesscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/.StrValuescip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/StrValue#{
72 Vscip-go gomod github.com/purpleidea/mgmt . `github.com/purpleidea/mgmt/lang/types`/StrValue#V.: netscip-go gomod github.com/golang/go/src go1.21 net/.IPscip-go gomod github.com/golang/go/src go1.21 net/IP#(ipnet.Maskscip-go gomod github.com/golang/go/src go1.21 net/IPNet#Mask.).Stringscip-go gomod github.com/golang/go/src go1.21 net/IP#String().(),
73 }, nil
74 }