1
0
mirror of https://github.com/golang/go synced 2024-11-06 02:36:15 -07:00
go/src/net/cgo_socknew.go
Mikio Hara 8854bdbd76 net: fix parsing literal IPv6 address with zone identifier when using cgo
Parsing literal IPv6 address with zone identifier is already supported
when not using cgo. This change enables it when using cgo too.

Fixes #12241.

Change-Id: I3ed78c9e750e75eff0dae76ba8608df39503cf85
Reviewed-on: https://go-review.googlesource.com/17215
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2015-12-04 02:50:00 +00:00

34 lines
748 B
Go

// 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.
// +build cgo,!netgo
// +build android linux solaris
package net
/*
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
*/
import "C"
import (
"syscall"
"unsafe"
)
func cgoSockaddrInet4(ip IP) *C.struct_sockaddr {
sa := syscall.RawSockaddrInet4{Family: syscall.AF_INET}
copy(sa.Addr[:], ip)
return (*C.struct_sockaddr)(unsafe.Pointer(&sa))
}
func cgoSockaddrInet6(ip IP, zone int) *C.struct_sockaddr {
sa := syscall.RawSockaddrInet6{Family: syscall.AF_INET6, Scope_id: uint32(zone)}
copy(sa.Addr[:], ip)
return (*C.struct_sockaddr)(unsafe.Pointer(&sa))
}