func rawpacket(proto packet.IPProto, src, dst packet.IP4, sport, dport uint16, trimLength int) []byte {
	var headerLength int

	switch proto {
	case ICMPv4:
		headerLength = 24
	case TCP:
		headerLength = 40
	case UDP:
		headerLength = 28
	default:
		headerLength = 24
	}
	if trimLength > headerLength {
		headerLength = trimLength
	}
	if trimLength == 0 {
		trimLength = headerLength
	}

	bin := binary.BigEndian
	hdr := make([]byte, headerLength)
	hdr[0] = 0x45
	bin.PutUint16(hdr[2:4], uint16(trimLength))
	hdr[8] = 64
	bin.PutUint32(hdr[12:16], uint32(src))
	bin.PutUint32(hdr[16:20], uint32(dst))
	// ports
	bin.PutUint16(hdr[20:22], sport)
	bin.PutUint16(hdr[22:24], dport)

	switch proto {
	case ICMPv4:
		hdr[9] = 1
	case TCP:
		hdr[9] = 6
	case UDP:
		hdr[9] = 17
	case Fragment:
		hdr[9] = 6
		// flags + fragOff
		bin.PutUint16(hdr[6:8], (1<<13)|1234)
	case Unknown:
	default:
		panic("unknown protocol")
	}

	// Trim the header if requested
	hdr = hdr[:trimLength]

	return hdr
}
// rawpacket generates a packet with given source and destination ports and IPs
// and resizes the header to trimLength if it is nonzero.
rawpacket generates a packet with given source and destination ports and IPs
and resizes the header to trimLength if it is nonzero.
// rawpacket generates a packet with given source and destination ports and IPs // and resizes the header to trimLength if it is nonzero .
func rawpacket(proto packet.IPProto, src, dst packet.IP4, sport, dport uint16, trimLength int) []byte {
	var headerLength int
	switch proto {
	case ICMPv4:
		headerLength = 24
	case TCP:
		headerLength = 40
	case UDP:
		headerLength = 28
	default:
		headerLength = 24
	}
	if trimLength > headerLength {
		headerLength = trimLength
	}
	if trimLength == 0 {
		trimLength = headerLength
	}
	bin := binary.BigEndian
	hdr := make([]byte, headerLength)
	hdr[0] = 0x45
	bin.PutUint16(hdr[2:4], uint16(trimLength))
	hdr[8] = 64
	bin.PutUint32(hdr[12:16], uint32(src))
	bin.PutUint32(hdr[16:20], uint32(dst))
	bin.PutUint16(hdr[20:22], sport)
	bin.PutUint16(hdr[22:24], dport)
	switch proto {
	case ICMPv4:
		hdr[9] = 1
	case TCP:
		hdr[9] = 6
	case UDP:
		hdr[9] = 17
	case Fragment:
		hdr[9] = 6
		bin.PutUint16(hdr[6:8], (1<<13)|1234)
	case Unknown:
	default:
		panic("unknown protocol")
	}
	hdr = hdr[:trimLength]
	return hdr
}
func rawpacket ( proto packet . IPProto , src , dst packet . IP4 , sport , dport uint16 , trimLength int ) [ ] byte { var headerLength int switch proto { case ICMPv4 : headerLength = 24 case TCP : headerLength = 40 case UDP : headerLength = 28 default : headerLength = 24 } if trimLength > headerLength { headerLength = trimLength } if trimLength == 0 { trimLength = headerLength } bin := binary . BigEndian hdr := make ( [ ] byte , headerLength ) hdr [ 0 ] = 0x45 bin . PutUint16 ( hdr [ 2 : 4 ] , uint16 ( trimLength ) ) hdr [ 8 ] = 64 bin . PutUint32 ( hdr [ 12 : 16 ] , uint32 ( src ) ) bin . PutUint32 ( hdr [ 16 : 20 ] , uint32 ( dst ) ) bin . PutUint16 ( hdr [ 20 : 22 ] , sport ) bin . PutUint16 ( hdr [ 22 : 24 ] , dport ) switch proto { case ICMPv4 : hdr [ 9 ] = 1 case TCP : hdr [ 9 ] = 6 case UDP : hdr [ 9 ] = 17 case Fragment : hdr [ 9 ] = 6 bin . PutUint16 ( hdr [ 6 : 8 ] , ( 1 << 13 ) | 1234 ) case Unknown : default : panic ( " " ) } hdr = hdr [ : trimLength ] return hdr }
rawpacket generates a packet with given source and destination ports and IPs
and resizes the header to trimLength if it is nonzero.
rawpacket generates a packet with given source and destination ports and IPs and resizes the header to trimLength if it is nonzero .
// ports // flags + fragOff // Trim the header if requested