Packet Sniffer SDK DLL Edition

HNAdapter :: Methods :: AdpSyncSendEx

 Previous Next

Sends a packet synchronously.

Syntax:

DWORD __stdcall AdpSyncSendEx(HANDLE hAdp, HANDLE hPkt);

Parameters:

hAdp

[in] HNAdapter object handle.

hPacket

[in] HNPacket object handle.

Return values:

HNERR_OKThe packet has been sent successfully.
HNERR_ADAPTER_NOT_OPENEDThe adapter has not been opened, see the AdpOpenAdapter function.
HNERR_SIZE_ERRThe HNPacket.IncPacketSize[Get/Set] property value is greater than the maximum size, see AdpCfgGetMaxPacketSize.
HNERR_ADAPTER_REQ_ERRAn internal driver request error.
HNERR_INVALID_HANDLEhAdp parameter is not the HNAdapter object handle.

Description:

Having created HNPacket object by PktCreate function you can use it to create raw packet. Note that when using AdpSyncSendEx function you should set HNPacket.IncPacketSize[Get/Set] property correctly, because this property value is used for sending data through the network adapter.

After the network adapter has been opened successfully by AdpOpenAdapter, you can send a raw packet directly, without using the OS functions. This packet will be sent synchronously.

This function cannot work with the devices recognized as atWAN. See HNNetAdapterType.
// Create ARP packet
ETHERNET_HEADER Eth;
ARP_HEADER Arp;

DWORD IncPacketSize = sizeof(ETHERNET_HEADER) + sizeof(ARP_HEADER);
HANDLE hPkt = PktCreate(IncPacketSize);
...
UCHAR *pPacketData = (UCHAR*)PktGetPacketData(hPkt);
...
memcpy(pPacketData,&Eth,sizeof(Eth));
...
memcpy(&pPacketData[sizeof(Eth)],&Arp,sizeof(Arp));
PktSetIncPacketSize(hPkt,IncPacketSize);
AdpSyncSendEx(hAdp,hPkt);
...
PktDestroy(hPkt);
See also:Packets processing diagram, HNAdapter, HNNetAdapterType, AdpOpenAdapter, AdpCfgGetMaxPacketSize, HNPacket, PktCreate, PktGetIncPacketSize, PktSetIncPacketSize, AdpSyncSend, OnAdpAsyncSend