Source file
src/net/cgo_unix_syscall.go
1
2
3
4
5
6
7 package net
8
9 import (
10 "internal/syscall/unix"
11 "runtime"
12 "syscall"
13 "unsafe"
14 )
15
16 const (
17 _C_AF_INET = syscall.AF_INET
18 _C_AF_INET6 = syscall.AF_INET6
19 _C_AF_UNSPEC = syscall.AF_UNSPEC
20 _C_EAI_ADDRFAMILY = unix.EAI_ADDRFAMILY
21 _C_EAI_AGAIN = unix.EAI_AGAIN
22 _C_EAI_NONAME = unix.EAI_NONAME
23 _C_EAI_SERVICE = unix.EAI_SERVICE
24 _C_EAI_NODATA = unix.EAI_NODATA
25 _C_EAI_OVERFLOW = unix.EAI_OVERFLOW
26 _C_EAI_SYSTEM = unix.EAI_SYSTEM
27 _C_IPPROTO_TCP = syscall.IPPROTO_TCP
28 _C_IPPROTO_UDP = syscall.IPPROTO_UDP
29 _C_SOCK_DGRAM = syscall.SOCK_DGRAM
30 _C_SOCK_STREAM = syscall.SOCK_STREAM
31 )
32
33 type (
34 _C_char = byte
35 _C_int = int32
36 _C_uchar = byte
37 _C_uint = uint32
38 _C_socklen_t = int
39 _C_struct___res_state = unix.ResState
40 _C_struct_addrinfo = unix.Addrinfo
41 _C_struct_sockaddr = syscall.RawSockaddr
42 )
43
44 func _C_free(p unsafe.Pointer) { runtime.KeepAlive(p) }
45
46 func _C_malloc(n uintptr) unsafe.Pointer {
47 if n <= 0 {
48 n = 1
49 }
50 return unsafe.Pointer(&make([]byte, n)[0])
51 }
52
53 func _C_ai_addr(ai *_C_struct_addrinfo) **_C_struct_sockaddr { return &ai.Addr }
54 func _C_ai_family(ai *_C_struct_addrinfo) *_C_int { return &ai.Family }
55 func _C_ai_flags(ai *_C_struct_addrinfo) *_C_int { return &ai.Flags }
56 func _C_ai_next(ai *_C_struct_addrinfo) **_C_struct_addrinfo { return &ai.Next }
57 func _C_ai_protocol(ai *_C_struct_addrinfo) *_C_int { return &ai.Protocol }
58 func _C_ai_socktype(ai *_C_struct_addrinfo) *_C_int { return &ai.Socktype }
59
60 func _C_freeaddrinfo(ai *_C_struct_addrinfo) {
61 unix.Freeaddrinfo(ai)
62 }
63
64 func _C_gai_strerror(eai _C_int) string {
65 return unix.GaiStrerror(int(eai))
66 }
67
68 func _C_getaddrinfo(hostname, servname *byte, hints *_C_struct_addrinfo, res **_C_struct_addrinfo) (int, error) {
69 return unix.Getaddrinfo(hostname, servname, hints, res)
70 }
71
72 func _C_res_ninit(state *_C_struct___res_state) error {
73 unix.ResNinit(state)
74 return nil
75 }
76
77 func _C_res_nsearch(state *_C_struct___res_state, dname *_C_char, class, typ int, ans *_C_char, anslen int) int {
78 x, _ := unix.ResNsearch(state, dname, class, typ, ans, anslen)
79 return x
80 }
81
82 func _C_res_nclose(state *_C_struct___res_state) {
83 unix.ResNclose(state)
84 }
85
86 func cgoNameinfoPTR(b []byte, sa *syscall.RawSockaddr, salen int) (int, error) {
87 gerrno, err := unix.Getnameinfo(sa, salen, &b[0], len(b), nil, 0, unix.NI_NAMEREQD)
88 return int(gerrno), err
89 }
90
91 func cgoSockaddrInet4(ip IP) *syscall.RawSockaddr {
92 sa := syscall.RawSockaddrInet4{Len: syscall.SizeofSockaddrInet4, Family: syscall.AF_INET}
93 copy(sa.Addr[:], ip)
94 return (*syscall.RawSockaddr)(unsafe.Pointer(&sa))
95 }
96
97 func cgoSockaddrInet6(ip IP, zone int) *syscall.RawSockaddr {
98 sa := syscall.RawSockaddrInet6{Len: syscall.SizeofSockaddrInet6, Family: syscall.AF_INET6, Scope_id: uint32(zone)}
99 copy(sa.Addr[:], ip)
100 return (*syscall.RawSockaddr)(unsafe.Pointer(&sa))
101 }
102
View as plain text