42 unsigned int addr =
ntohl(pcb->remote_ip.addr);
45 DbgPrint(
"\tRemote: (%d.%d.%d.%d, %d)\n",
233 tcp_recved(pcb,
p->tot_len);
279 if (newpcb->callback_arg)
327 msg->Output.Socket.NewPcb = tcp_new();
329 if (
msg->Output.Socket.NewPcb)
331 tcp_arg(
msg->Output.Socket.NewPcb,
msg->Input.Socket.Arg);
347 msg->Input.Socket.Arg =
arg;
352 ret =
msg->Output.Socket.NewPcb;
383 msg.Input.FreeSocket.pcb =
pcb;
400 if (!
msg->Input.Bind.Connection->SocketContext)
409 msg->Output.Bind.Error = tcp_bind(
pcb,
410 msg->Input.Bind.IpAddress,
428 msg->Input.Bind.IpAddress = ipaddr;
434 ret =
msg->Output.Bind.Error;
454 if (!
msg->Input.Listen.Connection->SocketContext)
456 msg->Output.Listen.NewPcb =
NULL;
460 msg->Output.Listen.NewPcb = tcp_listen_with_backlog((
PTCP_PCB)
msg->Input.Listen.Connection->SocketContext,
msg->Input.Listen.Backlog);
462 if (
msg->Output.Listen.NewPcb)
482 msg->Input.Listen.Backlog = backlog;
487 ret =
msg->Output.Listen.NewPcb;
510 if (!
msg->Input.Send.Connection->SocketContext)
516 if (
msg->Input.Send.Connection->SendShutdown)
522 SendFlags = TCP_WRITE_FLAG_COPY;
523 SendLength =
msg->Input.Send.DataLength;
524 if (tcp_sndbuf(
pcb) == 0)
530 else if (tcp_sndbuf(
pcb) < SendLength)
533 SendLength = tcp_sndbuf(
pcb);
536 SendFlags |= TCP_WRITE_FLAG_MORE;
539 msg->Output.Send.Error = tcp_write(
pcb,
540 msg->Input.Send.Data,
546 tcp_output((
PTCP_PCB)
msg->Input.Send.Connection->SocketContext);
547 msg->Output.Send.Information = SendLength;
571 msg->Input.Send.DataLength =
len;
579 ret =
msg->Output.Send.Error;
584 *
sent =
msg->Output.Send.Information;
605 if (!
msg->Input.Connect.Connection->SocketContext)
615 msg->Input.Connect.IpAddress,
ntohs(
msg->Input.Connect.Port),
635 msg->Input.Connect.IpAddress = ipaddr;
636 msg->Input.Connect.Port =
port;
642 ret =
msg->Output.Connect.Error;
662 if (!
msg->Input.Shutdown.Connection->SocketContext)
674 if (
msg->Input.Shutdown.shut_rx !=
msg->Input.Shutdown.shut_tx) {
675 if (
msg->Input.Shutdown.shut_rx) {
678 if (
msg->Input.Shutdown.shut_tx) {
682 else if (
msg->Input.Shutdown.shut_rx) {
691 DbgPrint(
"Requested socket shutdown(0, 0) !\n");
694 if (!
msg->Output.Shutdown.Error)
696 if (
msg->Input.Shutdown.shut_rx)
698 msg->Input.Shutdown.Connection->ReceiveShutdown =
TRUE;
702 if (
msg->Input.Shutdown.shut_tx)
703 msg->Input.Shutdown.Connection->SendShutdown =
TRUE;
705 if (
msg->Input.Shutdown.Connection->ReceiveShutdown &&
706 msg->Input.Shutdown.Connection->SendShutdown)
709 msg->Input.Shutdown.Connection->SocketContext =
NULL;
737 ret =
msg->Output.Shutdown.Error;
760 if (
msg->Input.Close.Connection->Closing)
767 if (
msg->Input.Close.Callback)
768 msg->Input.Close.Connection->Closing =
TRUE;
771 if (!
msg->Input.Close.Connection->SocketContext)
778 msg->Input.Close.Connection->SocketContext =
NULL;
785 if (
msg->Output.Close.Error)
788 msg->Input.Close.Connection->SocketContext =
pcb;
789 msg->Input.Close.Connection->Closing =
FALSE;
791 else if (
msg->Input.Close.Callback)
820 ret =
msg->Output.Close.Error;
843 tcp_accepted(listen_pcb);
852 *ipaddr =
pcb->local_ip;
864 *ipaddr =
pcb->remote_ip;
876 pcb->flags |= TF_NODELAY;
878 pcb->flags &= ~TF_NODELAY;
struct _QUEUE_ENTRY * PQUEUE_ENTRY
err_t LibTCPClose(PCONNECTION_ENDPOINT Connection, const int safe, const int callback)
err_t LibTCPBind(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
static const char *const tcp_state_str[]
struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST NPAGED_LOOKASIDE_LIST
NTSTATUS TCPTranslateError(const err_t err)
static err_t InternalRecvEventHandler(void *arg, PTCP_PCB pcb, struct pbuf *p, const err_t err)
static void LibTCPEmptyQueue(PCONNECTION_ENDPOINT Connection)
PTCP_PCB LibTCPListen(PCONNECTION_ENDPOINT Connection, const u8_t backlog)
err_t LibTCPGetPeerName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
STREAM tcp_recv(STREAM s, uint32 length)
VOID TCPFinEventHandler(void *arg, const err_t err)
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
static BOOLEAN WaitForEventSafely(PRKEVENT Event)
struct sock * tcp_accept(struct sock *sk, int flags, int *err)
VOID TCPRecvEventHandler(void *arg)
_In_ PVOID _In_ ULONG _In_ PVOID _In_ ULONG PayloadLength
err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block)
static void LibTCPConnectCallback(void *arg)
NTSTATUS ReceiveShutdownStatus
PCONNECTION_ENDPOINT Connection
err_t LibTCPConnect(PCONNECTION_ENDPOINT Connection, struct ip_addr *const ipaddr, const u16_t port)
#define InsertTailList(ListHead, Entry)
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID SocketContext
void LibTCPFreeSocket(PTCP_PCB pcb)
err_t pbuf_free_callback(struct pbuf *p)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
#define DereferenceObject(Object)
VOID TCPConnectEventHandler(void *arg, const err_t err)
void LibTCPAccept(PTCP_PCB pcb, struct tcp_pcb *listen_pcb, void *arg)
PQUEUE_ENTRY LibTCPDequeuePacket(PCONNECTION_ENDPOINT Connection)
static void LibTCPFreeSocketCallback(void *arg)
void LibTCPEnqueuePacket(PCONNECTION_ENDPOINT Connection, struct pbuf *p)
_In_ PVOID _In_ ULONG Event
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
u8_t pbuf_free(struct pbuf *p)
VOID TCPAcceptEventHandler(void *arg, PTCP_PCB newpcb)
static err_t InternalAcceptEventHandler(void *arg, PTCP_PCB newpcb, const err_t err)
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
static err_t InternalSendEventHandler(void *arg, PTCP_PCB pcb, const u16_t space)
void LibTCPDumpPcb(PVOID SocketContext)
static void LibTCPShutdownCallback(void *arg)
struct tcp_pcb * PTCP_PCB
NTSTATUS LibTCPGetDataFromConnectionQueue(PCONNECTION_ENDPOINT Connection, PUCHAR RecvBuffer, UINT RecvLen, UINT *Received)
RD_BOOL tcp_connect(char *server)
void tcp_shutdown(struct sock *sk, int how)
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
static err_t InternalConnectEventHandler(void *arg, PTCP_PCB pcb, const err_t err)
GLenum const GLvoid * addr
void LibTCPSetNoDelay(PTCP_PCB pcb, BOOLEAN Set)
void tcp_close(struct sock *sk, long timeout)
#define ReferenceObject(Object)
err_t LibTCPSend(PCONNECTION_ENDPOINT Connection, void *const dataptr, const u16_t len, u32_t *sent, const int safe)
static void LibTCPSendCallback(void *arg)
_In_ ULONG _In_ ULONG Offset
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
#define KeInitializeEvent(pEvt, foo, foo2)
#define UnlockObject(Object)
static void LibTCPSocketCallback(void *arg)
static void LibTCPCloseCallback(void *arg)
err_t LibTCPGetHostName(PTCP_PCB pcb, struct ip_addr *const ipaddr, u16_t *const port)
struct tcp_pcb * LibTCPSocket(void *arg)
err_t LibTCPShutdown(PCONNECTION_ENDPOINT Connection, const int shut_rx, const int shut_tx)
static void LibTCPListenCallback(void *arg)
static void InternalErrorEventHandler(void *arg, const err_t err)
int const JOCTET * dataptr
static void LibTCPBindCallback(void *arg)
VOID TCPSendEventHandler(void *arg, const u16_t space)
static IPrintDialogCallback callback
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
void LibTCPGetSocketStatus(PTCP_PCB pcb, PULONG State)
base of all file and directory entries
NPAGED_LOOKASIDE_LIST MessageLookasideList
#define STATUS_FILE_CLOSED
#define LockObject(Object)