src/Cedar/Listener.c
// An UDP packet has been received

An UDP packet has been received
An UDP packet has been received
void UDPReceivedPacket(CEDAR *cedar, SOCK *s, IP *ip, UINT port, void *data, UINT size)
{
	SESSION *session;
	UINT *key32;
	UCHAR *buf;
	CONNECTION *c;
	if (s == NULL || ip == NULL || data == NULL || size == 0 || cedar == NULL)
	{
		return;
	}
	if (size < 16)
	{
		return;
	}
	buf = (UCHAR *)data;
	key32 = (UINT *)(buf + 4);
	session = GetSessionFromUDPEntry(cedar, Endian32(*key32));
	if (session == NULL)
	{
		Debug("Invalid UDP Session Key 32: 0x%X\n", *key32);
		return;
	}
	c = session->Connection;
	PutUDPPacketData(c, buf, size);
	Lock(c->lock);
	{
		if (c->Protocol == CONNECTION_UDP)
		{
			if (c->Udp->s != s)
			{
				if (c->Udp->s != NULL)
				{
					ReleaseSock(c->Udp->s);
				}
				AddRef(s->ref);
				c->Udp->s = s;
			}
			Copy(&c->Udp->ip, ip, sizeof(UINT));
			c->Udp->port = port;
		}
	}
	Unlock(c->lock);
	Cancel(session->Cancel1);
	ReleaseSession(session);
}
void UDPReceivedPacket ( CEDAR * cedar , SOCK * s , IP * ip , UINT port , void * data , UINT size ) { SESSION * session ; UINT * key32 ; UCHAR * buf ; CONNECTION * c ; if ( s == NULL || ip == NULL || data == NULL || size == 0 || cedar == NULL ) { return ; } if ( size < 16 ) { return ; } buf = ( UCHAR * ) data ; key32 = ( UINT * ) ( buf + 4 ) ; session = GetSessionFromUDPEntry ( cedar , Endian32 ( * key32 ) ) ; if ( session == NULL ) { Debug ( " \n " , * key32 ) ; return ; } c = session -> Connection ; PutUDPPacketData ( c , buf , size ) ; Lock ( c -> lock ) ; { if ( c -> Protocol == CONNECTION_UDP ) { if ( c -> Udp -> s != s ) { if ( c -> Udp -> s != NULL ) { ReleaseSock ( c -> Udp -> s ) ; } AddRef ( s -> ref ) ; c -> Udp -> s = s ; } Copy ( & c -> Udp -> ip , ip , sizeof ( UINT ) ) ; c -> Udp -> port = port ; } } Unlock ( c -> lock ) ; Cancel ( session -> Cancel1 ) ; ReleaseSession ( session ) ; }
An UDP packet has been received
An UDP packet has been received
// Validate arguments
 // Ignore since the packet size is not enough
 // Get the session from the Key32 value
 // Write the data
 // Rewrite the UDP socket associated with the connection
 // Invoke the Cancel
 // Release the session
