X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FIPStack%2Fudp.c;h=8b0904c24a4dc5cc583104ed127b6d922b23e704;hb=849329d50395b44ac97c5b5145fc2df0749eace2;hp=cbdcd56be61a319b2ba270bd38f20d0437a056d5;hpb=51ab5f489bc356940c95cc936fd0508e8f07ea97;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/IPStack/udp.c b/KernelLand/Modules/IPStack/udp.c index cbdcd56b..8b0904c2 100644 --- a/KernelLand/Modules/IPStack/udp.c +++ b/KernelLand/Modules/IPStack/udp.c @@ -15,8 +15,8 @@ void UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, const void *Address, Uint16 Port, const void *Data, size_t Length); // --- Client Channels tVFS_Node *UDP_Channel_Init(tInterface *Interface); -Uint64 UDP_Channel_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); -Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer); +size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer); +size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer); int UDP_Channel_IOCtl(tVFS_Node *Node, int ID, void *Data); void UDP_Channel_Close(tVFS_Node *Node); // --- Helpers @@ -144,7 +144,7 @@ void UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, */ void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, const void *Address, Uint16 Port, const void *Data, size_t Length) { - tUDPHeader *hdr; + tUDPHeader hdr; if(Channel->Interface && Channel->Interface->Type != AddrType) return ; @@ -152,17 +152,17 @@ void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, const void *Address, U { case 4: // Create the packet - hdr = malloc(sizeof(tUDPHeader)+Length); - hdr->SourcePort = htons( Channel->LocalPort ); - hdr->DestPort = htons( Port ); - hdr->Length = htons( sizeof(tUDPHeader) + Length ); - hdr->Checksum = 0; // Checksum can be zero on IPv4 - memcpy(hdr->Data, Data, Length); + hdr.SourcePort = htons( Channel->LocalPort ); + hdr.DestPort = htons( Port ); + hdr.Length = htons( sizeof(tUDPHeader) + Length ); + hdr.Checksum = 0; // Checksum can be zero on IPv4 // Pass on the the IPv4 Layer + tIPStackBuffer *buffer = IPStack_Buffer_CreateBuffer(2 + IPV4_BUFFERS); + IPStack_Buffer_AppendSubBuffer(buffer, Length, 0, Data, NULL, NULL); + IPStack_Buffer_AppendSubBuffer(buffer, sizeof(hdr), 0, &hdr, NULL, NULL); // TODO: What if Channel->Interface is NULL here? - IPv4_SendPacket(Channel->Interface, *(tIPv4*)Address, IP4PROT_UDP, 0, sizeof(tUDPHeader)+Length, hdr); - // Free allocated packet - free(hdr); + IPv4_SendPacket(Channel->Interface, *(tIPv4*)Address, IP4PROT_UDP, 0, buffer); + IPStack_Buffer_DestroyBuffer(buffer); break; } } @@ -189,7 +189,7 @@ tVFS_Node *UDP_Channel_Init(tInterface *Interface) /** * \brief Read from the channel file (wait for a packet) */ -Uint64 UDP_Channel_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) +size_t UDP_Channel_Read(tVFS_Node *Node, off_t Offset, size_t Length, void *Buffer) { tUDPChannel *chan = Node->ImplPtr; tUDPPacket *pack; @@ -249,7 +249,7 @@ Uint64 UDP_Channel_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buf /** * \brief Write to the channel file (send a packet) */ -Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer) +size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const void *Buffer) { tUDPChannel *chan = Node->ImplPtr; const tUDPEndpoint *ep;