<commit_before>package gosrt

// #cgo pkg-config: srt
// #include <srt/srt.h>
import "C"

import "net"
import "unsafe"
import "errors"
import "encoding/binary"

const (
	INET_4 = C.AF_INET
	INET_6 = C.AF_INET6
)

// Check for SRT errors
func chkSrtError(errorCode int) error {
	if errorCode == -1 {
		return errors.New(C.GoString(C.srt_getlasterror_str()))
	}
	return nil
}

func sockaddrFromIpPort(ip net.IP, port int) C.struct_sockaddr_in {

	if len(ip) != 4 {
		panic("Internal SRT error: cannot get sockaddr ipv4 from an ipv6 IP")
	}

	// create sockaddr
	sockaddr := C.struct_sockaddr_in{}

	// zero
	C.memset(unsafe.Pointer(&sockaddr), C.int(0), C.sizeof_struct_sockaddr_in)

	var noPortBytes [2]byte
	binary.LittleEndian.PutUint16(noPortBytes[:], uint16(port))

	var noPort C.uint16_t

	C.memcpy(unsafe.Pointer(&noPort), unsafe.Pointer(&noPortBytes[0]), 2)

	sockaddr.sin_family = C.sa_family_t(INET_4)
	sockaddr.sin_port = C.in_port_t(noPort)

	// set it
	C.memcpy(unsafe.Pointer(&sockaddr.sin_addr), unsafe.Pointer(&ip[0]), C.size_t(4))

	return sockaddr

}

func sockaddrFromIpPort6(ip net.IP, port int) C.struct_sockaddr_in6 {

	if len(ip) != 4 {
		panic("Internal SRT error: cannot get sockaddr ipv4 from an ipv6 IP")
	}

	// create sockaddr
	sockaddr := C.struct_sockaddr_in6{}

	// zero
	C.memset(unsafe.Pointer(&sockaddr), C.int(0), C.sizeof_struct_sockaddr_in6)

	var noPortBytes [2]byte
	binary.LittleEndian.PutUint16(noPortBytes[:], uint16(port))<commit_msg>Fix endianness for net<commit_after>package gosrt

// #cgo pkg-config: srt
// #include <srt/srt.h>
import "C"

import "net"
import "unsafe"
import "errors"
import "encoding/binary"

const (
	INET_4 = C.AF_INET
	INET_6 = C.AF_INET6
)

// Check for SRT errors
func chkSrtError(errorCode int) error {
	if errorCode == -1 {
		return errors.New(C.GoString(C.srt_getlasterror_str()))
	}
	return nil
}

func sockaddrFromIpPort(ip net.IP, port int) C.struct_sockaddr_in {

	if len(ip) != 4 {
		panic("Internal SRT error: cannot get sockaddr ipv4 from an ipv6 IP")
	}

	// create sockaddr
	sockaddr := C.struct_sockaddr_in{}

	// zero
	C.memset(unsafe.Pointer(&sockaddr), C.int(0), C.sizeof_struct_sockaddr_in)

	var noPortBytes [2]byte
	binary.BigEndian.PutUint16(noPortBytes[:], uint16(port))

	var noPort C.uint16_t

	C.memcpy(unsafe.Pointer(&noPort), unsafe.Pointer(&noPortBytes[0]), 2)

	sockaddr.sin_family = C.sa_family_t(INET_4)
	sockaddr.sin_port = C.in_port_t(noPort)

	// set it
	C.memcpy(unsafe.Pointer(&sockaddr.sin_addr), unsafe.Pointer(&ip[0]), C.size_t(4))

	return sockaddr

}

func sockaddrFromIpPort6(ip net.IP, port int) C.struct_sockaddr_in6 {

	if len(ip) != 4 {
		panic("Internal SRT error: cannot get sockaddr ipv4 from an ipv6 IP")
	}

	// create sockaddr
	sockaddr := C.struct_sockaddr_in6{}

	// zero
	C.memset(unsafe.Pointer(&sockaddr), C.int(0), C.sizeof_struct_sockaddr_in6)

	var noPortBytes [2]byte
	binary.BigEndian.PutUint16(noPortBytes[:], uint16(port))
{'fraction_non_alphanumeric': 0.13671742808798645, 'fraction_numerical': 0.02233502538071066, 'mean_word_length': 4.641221374045801, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '552569', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1181, 'n_words': 246}