aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/net/cgo_resnew.go
blob: 6611fd7a3bea7d6073ddc1f4f1e0ef1236f846b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build cgo && !netgo && (aix || darwin || hurd || (linux && !android) || netbsd || solaris)
// +build cgo
// +build !netgo
// +build aix darwin hurd linux,!android netbsd solaris

package net

/*
#include <sys/types.h>
#include <sys/socket.h>

#include <netdb.h>
*/

import (
	"syscall"
)

//extern getnameinfo
func libc_getnameinfo(*syscall.RawSockaddr, syscall.Socklen_t, *byte, syscall.Size_t, *byte, syscall.Size_t, int) int

func cgoNameinfoPTR(b []byte, sa *syscall.RawSockaddr, salen syscall.Socklen_t) (int, error) {
	syscall.Entersyscall()
	gerrno := libc_getnameinfo(sa, salen, &b[0], syscall.Size_t(len(b)), nil, 0, syscall.NI_NAMEREQD)
	syscall.Exitsyscall()
	var err error
	if gerrno == syscall.EAI_SYSTEM {
		errno := syscall.GetErrno()
		if errno != 0 {
			err = errno
		}
	}
	return gerrno, err
}