github.com/gotranspile/cxgo@v0.3.8-0.20240118201721-29871598a6a2/libs/arpa_inet.go (about) 1 package libs 2 3 import ( 4 "github.com/gotranspile/cxgo/runtime/cnet" 5 "github.com/gotranspile/cxgo/types" 6 ) 7 8 // https://pubs.opengroup.org/onlinepubs/000095399/basedefs/arpa/inet.h.html 9 10 const ( 11 arpaInetH = "arpa/inet.h" 12 ) 13 14 func init() { 15 RegisterLibrary(arpaInetH, func(c *Env) *Library { 16 inAddrT := types.NamedTGo("in_addr_t", "cnet.Addr", types.UintT(8)) 17 inPortT := types.NamedTGo("in_port_t", "cnet.Port", types.UintT(4)) 18 inAddr := types.NamedTGo("in_addr", "cnet.Address", types.StructT([]*types.Field{ 19 {Name: types.NewIdentGo("s_addr", "Addr", types.UintT(4))}, 20 })) 21 sockLenT := types.UintT(4) 22 strT := c.C().String() 23 gstrT := c.Go().String() 24 return &Library{ 25 Imports: map[string]string{ 26 "cnet": RuntimePrefix + "cnet", 27 }, 28 Types: map[string]types.Type{ 29 "in_addr": inAddr, 30 "in_addr_t": inAddrT, 31 "in_port_t": inPortT, 32 }, 33 Idents: map[string]*types.Ident{ 34 "inet_addr": c.NewIdent("inet_addr", "cnet.ParseAddr", cnet.ParseAddr, c.FuncTT(inAddrT, gstrT)), 35 "htonl": c.NewIdent("htonl", "cnet.Htonl", cnet.Htonl, c.FuncTT(types.UintT(4), types.UintT(4))), 36 "htons": c.NewIdent("htons", "cnet.Htons", cnet.Htons, c.FuncTT(types.UintT(2), types.UintT(2))), 37 "ntohl": c.NewIdent("ntohl", "cnet.Ntohl", cnet.Ntohl, c.FuncTT(types.UintT(4), types.UintT(4))), 38 "ntohs": c.NewIdent("ntohs", "cnet.Ntohs", cnet.Ntohs, c.FuncTT(types.UintT(2), types.UintT(2))), 39 "inet_ntoa": c.NewIdent("inet_ntoa", "cnet.Ntoa", cnet.Ntoa, c.FuncTT(strT, inAddr)), 40 "inet_ntop": c.NewIdent("inet_ntop", "cnet.Ntop", cnet.Ntop, c.FuncTT(strT, types.IntT(4), c.PtrT(nil), strT, sockLenT)), 41 "inet_pton": c.NewIdent("inet_pton", "cnet.Pton", cnet.Pton, c.FuncTT(strT, types.IntT(4), strT, c.PtrT(nil))), 42 }, 43 } 44 }) 45 }