Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Nachdem eine WSK-Anwendung (Winsock Kernel) einen Datagrammsocket an eine lokale Transportadresse gebunden hat, kann sie Datagramme über den Socket senden. Eine WSK-Anwendung sendet ein Datagramm über einen Datagrammsocket, indem die WskSendTo-Funktion aufgerufen wird.
Das folgende Codebeispiel zeigt, wie eine WSK-Anwendung ein Datagramm über einen Datagrammsocket senden kann.
// Prototype for the send datagram IoCompletion routine
NTSTATUS
SendDatagramComplete(
PDEVICE_OBJECT DeviceObject,
PIRP Irp,
PVOID Context
);
// Function to send a datagram
NTSTATUS
SendDatagram(
PWSK_SOCKET Socket,
PWSK_BUF DatagramBuffer,
PSOCKADDR RemoteAddress
)
{
PWSK_PROVIDER_DATAGRAM_DISPATCH Dispatch;
PIRP Irp;
NTSTATUS Status;
// Get pointer to the provider dispatch structure
Dispatch =
(PWSK_PROVIDER_DATAGRAM_DISPATCH)(Socket->Dispatch);
// Allocate an IRP
Irp =
IoAllocateIrp(
1,
FALSE
);
// Check result
if (!Irp)
{
// Return error
return STATUS_INSUFFICIENT_RESOURCES;
}
// Set the completion routine for the IRP
IoSetCompletionRoutine(
Irp,
SendDatagramComplete,
DatagramBuffer, // Use the datagram buffer for the context
TRUE,
TRUE,
TRUE
);
// Initiate the send operation on the socket
Status =
Dispatch->WskSendTo(
Socket,
DatagramBuffer,
0, // No flags
RemoteAddress,
0,
NULL, // No associated control info
Irp
);
// Return the status of the call to WskSendTo()
return Status;
}
// Send datagram IoCompletion routine
NTSTATUS
SendDatagramComplete(
PDEVICE_OBJECT DeviceObject,
PIRP Irp,
PVOID Context
)
{
UNREFERENCED_PARAMETER(DeviceObject);
PWSK_BUF DatagramBuffer;
ULONG ByteCount;
// Check the result of the send operation
if (Irp->IoStatus.Status == STATUS_SUCCESS)
{
// Get the pointer to the datagram buffer
DatagramBuffer = (PWSK_BUF)Context;
// Get the number of bytes sent
ByteCount = (ULONG)(Irp->IoStatus.Information);
// Re-use or free the datagram buffer
...
}
// Error status
else
{
// Handle error
...
}
// Free the IRP
IoFreeIrp(Irp);
// Always return STATUS_MORE_PROCESSING_REQUIRED to
// terminate the completion processing of the IRP.
return STATUS_MORE_PROCESSING_REQUIRED;
}
Wenn die WSK-Anwendung entweder eine feste Remotetransportadresse oder eine feste Zieltransportadresse für den Datagrammsocket festgelegt hat, ist der remoteAddress-Parameter , der an die WskSendTo-Funktion übergeben wird, optional und kann NULL sein. Bei NULL wird das Datagramm an die feste Remotetransportadresse oder die feste Ziel-Transportadresse gesendet. Wenn nicht NULL, wird das Datagramm an die angegebene Remotetransportadresse gesendet.
Weitere Informationen zum Festlegen einer festen Remotetransportadresse für einen Datagrammsocket finden Sie unter SIO_WSK_SET_REMOTE_ADDRESS.
Weitere Informationen zum Festlegen einer festen Zieltransportadresse für einen Datagrammsocket finden Sie unter SIO_WSK_SET_SENDTO_ADDRESS.