Created
May 29, 2017 11:10
-
-
Save unakatsuo/6546992a3c449905b2568e9bb7dfedeb to your computer and use it in GitHub Desktop.
C.struct_in_addr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// #include <arpa/inet.h> | |
import "C" | |
import ( | |
"encoding/binary" | |
"fmt" | |
"net" | |
"unsafe" | |
) | |
func main() { | |
var addr C.struct_in_addr | |
fmt.Printf("sizeof=%d, %d\n", unsafe.Sizeof(addr), addr.s_addr) | |
goip := net.ParseIP("192.168.1.1") | |
addr.s_addr = (C.in_addr_t)(binary.LittleEndian.Uint32(goip.To4())) | |
fmt.Printf("%d\n", addr.s_addr) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment