⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 igmp_utilities.c

📁 路由器协议平台igmp协议设计实现源码。
💻 C
字号:
/*
 $Log:: /OEM Source Code/igmp/igmp_utilities.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 <stdarg.h>
#include <stdlib.h>
#include <memory.h>
#include "igmp.h"
/********************************************************************************************/
void igmp_trace (enum IGMP_TRACE_GROUP printf_group, const char *cptr_format, ...)
{
	enum BOOLEAN print_string;
	va_list argptr;

	va_start (argptr, cptr_format);

	print_string = FALSE;

	switch (printf_group)
		{
		case IGMP_ALARM_TRACE:
			print_string = igmp.trace.alarm_enabled;
			break;

		case IGMP_TRACE:
			print_string = igmp.trace.enabled;
			break;

		default:
			print_string = FALSE;
			break;
		}

	if (print_string == TRUE)
		{
		vprintf (cptr_format, argptr);
		}

	va_end (argptr);
}
/********************************************************************************************/
void igmp_display_message (ULONG source_address, ULONG destination_address, enum IGMP_MESSAGE_TYPE igmp_message_type,
				UINT igmp_message_max_response_time, ULONG igmp_message_group_ip_address)
{
	char ip_address[IP_ADDRESS_PRINT_BUFFER_SIZE];

	IGMP_PROTOCOL_TRACE (IGMP_TRACE, "IGMP:  Essential info from packet:\n");

	IGMP_PROTOCOL_TRACE (IGMP_TRACE, "IGMP:              Source address: %s\n",convert_ip_address_to_dot_format (&ip_address[0], source_address));

	IGMP_PROTOCOL_TRACE (IGMP_TRACE, "IGMP:         Destination address: %s\n",convert_ip_address_to_dot_format (&ip_address[0], destination_address));

	IGMP_PROTOCOL_TRACE (IGMP_TRACE, "IGMP:                    Protocol: IGMP\n");
	
	IGMP_PROTOCOL_TRACE (IGMP_TRACE, "IGMP:           IGMP message type: %s\n",igmp_message_type_string [igmp_message_type]);

	IGMP_PROTOCOL_TRACE (IGMP_TRACE, "IGMP: IGMP mesg max response time: %u\n",igmp_message_max_response_time);

	IGMP_PROTOCOL_TRACE (IGMP_TRACE, "IGMP:  IGMP message group address: %s\n",convert_ip_address_to_dot_format (&ip_address[0], igmp_message_group_ip_address));
}
/********************************************************************************************/
IGMP_GROUP_CLASS *igmp_add_group_to_port (ULONG group_ip_address, UINT port)
{
	IGMP_GROUP_CLASS *sptr_new_group_entry;

	sptr_new_group_entry = (IGMP_GROUP_CLASS *) table_malloc (1, sizeof (IGMP_GROUP_CLASS));

	if (sptr_new_group_entry != NULL)
		{
		sptr_new_group_entry->enabled = TRUE;
		sptr_new_group_entry->port_number = port;
		sptr_new_group_entry->multicast_group_ip_address = group_ip_address;
		sptr_new_group_entry->ip_address_of_last_reporter = 0x00000000L;

		sptr_new_group_entry->router_group.state = IGMP_ROUTER_GROUP_NO_MEMBERS_PRESENT_STATE;
		sptr_new_group_entry->router_group.group_specific_query_interval = IGMP_DEFAULT_GROUP_QUERY_INTERVAL;
		sptr_new_group_entry->router_group.group_specific_query_count = igmp.port_table[port].robustness;

		sptr_new_group_entry->host_group.state = IGMP_HOST_GROUP_NON_MEMBER_STATE;

	
		memset (&sptr_new_group_entry->igmpCacheEntry, 0, sizeof (IGMP_MIB_CACHE_ENTRY));

		sptr_new_group_entry->igmpCacheEntry.igmpCacheAddress = group_ip_address;
		sptr_new_group_entry->igmpCacheEntry.igmpCacheIfIndex = port;
		sptr_new_group_entry->igmpCacheEntry.igmpCacheSelf = TRUE;
		sptr_new_group_entry->igmpCacheEntry.igmpCacheStatus = TRUE; /* active */


		igmp_initialize_timer (&sptr_new_group_entry->router_group.group_specific_timer);
		igmp_initialize_timer (&sptr_new_group_entry->router_group.retransmit_timer);
		igmp_initialize_timer (&sptr_new_group_entry->router_group.v1_host_timer);

		igmp_initialize_timer (&sptr_new_group_entry->host_group.report_delay_timer);

		add_entry_to_list ((LINK *)(&igmp.port_table[port].active_group_list), (LINK*)sptr_new_group_entry);
	
		return (sptr_new_group_entry);
		}
	
	return (NULL);
}
/********************************************************************************************/
IGMP_GROUP_CLASS *igmp_get_matching_group_node_on_port (ULONG group_ip_address, UINT port)
{
	IGMP_GROUP_CLASS *sptr_matching_group_node;

	for (sptr_matching_group_node = (IGMP_GROUP_CLASS *) get_pointer_to_first_entry_in_list ((LINK *) &igmp.port_table[port].active_group_list);
		sptr_matching_group_node != NULL;
		sptr_matching_group_node = (IGMP_GROUP_CLASS *) get_pointer_to_next_entry_in_list ((LINK *) &sptr_matching_group_node->links))
		{
		if (sptr_matching_group_node->multicast_group_ip_address == group_ip_address)
			{
			return (sptr_matching_group_node);
			}
		}

	return (NULL);
}
/********************************************************************************************/
IGMP_MESSAGE *igmp_create_message (void)
{
	IGMP_MESSAGE *sptr_igmp_message;

	sptr_igmp_message = (IGMP_MESSAGE *) buffer_malloc (sizeof (IGMP_MESSAGE));

	return (sptr_igmp_message);
}
/********************************************************************************************/
void igmp_free_message (IGMP_MESSAGE *sptr_igmp_message)
{
	buffer_free (sptr_igmp_message);
}
/********************************************************************************************/
void igmp_initialize_timer (IGMP_TIMER *sptr_timer)
{
	sptr_timer->enabled = FALSE;
	sptr_timer->second_counter = 0;
	sptr_timer->expiry_time = 0;
}
/********************************************************************************************/
void igmp_increment_timer (IGMP_TIMER *sptr_timer)
{
	if (sptr_timer->enabled == TRUE)
	{
		++sptr_timer->second_counter;
	}
}
/********************************************************************************************/
enum BOOLEAN igmp_timer_has_expired (IGMP_TIMER *sptr_timer)
{
	if ((sptr_timer->enabled == TRUE) && (sptr_timer->second_counter > sptr_timer->expiry_time))
		{
		return (TRUE);
		}
	return (FALSE);
}
/********************************************************************************************/
void igmp_enable_timer (IGMP_TIMER *sptr_timer, UINT expiry_time)
{
	sptr_timer->enabled = TRUE;
	sptr_timer->second_counter = 0;
	sptr_timer->expiry_time = expiry_time;
}
/********************************************************************************************/
ULONG igmp_get_ip_address_for_port_from_ip (UINT port)
{
	ULONG ip_address;

	lsl_control (PROTOCOL_STACK_CONTROL, "IP Routing", GET_PROTOCOL_ADDRESS, port, &ip_address);

	/* the IP address for the port returned by IP is in network order. But inside our module we
		would like to store it in host order. That makes it easier for comparisions if any! */

	ip_address = net_to_host_long (ip_address);

	return (ip_address);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -