// With an unsafe.Pointer to the block of C memory NewTcpHdr returns a filled in TcpHdr struct.
With an unsafe.Pointer to the block of C memory NewTcpHdr returns a filled in TcpHdr struct.
// With an unsafe . Pointer to the block of C memory NewTcpHdr returns a filled in TcpHdr struct .
func NewTcpHdr(p unsafe.Pointer) (*TcpHdr, unsafe.Pointer) {
	tcpHead := &TcpHdr{
		cptr: (*C.struct_tcphdr)(p),
		Doff: *(*byte)(unsafe.Pointer(uintptr(p) + uintptr(12))) >> 4,
	}
	tcpHead.Source = uint16(C.tcphdr_source_ntohs(tcpHead.cptr))
	tcpHead.Dest = uint16(C.tcphdr_dest_ntohs(tcpHead.cptr))
	tcpHead.Seq = uint32(C.tcphdr_seq_ntohl(tcpHead.cptr))
	tcpHead.AckSeq = uint32(C.tcphdr_ack_seq_ntohl(tcpHead.cptr))
	tcpHead.Flags = uint16(C.ntohs(C.uint16_t(
		*(*uint16)(unsafe.Pointer(uintptr(p) + uintptr(12)))))) & uint16(0x01FF)
	tcpHead.Window = uint16(C.tcphdr_window_ntohs(tcpHead.cptr))
	tcpHead.Check = uint16(C.tcphdr_check_ntohs(tcpHead.cptr))
	tcpHead.UrgPtr = uint16(C.tcphdr_urg_ptr_ntohs(tcpHead.cptr))
	tcpHead.payload = unsafe.Pointer(uintptr(p) + uintptr(tcpHead.Doff*4))
	return tcpHead, tcpHead.payload
}
func NewTcpHdr ( p unsafe . Pointer ) ( * TcpHdr , unsafe . Pointer ) { tcpHead := & TcpHdr { cptr : ( * C . struct_tcphdr ) ( p ) , Doff : * ( * byte ) ( unsafe . Pointer ( uintptr ( p ) + uintptr ( 12 ) ) ) >> 4 , } tcpHead . Source = uint16 ( C . tcphdr_source_ntohs ( tcpHead . cptr ) ) tcpHead . Dest = uint16 ( C . tcphdr_dest_ntohs ( tcpHead . cptr ) ) tcpHead . Seq = uint32 ( C . tcphdr_seq_ntohl ( tcpHead . cptr ) ) tcpHead . AckSeq = uint32 ( C . tcphdr_ack_seq_ntohl ( tcpHead . cptr ) ) tcpHead . Flags = uint16 ( C . ntohs ( C . uint16_t ( * ( * uint16 ) ( unsafe . Pointer ( uintptr ( p ) + uintptr ( 12 ) ) ) ) ) ) & uint16 ( 0x01FF ) tcpHead . Window = uint16 ( C . tcphdr_window_ntohs ( tcpHead . cptr ) ) tcpHead . Check = uint16 ( C . tcphdr_check_ntohs ( tcpHead . cptr ) ) tcpHead . UrgPtr = uint16 ( C . tcphdr_urg_ptr_ntohs ( tcpHead . cptr ) ) tcpHead . payload = unsafe . Pointer ( uintptr ( p ) + uintptr ( tcpHead . Doff * 4 ) ) return tcpHead , tcpHead . payload }
With an unsafe.Pointer to the block of C memory NewTcpHdr returns a filled in TcpHdr struct.
With an unsafe . Pointer to the block of C memory NewTcpHdr returns a filled in TcpHdr struct .
// Since cgo does not provide access to bit fields in a struct // we index 12 octets in and then shift out the unneeded bits. // A this time (and there are no plans to support it) cgo does not // provide access to bit fields in a struct so this is what we are stuck // with.  We index 12 octets in and then use a bit mask.