diff U3 C:/igmp_patch2/igmp_original.c C:/igmp_patch2/igmp.c --- C:/igmp_patch2/igmp_original.c Fri Nov 16 14:31:12 2007 +++ C:/igmp_patch2/igmp.c Sun Mar 09 20:09:03 2008 @@ -137,6 +137,17 @@ #define igmp_dump_group_list() #endif /* LWIP_DEBUG */ +#ifndef LWIP_IGMP_RANDOM +/* The end user can override this macro to provide his own random number routine + For example to use the standard c rand() function, include the following + in your lwipopts.h file: + #define IGMP_RANDOM(max) ((u8_t) ((long) max * rand()/RAND_MAX)) + The user routine should return a random u8_t ranging from 0 to max. + Default to the original source, which simply used max/2: +*/ +#define IGMP_RANDOM(max) ((u8_t) ((max)/2)) +#endif + /** * Start IGMP processing on interface * @@ -640,9 +651,6 @@ void igmp_start_timer(struct igmp_group *group, u8_t max_time) { - /** - * @todo Important !! this should be random 0 -> max_time. Find out how to do this - */ group->timer = max_time; } @@ -666,8 +674,15 @@ void igmp_delaying_member( struct igmp_group *group, u8_t maxresp) { - if ((group->group_state == IGMP_GROUP_IDLE_MEMBER) || ((group->group_state == IGMP_GROUP_DELAYING_MEMBER) && (maxresp > group->timer))) { - igmp_start_timer(group, (maxresp)/2); + u8_t time; + if ( (group->group_state == IGMP_GROUP_IDLE_MEMBER) + || ((group->group_state == IGMP_GROUP_DELAYING_MEMBER) && ((group->timer==0) || (maxresp > group->timer))) + ) { + time = LWIP_IGMP_RANDOM(maxresp); /* Generate a random u8_t integer 0 to maxresp */ + if (time==0) { /* For now change 0 to 1 to force a send the next timer tick. */ + time = 1; /* In the future, a developer can change this to send message */ + } /* right now if time == 0 without macro breakage. */ + igmp_start_timer(group, time); group->group_state = IGMP_GROUP_DELAYING_MEMBER; } }