void UDP_Initialise();
void UDP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer);
void UDP_Unreachable(tInterface *Interface, int Code, void *Address, int Length, void *Buffer);
-void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, void *Address, Uint16 Port, void *Data, size_t 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);
pack->Next = NULL;
memcpy(&pack->Remote.Addr, Address, IPStack_GetAddressSize(Interface->Type));
pack->Remote.Port = ntohs(hdr->SourcePort);
+ pack->Remote.AddrType = Interface->Type;
pack->Length = len;
memcpy(pack->Data, hdr->Data, len);
* \param Data Packet data
* \param Length Length in bytes of packet data
*/
-void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, void *Address, Uint16 Port, void *Data, size_t Length)
+void UDP_SendPacketTo(tUDPChannel *Channel, int AddrType, const void *Address, Uint16 Port, const void *Data, size_t Length)
{
tUDPHeader *hdr;
tUDPChannel *chan = Node->ImplPtr;
tUDPPacket *pack;
tUDPEndpoint *ep;
- int ofs;
+ int ofs, addrlen;
if(chan->LocalPort == 0) {
Log_Notice("UDP", "Channel %p sent with no local port", chan);
}
// Check that the header fits
+ addrlen = IPStack_GetAddressSize(pack->Remote.AddrType);
ep = Buffer;
- ofs = 4 + IPStack_GetAddressSize(pack->Remote.AddrType);
+ ofs = 4 + addrlen;
if(Length < ofs) {
free(pack);
Log_Notice("UDP", "Insuficient space for header in buffer (%i < %i)", (int)Length, ofs);
// Fill header
ep->Port = pack->Remote.Port;
ep->AddrType = pack->Remote.AddrType;
- memcpy(&ep->Addr, &pack->Remote.Addr, IPStack_GetAddressSize(pack->Remote.AddrType));
+ memcpy(&ep->Addr, &pack->Remote.Addr, addrlen);
// Copy packet data
if(Length > ofs + pack->Length) Length = ofs + pack->Length;
Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer)
{
tUDPChannel *chan = Node->ImplPtr;
- tUDPEndpoint *ep;
- void *data;
+ const tUDPEndpoint *ep;
+ const void *data;
int ofs;
if(chan->LocalPort == 0) return 0;
ep = Buffer;
ofs = 2 + 2 + IPStack_GetAddressSize( ep->AddrType );
- data = (char*)Buffer + ofs;
+ data = (const char *)Buffer + ofs;
UDP_SendPacketTo(chan, ep->AddrType, &ep->Addr, ep->Port, data, (size_t)Length - ofs);