Static int
Searchusingroutecmd (char * address, struct in_addr * In, struct in_addr * addr_out, char * best_if, size_t best_iflen, unsigned long * best_netmask)
{
Char mask [20];
Char routecmd [maxstr];
Int best_metric = int_max;
Char Buf [2048];
Char interface [maxstr];
Char * CP, * sp;
Int done = 0;
File * routefd = NULL;
Uint32_t maskbits;
/* Open route and get the information */
/* Store the command in the routecmd variable */
Snprintf (routecmd, sizeof (routecmd), "% S % s", route, routeparm, address );
/* Execute the command line and obtain the file descriptor */
Routefd = popen (routecmd, "R ");
If (routefd = NULL)
Return (ocf_err_generic );
Mask [0] = EOS;
Interface [0] = EOS;
/* Operation file descriptor, and get the message printed after command line execution */
While (done <3) & fgets (BUF, sizeof (BUF), routefd )){
Int buflen = strnlen (BUF, sizeof (BUF ));
CP = Buf;
SP = BUF + buflen;
While (SP! = Buf & isspace (INT) * (SP-1 ))){
-- Sp;
}
* Sp = EOS;
Buf [buflen] = EOS;
If (strstr (BUF, "Mask :")){
/* Strsep (& CP, ":"); CP ++ ;*/
CP = strtok (BUF ,":");
CP = strtok (null, ":"); CP ++;
Strncpy (mask, CP, sizeof (mask ));
Done ++;
}
If (strstr (BUF, "interface :")){
/* Strsep (& CP, ":"); CP ++ ;*/
CP = strtok (BUF ,":");
CP = strtok (null, ":"); CP ++;
Strncpy (interface, CP, sizeof (Interface ));
Done ++;
}
}
Fclose (routefd );
}