X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FIPStack%2Fudp.c;h=ae3806b4a7fd9c117b6e45b1d79212ec0cac5fae;hb=83545da85faef6c5447943266508a3de778ebaf5;hp=0f6ec3dfb394300a8a509a4222afee86ecab1c56;hpb=880dd63bfcba522dab0a75cc63fdec1d04ff8c89;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/IPStack/udp.c b/KernelLand/Modules/IPStack/udp.c index 0f6ec3df..ae3806b4 100644 --- a/KernelLand/Modules/IPStack/udp.c +++ b/KernelLand/Modules/IPStack/udp.c @@ -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; } } @@ -255,7 +255,11 @@ size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const voi const tUDPEndpoint *ep; const void *data; int ofs; - if(chan->LocalPort == 0) return 0; + + if(chan->LocalPort == 0) { + Log_Notice("UDP", "Write to channel %p with zero local port", chan); + return 0; + } ep = Buffer; ofs = 2 + 2 + IPStack_GetAddressSize( ep->AddrType ); @@ -264,7 +268,7 @@ size_t UDP_Channel_Write(tVFS_Node *Node, off_t Offset, size_t Length, const voi UDP_SendPacketTo(chan, ep->AddrType, &ep->Addr, ep->Port, data, (size_t)Length - ofs); - return 0; + return Length; } /**