Packet Sniffer SDK DLL Edition

HNPacket :: Methods :: PktCreate

 Previous Next

Creates the HNPacket object.

Syntax:

HANDLE __stdcall PktCreate(DWORD MaxPacketSize);

Parameters:

MaxPacketSize

[in] The size of the buffer allocated for a packet data. For certain adapter this value may be defined by HNAdapterConfig.MaxPacketSize [Get] property of the HNAdapterConfig object. This parameter value will be stored in the MaxPacketSize [Get] property.

Return values:

If the function succeeds the return value will be the handle of the HNPacket object. Otherwise the return value will be NULL. The only reason for unsuccessful Packet object creation can be a lack of memory.

Description:

Use this function to create the HNPacket object that allows you to create your own raw packets. To destroy HNPacket object use PktDestroy function.

// Create and asynchronously send ARP packet 
ETHERNET_HEADER Eth;
ARP_HEADER      Arp;

DWORD PacketSize = sizeof(ETHERNET_HEADER) + sizeof(ARP_HEADER);
HANDLE hPkt = PktCreate(PacketSize);
...
UCHAR *pPacketData = (UCHAR*)PktGetPacketData(hPkt);
...
memcpy(pPacketData, &Eth, sizeof(Eth));
...
memcpy(&pPacketData[sizeof(Eth)], &Arp, sizeof(Arp));
PktSetPacketSize(hPkt);
AdpSyncSendEx(hAdp, hPkt);
...
PktDestroy(hPkt);
See also:HNPacket, PktDestroy