信号处理配置
物理网络接口配置加载
配置文件的加载
虚拟网络设备初始化
路由向量表初始化
定时器初始化
sigemptyset(&sa.sa_mask); sigaction(SIGTERM, &sa, NULL); sigaction(SIGINT, &sa, NULL);
struct IfDesc { char Name[ sizeof( ((struct ifreq *)NULL)->ifr_name ) ]; struct in_addr InAdr; /* == 0 for non IP interfaces */ short Flags; short state; //状态:如upstream、downstream struct SubnetList* allowednets; //一个子网链表 unsigned int robustness; unsigned char threshold; /* ttl limit */ unsigned int ratelimit; unsigned int index; };
if ( (MRouterFD = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP)) < 0 )//打开套接口MRouterFD log( LOG_ERR, errno, "IGMP socket open" ); if ( setsockopt( MRouterFD, IPPROTO_IP, MRT_INIT,(void *)&Va, sizeof( Va ) ) )//激活Linux内核模块mrouted服务 return errno;
setsockopt( MRouterFD, IPPROTO_IP, MRT_ADD_VIF, (char *)&VifCtl, sizeof( VifCtl ) )
struct vifctl { vifi_t vifc_vifi; /* Index of VIF */ unsigned char vifc_flags; /* VIFF_ flags */ unsigned char vifc_threshold; /* ttl limit */ unsigned int vifc_rate_limit; /* Rate limiter values (NI) */ union { struct in_addr vifc_lcl_addr; /* Local interface address */ int vifc_lcl_ifindex; /* Local interface index */ }; struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */ };
struct ip { #if __BYTE_ORDER == __LITTLE_ENDIAN unsigned int ip_hl:4; /* header length */ unsigned int ip_v:4; /* version */ #endif #if __BYTE_ORDER == __BIG_ENDIAN unsigned int ip_v:4; /* version */ unsigned int ip_hl:4; /* header length */ #endif u_int8_t ip_tos; /* type of service */ u_short ip_len; /* total length */ u_short ip_id; /* identification */ u_short ip_off; /* fragment offset field */ #define IP_RF 0x8000 /* reserved fragment flag */ #define IP_DF 0x4000 /* dont fragment flag */ #define IP_MF 0x2000 /* more fragments flag */ #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ u_int8_t ip_ttl; /* time to live */ u_int8_t ip_p; /* protocol */ u_short ip_sum; /* checksum */ struct in_addr ip_src, ip_dst; /* source and dest address */ };
allhosts_group = htonl(INADDR_ALLHOSTS_GROUP); //224.0.0.1 在本子网上的所有参加多播的主机和路由器 allrouters_group = htonl(INADDR_ALLRTRS_GROUP); //224.0.0.2 在本子网上的所有参加多播的路由器
joinMcGroup( getMcGroupSock(), Dp, allrouters_group );
joinleave( int Cmd, int UdpSock, struct IfDesc *IfDp, uint32 mcastaddr )
setsockopt( UdpSock, IPPROTO_IP, Cmd == 'j' ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP, (void *)&CtlReq, sizeof( CtlReq ) )
void callout_init() { queue = NULL; }
igmpproxy源代码学习——igmpProxyInit()
原文地址:http://blog.csdn.net/windeal3203/article/details/39339761