1// Copyright 2015 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// +build cgo,!netgo
6// +build aix darwin hurd linux,!android netbsd solaris
7
8package net
9
10/*
11#include <sys/types.h>
12#include <sys/socket.h>
13
14#include <netdb.h>
15*/
16
17import (
18	"syscall"
19)
20
21//extern getnameinfo
22func libc_getnameinfo(*syscall.RawSockaddr, syscall.Socklen_t, *byte, syscall.Size_t, *byte, syscall.Size_t, int) int
23
24func cgoNameinfoPTR(b []byte, sa *syscall.RawSockaddr, salen syscall.Socklen_t) (int, error) {
25	syscall.Entersyscall()
26	gerrno := libc_getnameinfo(sa, salen, &b[0], syscall.Size_t(len(b)), nil, 0, syscall.NI_NAMEREQD)
27	syscall.Exitsyscall()
28	var err error
29	if gerrno == syscall.EAI_SYSTEM {
30		errno := syscall.GetErrno()
31		if errno != 0 {
32			err = errno
33		}
34	}
35	return gerrno, err
36}
37