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

📄 igmp_host_api.c

📁 路由器协议平台igmp协议设计实现源码。
💻 C
字号:
/*
 $Log:: /OEM Source Code/igmp/igmp_host_api.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_host_api_error_codes.h"
/********************************************************************************************/
enum IGMP_HOST_API_ERROR igmp_host_join_group (UINT port, ULONG group_ip_address)
{
	/* note: the group_ip_address should be in host order */

	char ip_address[IP_ADDRESS_PRINT_BUFFER_SIZE];
	IGMP_GROUP_CLASS *sptr_matching_group_node;

	if (port > igmp.number_of_ports)
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP Host: Application attempting to join group %s on out of range port %u.\n",
				convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return (IGMP_HOST_API_JOIN_GROUP_PORT_OUT_OF_RANGE_ERROR);
		}

	if (igmp.port_table[port].host_enabled == FALSE)
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP Host: Application attempting to join group %s on port %u with host disabled.\n",
				convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return (IGMP_HOST_API_JOIN_DISABLED_PORT_ERROR);
		}
		
	if (!IN_CLASS_D (group_ip_address))
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP Host: Application attempting to join group on non-multicast ip address %s on port %u.\n",
				convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return (IGMP_HOST_API_JOIN_GROUP_NON_MULTICAST_ADDRESS_ERROR);
		}
		
	/* try to locate the group on the port */
	sptr_matching_group_node = igmp_get_matching_group_node_on_port (group_ip_address, port);

	if (sptr_matching_group_node == NULL)
		{
		/* if couldn't locate the group, then add it */
		sptr_matching_group_node = igmp_add_group_to_port (group_ip_address, port);
		}

	if (sptr_matching_group_node == NULL)
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP Host: Unable to add group %s on port %u for application joining the group.\n",
			convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return (IGMP_HOST_API_JOIN_GROUP_CANT_ADD_GROUP_ERROR);
		}

	if (sptr_matching_group_node->host_group.state == IGMP_HOST_GROUP_NON_MEMBER_STATE)
		{
		++igmp.port_table[port].igmpInterfaceEntry.igmpInterfaceJoins;

		++igmp.port_table[port].igmpInterfaceEntry.igmpInterfaceGroups;

		igmp_process_host_group_state_transition (port, group_ip_address, IGMP_HOST_GROUP_JOIN_EVENT);
		}
	else if ((sptr_matching_group_node->host_group.state == IGMP_HOST_GROUP_DELAYING_MEMBER_STATE) || (sptr_matching_group_node->host_group.state == IGMP_HOST_GROUP_IDLE_MEMBER_STATE))
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP HOST: Join occured for MEMBER group %s on port %u.\n",
			convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return (IGMP_HOST_API_JOIN_GROUP_FOR_MEMBER_GROUP_ERROR);
		}
	else
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP Host: Join occured for group %s in UNKNOWN state on port %u.\n",
			convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return (IGMP_HOST_API_JOIN_GROUP_FOR_UNKNOWN_STATE_ERROR);
		}

	return (IGMP_HOST_API_NO_ERROR);		
}
/********************************************************************************************/
enum IGMP_HOST_API_ERROR igmp_host_leave_group (UINT port, ULONG group_ip_address)
{
	/* note: the group_ip_address should be in host order */
	enum IGMP_HOST_API_ERROR return_value;

	char ip_address[IP_ADDRESS_PRINT_BUFFER_SIZE];
	IGMP_GROUP_CLASS *sptr_matching_group_node;
	
	if (port > igmp.number_of_ports)
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP Host: Application attempting to leave group %s on out of range port %u.\n",
				convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return (IGMP_HOST_API_LEAVE_GROUP_PORT_OUT_OF_RANGE_ERROR);
		}

	if (igmp.port_table[port].host_enabled == FALSE)
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP Host: Application attempting to leave group %s on port %u with host disabled.\n",
				convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return (IGMP_HOST_API_LEAVE_DISABLED_PORT_ERROR);
		}

	if (!IN_CLASS_D (group_ip_address))
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP Host: Application attempting to leave group on non-multicast ip address %s on port %u.\n",
				convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return (IGMP_HOST_API_LEAVE_GROUP_NON_MULTICAST_ADDRESS_ERROR);
		}
		
	sptr_matching_group_node = igmp_get_matching_group_node_on_port (group_ip_address, port);

	if (sptr_matching_group_node == NULL)
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP Host: Unable to get matching node for group %s on port %u.\n",
			convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return (IGMP_HOST_API_LEAVE_GROUP_NO_MATCHING_GROUP_NODE_ERROR);
		}

	if ((sptr_matching_group_node->host_group.state == IGMP_HOST_GROUP_DELAYING_MEMBER_STATE) || (sptr_matching_group_node->host_group.state == IGMP_HOST_GROUP_IDLE_MEMBER_STATE))
		{
		++igmp.port_table[port].igmpInterfaceEntry.igmpInterfaceLeaves;

		--igmp.port_table[port].igmpInterfaceEntry.igmpInterfaceGroups;

		igmp_process_host_group_state_transition (port, group_ip_address, IGMP_HOST_GROUP_LEAVE_EVENT);

		return_value = IGMP_HOST_API_NO_ERROR;
		}
	else if (sptr_matching_group_node->host_group.state == IGMP_HOST_GROUP_NON_MEMBER_STATE)
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP Host: Leave occured for Non-MEMBER group %s on port %u.\n",
			convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return_value = IGMP_HOST_API_LEAVE_GROUP_FOR_NON_MEMBER_ERROR;
		}
	else
		{
		IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP Host: Leave occured for group %s in UNKNOWN state on port %u.\n",
			convert_ip_address_to_dot_format (&ip_address[0], group_ip_address), port);

		return_value = IGMP_HOST_API_LEAVE_GROUP_FOR_UNKNOWN_STATE_ERROR;
		}

	delete_entry_from_list ((LINK *) &igmp.port_table[port].active_group_list, (LINK *) sptr_matching_group_node);

	table_free (sptr_matching_group_node);
	
	return (return_value);		
}

⌨️ 快捷键说明

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