Set read Timeout:
Packetsetreadtimeout (p-> adapter, p-> Md. Timeout );
Boolean packetsetreadtimeout (lpadapter adapterobject, int timeout)
{
Boolean result;
Trace_enter ("packetsetreadtimeout ");
Adapterobject-> readtimeout = timeout;
# Ifdef have_wanpacket_api
If (adapterobject-> flags = info_flag_ndiswan_adapter)
{
Result = wanpacketsetreadtimeout (adapterobject-> pwanadapter, timeout );
Trace_exit ("packetsetreadtimeout ");
Return result;
}
# Endif // have_wanpacket_api
# Ifdef have_npfim_api
If (adapterobject-> flags = info_flag_npfim_device)
{
//
// Convert the timestamps to Windows like format (0 = immediate,-1 (infinite) = infinite)
//
If (timeout =-1) Timeout = 0;
Else if (timeout = 0) Timeout = infinite;
Result = (Boolean) g_npfimhandlers.npfimsetreadtimeout (adapterobject-> npfimhandle, timeout );
Trace_exit ("packetsetreadtimeout ");
Return result;
}
# Endif // have_npfim_api
# Ifdef have_airpcap_api
//
// Timeout with airpcap is handled at user level
//
If (adapterobject-> flags = info_flag_airpcap_card)
{
Trace_exit ("packetsetreadtimeout ");
Return true;
}
# Endif // have_airpcap_api
# Ifdef have_dag_api
// Under Dag, we simply store the timeout value and then
If (adapterobject-> flags & info_flag_dag_card)
{
If (timeout =-1)
{
// Tell Dag card to return immediately
Adapterobject-> dagreadtimeout. TV _sec = 0;
Adapterobject-> dagreadtimeout. TV _usec = 0;
}
Else
{
If (timeout = 0)
{
// Tell the Dag card to wait forvever
Adapterobject-> dagreadtimeout. TV _sec =-1;
Adapterobject-> dagreadtimeout. TV _usec =-1;
}
Else
{
// Set the timeout for the Dag card
Adapterobject-> dagreadtimeout. TV _sec = timeout/1000;
Adapterobject-> dagreadtimeout. TV _usec = (timeout * 1000) % 1000000;
}
}
Trace_exit ("packetsetreadtimeout ");
Return true;
}
# Endif // have_dag_api
If (adapterobject-> flags = info_flag_ndis_adapter)
{
Result = true;
}
Else
{
//
// If we are here, it's an unsupported adapter type!
//
Trace_print1 ("request to set read timeout on an unknown device type (% u)", adapterobject-> flags );
Result = false;
}
Trace_exit ("packetsetreadtimeout ");
Return result;
}
From the source code, it is found that the read timeout setting is not passed through deviceiocontrol just like setting the kernel buffer. That is to say, setting the timeout will stop the application and will not be passed down, however, in NPF, I found the Code related to read Timeout:
# Define biocsrtimeout 7416
Case biocsrtimeout: // set the timeout on the read CILS
Trace_message (packet_debug_timeout, "biocsrtimeout ");
If (irpsp-> parameters. deviceiocontrol. inputbufferlength <sizeof (ulong ))
{
Set_failure_buffer_small ();
Break;
}
Timeout = * (Pulong) IRP-> associatedirp. systembuffer );
If (timeout = (ulong)-1)
Open-> timeout. quadpart = (Longlong) Immediate;
Else
{
Open-> timeout. quadpart = (Longlong) Timeout;
Open-> timeout. quadpart * = 10000;
Open-> timeout. quadpart =-open-> timeout. quadpart;
}
Trace_message1 (packet_debug_parts, "Read timeout set to % i64d", open-> timeout. quadpart );
Set_result_success (0 );
Break;
The npf_read READ function also contains:
Occupation = 0;
For (I = 0; I <g_ncpu; I ++)
Occupation + = (open-> size-open-> cpudata [I]. Free );
// See if the buffer is full enough to be copied
If (occupation <= open-> mintocopy * g_ncpu | open-> mode & mode_dump)
{
If (open-> readevent! = NULL)
{
// Wait until some packets arrive or the timeout expires
If (open-> timeout. quadpart! = (Longlong) Immediate)
Kewaitforsingleobject (open-> readevent,
Userrequest,
Kernelmode,
True,
(Open-> timeout. quadpart = (Longlong) 0 )? Null: & (open-> timeout ));
Keclearevent (open-> readevent );
}
How is the timeout in the driver passed in! I searched for biocsrtimeout and found it in packetntx \ driver in NPF. SYS. I didn't have it in both wpcap and packet databases! Surprised! Who knows? in Windows XP, the driver under packetntx should be used!