📄 igmp_deserialize_message.c
字号:
/*
$Log:: /OEM Source Code/igmp/igmp_deserialize_message.c $
*
* 1 4/23/98 9:53p Release Engineer
* Initial release
* IGMP v4.1.0
*/
/************************************************************************/
/* Copyright (C) 1997-1998 RouterWare, Inc. */
/* Unpublished - rights reserved under the Copyright Laws of the */
/* United States. Use, duplication, or disclosure by the */
/* Government is subject to restrictions as set forth in */
/* subparagraph (c)(1)(ii) of the Rights in Technical Data and */
/* Computer Software clause at 252.227-7013. */
/* RouterWare, Inc., 3961 MacArthur Blvd. Suite 212, Newport Beach, CA */
/************************************************************************/
#include <stdlib.h>
#include "igmp.h"
#include "igmp_packet.h"
/********************************************************************************************/
static enum BOOLEAN igmp_received_valid_ip_packet (IP_PARAMETERS *sptr_ip_parameters);
static enum BOOLEAN igmp_received_valid_message (IGMP_PAYLOAD *sptr_igmp_payload, UINT size_of_igmp_payload);
/********************************************************************************************/
IGMP_MESSAGE *igmp_deserialize_received_message (IP_PARAMETERS *sptr_ip_parameters, void *sptr_igmp_received_packet, UINT igmp_packet_size)
{
IGMP_MESSAGE *sptr_igmp_message;
IGMP_PAYLOAD *sptr_igmp_payload;
if (igmp_received_valid_ip_packet (sptr_ip_parameters) == FALSE)
{
return (NULL);
}
sptr_igmp_payload = (IGMP_PAYLOAD *)(&(((IP_PACKET *)sptr_igmp_received_packet)->options_or_data.data) + sptr_ip_parameters->options_length);
if (igmp_received_valid_message (sptr_igmp_payload, igmp_packet_size) == FALSE)
{
return (NULL);
}
sptr_igmp_message = igmp_create_message ();
if (sptr_igmp_message == NULL)
{
IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Failed to create an IGMP message when deserializing received packet.\n");
return (NULL);
}
/* fill in the IGMP message */
sptr_igmp_message->type = (enum IGMP_MESSAGE_TYPE) sptr_igmp_payload->message_type;
sptr_igmp_message->max_response_time = sptr_igmp_payload->max_response_time;
sptr_igmp_message->group_ip_address = deserialize_long (sptr_igmp_payload->group_ip_address);
sptr_igmp_message->source_ip_address = sptr_ip_parameters->source_address;
sptr_igmp_message->receiving_port = sptr_ip_parameters->rx_port_number;
return (sptr_igmp_message);
}
/********************************************************************************************/
static enum BOOLEAN igmp_received_valid_ip_packet (IP_PARAMETERS *sptr_ip_parameters)
{
if (igmp.port_table[sptr_ip_parameters->rx_port_number].enabled == FALSE)
{
IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Received packet on disabled port %u.\n",sptr_ip_parameters->rx_port_number);
return (FALSE);
}
if (!IN_CLASS_D (sptr_ip_parameters->destination_address))
{
IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Received packet not a multicast packet.\n");
return (FALSE);
}
return (TRUE);
}
/********************************************************************************************/
static enum BOOLEAN igmp_received_valid_message (IGMP_PAYLOAD *sptr_igmp_payload, UINT size_of_igmp_payload)
{
if (size_of_igmp_payload < IGMP_MINIMUM_MESSAGE_SIZE)
{
IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Received IGMP message with lesser than expected length.\n");
return (FALSE);
}
if (calculate_ip_checksum (NULL, (BYTE *) sptr_igmp_payload, (USHORT) size_of_igmp_payload) != 0x0000)
{
IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Received IGMP message failed checksum validation\n");
return (FALSE);
}
if (sptr_igmp_payload->group_ip_address != 0x00000000L)
{
if (!IN_CLASS_D (host_to_net_long (sptr_igmp_payload->group_ip_address)))
{
IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Received IGMP message Group not a Class D address!\n");
return (FALSE);
}
}
return (TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -