Main Page Modules Data Structures File List Data Fields Globals Related Pages

# Write.c File Reference

`#include "stdarg.h"`
`#include "ntddk.h"`
`#include "ntiologc.h"`
`#include "ndis.h"`
`#include "debug.h"`
`#include "packet.h"`

Go to the source code of this file.

## Functions
NTSTATUS | NPF_Write (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
| Writes a raw packet to the network.
INT | NPF_BufferedWrite (IN PIRP Irp, IN PCHAR UserBuff, IN ULONG UserBuffSize, BOOLEAN Sync)
| Writes a buffer of raw packets to the network.
VOID | NPF_WaitEndOfBufferedWrite (POPEN_INSTANCE Open)
| Waits the completion of all the sends performed by NPF_BufferedWrite.
VOID | NPF_SendComplete (IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_PACKET pPacket, IN NDIS_STATUS Status)
| Ends a send operation.

## Function Documentation

INT NPF_BufferedWrite | ( | IN PIRP | Irp,
|  | IN PCHAR | UserBuff,
|  | IN ULONG | UserBuffSize,
|  | BOOLEAN | sync
| ) |

  | Writes a buffer of raw packets to the network. Parameters:
  Irp | Pointer to the IRP containing the user request.
  UserBuff | Pointer to the buffer containing the packets to send.
  UserBuffSize | Size of the buffer with the packets.
Returns: The amount of bytes actually sent. If the return value is smaller than the Size parameter, an error occurred during the send. The error can be caused by an adapter problem or by an inconsistent/bogus user buffer. This function is called by the OS in consequence of a BIOCSENDPACKETSNOSYNC or a BIOCSENDPACKETSSYNC IOCTL. The buffer received as input parameter contains an arbitrary number of packets, each of which preceded by a sf_pkthdr structure. NPF_BufferedWrite() scans the buffer and sends every packet via the NdisSend() function. When Sync is set to TRUE, the packets are synchronized with the KeQueryPerformanceCounter() function. This requires a remarkable amount of CPU, but allows to respect the timestamps associated with packets with a precision of some microseconds (depending on the precision of the performance counter of the machine). If Sync is false, the timestamps are ignored and the packets are sent as fat as possible. Definition at line 156 of file Write.c. References _OPEN_INSTANCE::AdapterHandle, _OPEN_INSTANCE::Bound, sf_pkthdr::caplen, _OPEN_INSTANCE::MaxFrameSize, _OPEN_INSTANCE::Multiple_Write_Counter, NPF_SendComplete(), NPF_WaitEndOfBufferedWrite(), _OPEN_INSTANCE::PacketPool, RESERVED, sf_pkthdr::ts, and _OPEN_INSTANCE::WriteEvent. Referenced by NPF_IoControl().

VOID NPF_SendComplete | ( | IN NDIS_HANDLE | ProtocolBindingContext,
|  | IN PNDIS_PACKET | pPacket,
|  | IN NDIS_STATUS | Status
| ) |

  | Ends a send operation. Parameters:
  ProtocolBindingContext | Context of the function. Contains a pointer to the OPEN_INSTANCE structure associated with the current instance.
  pRequest | Pointer to the NDIS PACKET structure used by NPF_Write() to send the packet.
  Status | Status of the operation.
Callback function associated with the NdisSend() NDIS function. It is invoked by NDIS when the NIC driver has finished an OID request operation that was previously started by NPF_Write(). Definition at line 367 of file Write.c. References _OPEN_INSTANCE::Multiple_Write_Counter, _OPEN_INSTANCE::Nwrites, RESERVED, _OPEN_INSTANCE::WriteEvent, _OPEN_INSTANCE::WriteInProgress, and _OPEN_INSTANCE::WriteLock. Referenced by DriverEntry(), NPF_BufferedWrite(), and NPF_Write().

VOID NPF_WaitEndOfBufferedWrite | ( | POPEN_INSTANCE | Open | ) |

  | Waits the completion of all the sends performed by NPF_BufferedWrite. Parameters:
  Open | Pointer to open context structure
Used by NPF_BufferedWrite to wait the completion of all the sends before returning the control to the user. Definition at line 349 of file Write.c. References _OPEN_INSTANCE::Multiple_Write_Counter, TRANSMIT_PACKETS, and _OPEN_INSTANCE::WriteEvent. Referenced by NPF_BufferedWrite().

NTSTATUS NPF_Write | ( | IN PDEVICE_OBJECT | DeviceObject,
|  | IN PIRP | Irp
| ) |

  | Writes a raw packet to the network. Parameters:
  DeviceObject | Pointer to the device object on which the user wrote the packet.
  Irp | Pointer to the IRP containing the user request.
Returns: The status of the operation. See ntstatus.h in the DDK. This function is called by the OS in consequence of user WriteFile() call, with the data of the packet that must be sent on the net. The data is contained in the buffer associated with Irp, NPF_Write takes it and delivers it to the NIC driver via the NdisSend() function. The Nwrites field of the OPEN_INSTANCE structure associated with Irp indicates the number of copies of the packet that will be sent: more than one copy of the packet can be sent for performance reasons. Definition at line 45 of file Write.c. References _OPEN_INSTANCE::AdapterHandle, _OPEN_INSTANCE::Bound, EXIT_FAILURE, _OPEN_INSTANCE::MaxFrameSize, _OPEN_INSTANCE::Multiple_Write_Counter, NPF_SendComplete(), _OPEN_INSTANCE::Nwrites, _OPEN_INSTANCE::PacketPool, RESERVED, _OPEN_INSTANCE::WriteEvent, _OPEN_INSTANCE::WriteInProgress, and _OPEN_INSTANCE::WriteLock. Referenced by DriverEntry().

documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.