Hey guys, I am trying to write a loop that will iterate through a char array in C and pull the IP addresses and test them to see if hthey respond. My ultimate goal is to have the first one that responds returned in the function, but the loop is not running correctly. It will run through right the first time, but then will start over again. Any help would be greatly appreciated. Thanks.

Code:
const char * getServer(char *svrList)
        {
       
 
        char *srList;
 
        srList = strtok(svrList, " ," );
        printf("Contents of srList b4 loop: %s\n", srList);
        printf("Server List: %s\n", svrList);
                while(srList !=NULL)
                        {
                       
                        printf("result is \"%s\"\n", srList);
                        char pComm[512];
                        memset(pComm, '\0', sizeof(512));
                        sprintf(pComm, "ping -c 1 %s > /dev/null", srList);
                       
                if((system (pComm))==0)
                        {
                        printf("result is \"%s\"\n", srList);
                        return "%s", srList;
                        }
                        else
                        {
                        printf("Hitting else loop\n");
                        printf("Contents of srList in else: %s\n", srList);
                        }
                        srList = strtok(NULL, " ," );
 
                        }
 
        return "0";
        }
 
char svrList[] = "1.1.1.1, 2.2.2.2, 4.2.2.2, 8.8.8.8";
getServer(svrList)

Code output:
Contents of srList b4 loop: 1.1.1.1
Server List: 1.1.1.1
result is "1.1.1.1"
Hitting else loop
Contents of srList in else: 2.2.2.2
result is "2.2.2.2"
result is "2.2.2.2"
Contents of srList b4 loop: 1.1.1.1
Server List: 1.1.1.1
result is "1.1.1.1"
Hitting else loop
Contents of srList in else: (null)