Reply To: Send Raw Packet.

Home Forums Discussions General Discussion Send Raw Packet. Reply To: Send Raw Packet.

#6462

Vadim Smirnov
Moderator

I’m wondering if it has the ability to send raw packet???

Sure it can.

int main(int argc, char* argv[])
{
UINT counter = 0;
ether_header* pEthHeader = NULL;

if (argc < 3)
{
printf ("Command line syntax:ntsender.exe index numntindex - network interface index.ntnum - number or packets to sendntYou can use ListAdapters to determine correct index.n");
return 0;
}

iIndex = atoi(argv[1]) - 1;
counter = atoi(argv[2]);

if(!api.IsDriverLoaded())
{
printf ("Driver not installed on this system of failed to load.n");
return 0;
}

api.GetTcpipBoundAdaptersInfo ( &AdList );

if ( iIndex + 1 > AdList.m_nAdapterCount )
{
printf("There is no network interface with such index on this system.n");
return 0;
}

// Initialize Request
ZeroMemory ( &Request, sizeof(ETH_REQUEST) );
ZeroMemory ( &PacketBuffer, sizeof(INTERMEDIATE_BUFFER) );
Request.EthPacket.Buffer = &PacketBuffer;
Request.hAdapterHandle = (HANDLE)AdList.m_nAdapterHandle[iIndex];

pEthHeader = (ether_header*)PacketBuffer.m_IBuffer;

memcpy(&pEthHeader->h_source, AdList.m_czCurrentAddress[iIndex], ETH_ALEN);
memset(&pEthHeader->h_dest, 0xFF, ETH_ALEN);
pEthHeader->h_proto = ETH_P_IP;
Request.EthPacket.Buffer->m_Length = MAX_ETHER_FRAME;

while (counter--)
api.SendPacketToAdapter(&Request);

return 0;
}

The code above initializes Ethernet header (broadcast IP packet) and sends it over the network. IP header and above are not initialized (packet is filled by zeros).