Exemple #1
0
func GetRemoteHostName(node string) (hostname string, err os.Error) {
	var cres *C.struct_addrinfo

	cnode := C.CString(node)
	defer C.free(unsafe.Pointer(cnode))

	ret := C.getaddrinfo(cnode, nil, nil, &cres)
	defer C.freeaddrinfo(cres)

	if int(ret) != 0 {
		err = os.NewError(error(ret))
		return
	}

	chostname := make([]C.char, C.NI_MAXHOST)
	ret = C.getnameinfo(cres.ai_addr, cres.ai_addrlen, (*C.char)(unsafe.Pointer(&chostname[0])), C.NI_MAXHOST, nil, 0, 0)

	if int(ret) != 0 {
		err = os.NewError(error(ret))
		return
	}
	hostname = C.GoString((*C.char)(unsafe.Pointer(&chostname[0])))
	return
}
Exemple #2
0
func cgoNameinfoPTR(b []byte, sa *C.struct_sockaddr, salen C.socklen_t) (int, error) {
	gerrno, err := C.getnameinfo(sa, salen, (*C.char)(unsafe.Pointer(&b[0])), C.socklen_t(len(b)), nil, 0, C.NI_NAMEREQD)
	return int(gerrno), err
}