package stun

import (
	"encoding/binary"

	"github.com/pkg/errors"
)

type ChannelData struct {
	ChannelNumber uint16
	Length        uint16
	Data          []byte
}

func NewChannelData(packet []byte) (*ChannelData, error) {
	cn, err := getChannelNumber(packet)
	if err != nil {
		return nil, err
	}

	return &ChannelData{
		ChannelNumber: cn,
		Length:        getChannelLength(packet),
		Data:          packet[4:],
	}, nil
}

//  0b01: ChannelData message (since the channel number is the first
//  field in the ChannelData message and channel numbers fall in the
//  range 0x4000 - 0x7FFF).
func getChannelNumber(header []byte) (uint16, error) {
	cn := binary.BigEndian.Uint16(header)
	if cn < 0x4000 || cn > 0x7FFF {
		return 0, errors.Errorf("ChannelNumber is out of range: %d", cn)
	}
	return cn, nil
}

func getChannelLength(header []byte) uint16 {
	return binary.BigEndian.Uint16(header[2:])
}

package stun

import (
	"encoding/binary"

	"github.com/pkg/errors"
)

type ChannelData struct {
	ChannelNumber uint16
	Data          []byte
}

func NewChannelData(packet []byte) (*ChannelData, error) {
	cn, err := getChannelNumber(packet)
	if err != nil {
		return nil, err
	}

	return &ChannelData{
		ChannelNumber: cn,
		Data:          packet,
	}, nil
}

//  0b01: ChannelData message (since the channel number is the first
//  field in the ChannelData message and channel numbers fall in the
//  range 0x4000 - 0x7FFF).
func getChannelNumber(header []byte) (uint16, error) {
	cn := binary.BigEndian.Uint16(header)
	if cn < 0x4000 || cn > 0x7FFF {
		return 0, errors.Errorf("ChannelNumber is out of range: %d", cn)
	}
	return cn, nil
}

--- 
+++ 
@@ -8,6 +8,7 @@
 
 type ChannelData struct {
 	ChannelNumber uint16
+	Length        uint16
 	Data          []byte
 }
 
@@ -19,7 +20,8 @@
 
 	return &ChannelData{
 		ChannelNumber: cn,
-		Data:          packet,
+		Length:        getChannelLength(packet),
+		Data:          packet[4:],
 	}, nil
 }
 
@@ -33,3 +35,7 @@
 	}
 	return cn, nil
 }
+
+func getChannelLength(header []byte) uint16 {
+	return binary.BigEndian.Uint16(header[2:])
+}
Add ChannelData length to struct
