diff --git a/cnping.c b/cnping.c index 07140a8..3375683 100644 --- a/cnping.c +++ b/cnping.c @@ -735,7 +735,7 @@ int main( int argc, const char ** argv ) //Parameter-based field. switch( thisargv[1] ) { - case 'h': prependPingHost( &pinghostList, &pinghostListSize, nextargv ); break; + case 'h': appendPingHost( &pinghostList, &pinghostListSize, nextargv ); break; case 'p': pingperiodseconds = atof( nextargv ); break; case 's': ExtraPingSize = atoi( nextargv ); break; case 'y': GuiYScaleFactor = atof( nextargv ); break; @@ -750,7 +750,7 @@ int main( int argc, const char ** argv ) //Unmarked fields switch( argcunmarked++ ) { - case 1: prependPingHost( &pinghostList, &pinghostListSize, thisargv ); break; + case 1: appendPingHost( &pinghostList, &pinghostListSize, thisargv ); break; case 2: pingperiodseconds = atof( thisargv ); break; case 3: ExtraPingSize = atoi( thisargv ); break; case 4: GuiYScaleFactor = atof( thisargv ); break; diff --git a/pinghostlist.c b/pinghostlist.c index 31f8162..bac0588 100644 --- a/pinghostlist.c +++ b/pinghostlist.c @@ -3,12 +3,31 @@ #include #include -void prependPingHost( struct PingHost ** list, unsigned int * listSize, const char * newEntryValue ) +void appendPingHost( struct PingHost ** list, unsigned int * listSize, const char * newEntryValue ) { + // find last entry + struct PingHost * current = *list; + struct PingHost * last = current; + while( current ) + { + struct PingHost * next = current->next; + last = current; + current = next; + } + struct PingHost* newEntry = malloc( sizeof(struct PingHost) ); newEntry->host = newEntryValue; - newEntry->next = *list; - *list = newEntry; + newEntry->next = NULL; + + if ( last ) + { + last->next = newEntry; + } + else + { + *list = newEntry; + } + (*listSize) ++; } diff --git a/pinghostlist.h b/pinghostlist.h index a06ba3a..448f1a8 100644 --- a/pinghostlist.h +++ b/pinghostlist.h @@ -10,7 +10,7 @@ struct PingHost }; // add a new entry to the list -void prependPingHost( struct PingHost ** list, unsigned int * listSize, const char * newEntryValue ); +void appendPingHost( struct PingHost ** list, unsigned int * listSize, const char * newEntryValue ); // delete the list // *list and *listsize will be set to 0