check_nt.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /******************************************************************************
  2. *
  3. * CHECK_NT.C
  4. *
  5. * Program: Windows NT plugin for NetSaint
  6. * License: GPL
  7. * Copyright (c) 2000-2002 Yves Rubin (rubiyz@yahoo.com)
  8. *
  9. * Description:
  10. *
  11. * This requires NSClient software to run on NT (http://nsclient.ready2run.nl/)
  12. *
  13. * License Information:
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. *
  29. *****************************************************************************/
  30. #include "config.h"
  31. #include "common.h"
  32. #include "netutils.h"
  33. #include "utils.h"
  34. #define CHECK_NONE 0
  35. #define CHECK_CLIENTVERSION 1
  36. #define CHECK_CPULOAD 2
  37. #define CHECK_UPTIME 3
  38. #define CHECK_USEDDISKSPACE 4
  39. #define CHECK_SERVICESTATE 5
  40. #define CHECK_PROCSTATE 6
  41. #define CHECK_MEMUSE 7
  42. #define CHECK_COUNTER 8
  43. #define CHECK_FILEAGE 9
  44. #define MAX_VALUE_LIST 30
  45. #define PORT 1248
  46. char *server_address=NULL;
  47. char *volume_name=NULL;
  48. int server_port=PORT;
  49. char *value_list=NULL;
  50. char *req_password=NULL;
  51. unsigned long lvalue_list[MAX_VALUE_LIST];
  52. unsigned long warning_value=0L;
  53. unsigned long critical_value=0L;
  54. int check_value_list=FALSE;
  55. int check_warning_value=FALSE;
  56. int check_critical_value=FALSE;
  57. int vars_to_check=CHECK_NONE;
  58. int show_all=FALSE;
  59. const char *progname = "check_nt";
  60. int process_arguments(int, char **);
  61. void print_usage(void);
  62. void print_help(void);
  63. void preparelist(char *string);
  64. int main(int argc, char **argv){
  65. int result;
  66. int return_code = STATE_UNKNOWN;
  67. char *send_buffer=NULL;
  68. char recv_buffer[MAX_INPUT_BUFFER];
  69. char *output_message=NULL;
  70. char *temp_string=NULL;
  71. char *description=NULL;
  72. double total_disk_space=0;
  73. double free_disk_space=0;
  74. double percent_used_space=0;
  75. double mem_commitLimit=0;
  76. double mem_commitByte=0;
  77. unsigned long utilization;
  78. unsigned long uptime;
  79. unsigned long age_in_minutes;
  80. double counter_value;
  81. int offset=0;
  82. int updays=0;
  83. int uphours=0;
  84. int upminutes=0;
  85. asprintf(&req_password,"None");
  86. if(process_arguments(argc,argv)==ERROR)
  87. usage("Could not parse arguments\n");
  88. /* initialize alarm signal handling */
  89. signal(SIGALRM,socket_timeout_alarm_handler);
  90. /* set socket timeout */
  91. alarm(socket_timeout);
  92. if (vars_to_check==CHECK_CLIENTVERSION) {
  93. asprintf(&send_buffer,strcat(req_password,"&1"));
  94. result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
  95. if(result!=STATE_OK)
  96. return result;
  97. asprintf(&output_message,recv_buffer);
  98. return_code=STATE_OK;
  99. }
  100. else if(vars_to_check==CHECK_CPULOAD){
  101. if (check_value_list==TRUE) {
  102. if (strtolarray(&lvalue_list,value_list,",")==TRUE) {
  103. /* -l parameters is present with only integers */
  104. return_code=STATE_OK;
  105. asprintf(&temp_string,"CPU Load");
  106. while (lvalue_list[0+offset]>(unsigned long)0 &&
  107. lvalue_list[0+offset]<=(unsigned long)17280 &&
  108. lvalue_list[1+offset]>=(unsigned long)0 &&
  109. lvalue_list[1+offset]<=(unsigned long)100 &&
  110. lvalue_list[2+offset]>=(unsigned long)0 &&
  111. lvalue_list[2+offset]<=(unsigned long)100) {
  112. /* loop until one of the parameters is wrong or not present */
  113. /* Send request and retrieve data */
  114. asprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]);
  115. result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
  116. if(result!=STATE_OK)
  117. return result;
  118. if (!strncmp(recv_buffer,"ERROR",5)) {
  119. printf("NSClient - %s\n",recv_buffer);
  120. exit(STATE_UNKNOWN);
  121. }
  122. utilization=strtoul(recv_buffer,NULL,10);
  123. /* Check if any of the request is in a warning or critical state */
  124. if(utilization >= lvalue_list[2+offset])
  125. return_code=STATE_CRITICAL;
  126. else if(utilization >= lvalue_list[1+offset] && return_code<STATE_WARNING)
  127. return_code=STATE_WARNING;
  128. asprintf(&output_message," %lu%% (%lu min average)", utilization, lvalue_list[0+offset]);
  129. asprintf(&temp_string,"%s%s",temp_string,output_message);
  130. offset+=3; /* move across the array */
  131. }
  132. if (strlen(temp_string)>10) {
  133. /* we had at least on loop */
  134. asprintf(&output_message,"%s",temp_string);
  135. }
  136. else
  137. asprintf(&output_message,"%s","not enough values for -l parameters");
  138. } else
  139. asprintf(&output_message,"wrong -l parameter.");
  140. } else
  141. asprintf(&output_message,"missing -l parameters");
  142. }
  143. else if(vars_to_check==CHECK_UPTIME){
  144. asprintf(&send_buffer,strcat(req_password,"&3"));
  145. result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
  146. if(result!=STATE_OK)
  147. return result;
  148. if (!strncmp(recv_buffer,"ERROR",5)) {
  149. printf("NSClient - %s\n",recv_buffer);
  150. exit(STATE_UNKNOWN);
  151. }
  152. uptime=strtoul(recv_buffer,NULL,10);
  153. updays = uptime / 86400;
  154. uphours = (uptime % 86400) / 3600;
  155. upminutes = ((uptime % 86400) % 3600) / 60;
  156. asprintf(&output_message,"System Uptime : %u day(s) %u hour(s) %u minute(s)",updays,uphours, upminutes);
  157. return_code=STATE_OK;
  158. }
  159. else if(vars_to_check==CHECK_USEDDISKSPACE){
  160. return_code=STATE_UNKNOWN;
  161. if (check_value_list==TRUE) {
  162. if (strlen(value_list)==1) {
  163. asprintf(&send_buffer,"%s&4&%s", req_password, value_list);
  164. result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
  165. if(result!=STATE_OK)
  166. return result;
  167. if (!strncmp(recv_buffer,"ERROR",5)) {
  168. printf("NSClient - %s\n",recv_buffer);
  169. exit(STATE_UNKNOWN);
  170. }
  171. free_disk_space=atof(strtok(recv_buffer,"&"));
  172. total_disk_space=atof(strtok(NULL,"&"));
  173. percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100;
  174. if (free_disk_space>=0) {
  175. asprintf(&temp_string,"%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)",
  176. value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824, percent_used_space,
  177. free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100);
  178. if(check_critical_value==TRUE && percent_used_space >= critical_value)
  179. return_code=STATE_CRITICAL;
  180. else if (check_warning_value==TRUE && percent_used_space >= warning_value)
  181. return_code=STATE_WARNING;
  182. else
  183. return_code=STATE_OK;
  184. asprintf(&output_message,"%s",temp_string);
  185. }
  186. else {
  187. asprintf(&output_message,"Free disk space : Invalid drive ");
  188. return_code=STATE_UNKNOWN;
  189. }
  190. }
  191. else
  192. asprintf(&output_message,"wrong -l argument");
  193. } else
  194. asprintf(&output_message,"missing -l parameters");
  195. }
  196. else if(vars_to_check==CHECK_SERVICESTATE || vars_to_check==CHECK_PROCSTATE){
  197. if (check_value_list==TRUE) {
  198. preparelist(value_list); /* replace , between services with & to send the request */
  199. asprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6,
  200. (show_all==TRUE)?"ShowAll":"ShowFail",value_list);
  201. result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
  202. if(result!=STATE_OK)
  203. return result;
  204. if (!strncmp(recv_buffer,"ERROR",5)) {
  205. printf("NSClient - %s\n",recv_buffer);
  206. exit(STATE_UNKNOWN);
  207. }
  208. return_code=atoi(strtok(recv_buffer,"&"));
  209. temp_string=strtok(NULL,"&");
  210. asprintf(&output_message, "%s",temp_string);
  211. }
  212. else
  213. asprintf(&output_message,"No service/process specified");
  214. }
  215. else if(vars_to_check==CHECK_MEMUSE) {
  216. asprintf(&send_buffer,"%s&7", req_password);
  217. result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
  218. if (result!=STATE_OK)
  219. return result;
  220. if (!strncmp(recv_buffer,"ERROR",5)) {
  221. printf("NSClient - %s\n",recv_buffer);
  222. exit(STATE_UNKNOWN);
  223. }
  224. mem_commitLimit=atof(strtok(recv_buffer,"&"));
  225. mem_commitByte=atof(strtok(NULL,"&"));
  226. percent_used_space = (mem_commitByte / mem_commitLimit) * 100;
  227. asprintf(&output_message,"Memory usage: total:%.2f Mb - used: %.2f Mb (%.0f%%) - free: %.2f Mb (%.0f%%)",
  228. mem_commitLimit / 1048576, mem_commitByte / 1048567, percent_used_space,
  229. (mem_commitLimit - mem_commitByte) / 1048576, (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100);
  230. if(check_critical_value==TRUE && percent_used_space >= critical_value)
  231. return_code=STATE_CRITICAL;
  232. else if (check_warning_value==TRUE && percent_used_space >= warning_value)
  233. return_code=STATE_WARNING;
  234. else
  235. return_code=STATE_OK;
  236. }
  237. else if(vars_to_check==CHECK_COUNTER) {
  238. if (check_value_list==TRUE) {
  239. preparelist(value_list); /* replace , between services with & to send the request */
  240. asprintf(&send_buffer,"%s&8&%s", req_password,value_list);
  241. result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
  242. if (result!=STATE_OK)
  243. return result;
  244. if (!strncmp(recv_buffer,"ERROR",5)) {
  245. printf("NSClient - %s\n",recv_buffer);
  246. exit(STATE_UNKNOWN);
  247. }
  248. strtok(value_list,"&"); /* burn the first parameters */
  249. description = strtok(NULL,"&");
  250. counter_value = atof(recv_buffer);
  251. if (description == NULL)
  252. asprintf(&output_message, "%.f", counter_value);
  253. else
  254. asprintf(&output_message, description, counter_value);
  255. if (critical_value > warning_value) {
  256. /* Normal thresholds */
  257. if(check_critical_value==TRUE && counter_value >= critical_value)
  258. return_code=STATE_CRITICAL;
  259. else if (check_warning_value==TRUE && counter_value >= warning_value)
  260. return_code=STATE_WARNING;
  261. else
  262. return_code=STATE_OK;
  263. }
  264. else {
  265. /* inverse thresholds */
  266. if(check_critical_value==TRUE && counter_value <= critical_value)
  267. return_code=STATE_CRITICAL;
  268. else if (check_warning_value==TRUE && counter_value <= warning_value)
  269. return_code=STATE_WARNING;
  270. else
  271. return_code=STATE_OK;
  272. }
  273. }
  274. else {
  275. asprintf(&output_message,"No counter specified");
  276. result=STATE_UNKNOWN;
  277. }
  278. }
  279. else if(vars_to_check==CHECK_FILEAGE) {
  280. if (check_value_list==TRUE) {
  281. preparelist(value_list); /* replace , between services with & to send the request */
  282. asprintf(&send_buffer,"%s&9&%s", req_password,value_list);
  283. result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
  284. if (result!=STATE_OK)
  285. return result;
  286. if (!strncmp(recv_buffer,"ERROR",5)) {
  287. printf("NSClient - %s\n",recv_buffer);
  288. exit(STATE_UNKNOWN);
  289. }
  290. age_in_minutes = atoi(strtok(recv_buffer,"&"));
  291. description = strtok(NULL,"&");
  292. asprintf(&output_message, description);
  293. if (critical_value > warning_value) {
  294. /* Normal thresholds */
  295. if(check_critical_value==TRUE && age_in_minutes >= critical_value)
  296. return_code=STATE_CRITICAL;
  297. else if (check_warning_value==TRUE && age_in_minutes >= warning_value)
  298. return_code=STATE_WARNING;
  299. else
  300. return_code=STATE_OK;
  301. }
  302. else {
  303. /* inverse thresholds */
  304. if(check_critical_value==TRUE && age_in_minutes <= critical_value)
  305. return_code=STATE_CRITICAL;
  306. else if (check_warning_value==TRUE && age_in_minutes <= warning_value)
  307. return_code=STATE_WARNING;
  308. else
  309. return_code=STATE_OK;
  310. }
  311. }
  312. else {
  313. asprintf(&output_message,"No file specified");
  314. result=STATE_UNKNOWN;
  315. }
  316. }
  317. /* reset timeout */
  318. alarm(0);
  319. printf("%s\n",output_message);
  320. return return_code;
  321. }
  322. /* process command-line arguments */
  323. int process_arguments(int argc, char **argv){
  324. int c;
  325. int option_index = 0;
  326. static struct option long_options[] =
  327. {
  328. {"port", required_argument,0,'p'},
  329. {"timeout", required_argument,0,'t'},
  330. {"critical", required_argument,0,'c'},
  331. {"warning", required_argument,0,'w'},
  332. {"variable", required_argument,0,'v'},
  333. {"hostname", required_argument,0,'H'},
  334. {"version", no_argument, 0,'V'},
  335. {"help", no_argument, 0,'h'},
  336. {0,0,0,0}
  337. };
  338. /* no options were supplied */
  339. if(argc<2) return ERROR;
  340. /* backwards compatibility */
  341. if (! is_option(argv[1])) {
  342. server_address=argv[1];
  343. argv[1]=argv[0];
  344. argv=&argv[1];
  345. argc--;
  346. }
  347. for (c=1;c<argc;c++) {
  348. if(strcmp("-to",argv[c])==0)
  349. strcpy(argv[c],"-t");
  350. else if (strcmp("-wv",argv[c])==0)
  351. strcpy(argv[c],"-w");
  352. else if (strcmp("-cv",argv[c])==0)
  353. strcpy(argv[c],"-c");
  354. }
  355. while (1){
  356. c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:",long_options,&option_index);
  357. if (c==-1||c==EOF||c==1)
  358. break;
  359. switch (c)
  360. {
  361. case '?': /* print short usage statement if args not parsable */
  362. printf("%s: Unknown argument: %s\n\n",progname,optarg);
  363. print_usage();
  364. exit(STATE_UNKNOWN);
  365. case 'h': /* help */
  366. print_help();
  367. exit(STATE_OK);
  368. case 'V': /* version */
  369. print_revision(progname,"$Revision$");
  370. exit(STATE_OK);
  371. case 'H': /* hostname */
  372. server_address=optarg;
  373. break;
  374. case 's': /* password */
  375. asprintf(&req_password,optarg);
  376. break;
  377. case 'p': /* port */
  378. if (is_intnonneg(optarg))
  379. server_port=atoi(optarg);
  380. else
  381. terminate(STATE_UNKNOWN,"Server port an integer (seconds)\nType '%s -h' for additional help\n",progname);
  382. break;
  383. case 'v':
  384. if(strlen(optarg)<4)
  385. return ERROR;
  386. if(!strcmp(optarg,"CLIENTVERSION"))
  387. vars_to_check=CHECK_CLIENTVERSION;
  388. else if(!strcmp(optarg,"CPULOAD"))
  389. vars_to_check=CHECK_CPULOAD;
  390. else if(!strcmp(optarg,"UPTIME"))
  391. vars_to_check=CHECK_UPTIME;
  392. else if(!strcmp(optarg,"USEDDISKSPACE"))
  393. vars_to_check=CHECK_USEDDISKSPACE;
  394. else if(!strcmp(optarg,"SERVICESTATE"))
  395. vars_to_check=CHECK_SERVICESTATE;
  396. else if(!strcmp(optarg,"PROCSTATE"))
  397. vars_to_check=CHECK_PROCSTATE;
  398. else if(!strcmp(optarg,"MEMUSE"))
  399. vars_to_check=CHECK_MEMUSE;
  400. else if(!strcmp(optarg,"COUNTER"))
  401. vars_to_check=CHECK_COUNTER;
  402. else if(!strcmp(optarg,"FILEAGE"))
  403. vars_to_check=CHECK_FILEAGE;
  404. else
  405. return ERROR;
  406. break;
  407. case 'l': /* value list */
  408. asprintf(&value_list,"%s",optarg);
  409. check_value_list=TRUE;
  410. break;
  411. case 'w': /* warning threshold */
  412. warning_value=strtoul(optarg,NULL,10);
  413. check_warning_value=TRUE;
  414. break;
  415. case 'c': /* critical threshold */
  416. critical_value=strtoul(optarg,NULL,10);
  417. check_critical_value=TRUE;
  418. break;
  419. case 'd': /* Display select for services */
  420. if (!strcmp(optarg,"SHOWALL"))
  421. show_all = TRUE;
  422. break;
  423. case 't': /* timeout */
  424. socket_timeout=atoi(optarg);
  425. if(socket_timeout<=0)
  426. return ERROR;
  427. }
  428. }
  429. if (vars_to_check==CHECK_NONE)
  430. return ERROR;
  431. return OK;
  432. }
  433. void print_usage(void)
  434. {
  435. printf("Usage: %s -H host -v variable [-p port] [-w warning] [-c critical] [-l params] [-d SHOWALL] [-t timeout]\n",progname);
  436. }
  437. void print_help(void)
  438. {
  439. print_revision(progname,"$Revision$");
  440. printf ("\
  441. Copyright (c) 2000 Yves Rubin (rubiyz@yahoo.com)\n\n\
  442. This plugin collects data from the NSClient service running on a\n\
  443. Windows NT/2000/XP server.\n\n");
  444. print_usage();
  445. printf ("\nOptions:\n\
  446. -H, --hostname=HOST\n\
  447. Name of the host to check\n\
  448. -p, --port=INTEGER\n\
  449. Optional port number (default: %d)\n\
  450. -s <password>\n\
  451. Password needed for the request\n\
  452. -w, --warning=INTEGER\n\
  453. Threshold which will result in a warning status\n\
  454. -c, --critical=INTEGER\n\
  455. Threshold which will result in a critical status\n\
  456. -t, --timeout=INTEGER\n\
  457. Seconds before connection attempt times out (default: %d)\n\
  458. -h, --help\n\
  459. Print this help screen\n\
  460. -V, --version\n\
  461. Print version information\n",
  462. PORT, DEFAULT_SOCKET_TIMEOUT);
  463. printf ("\
  464. -v, --variable=STRING\n\
  465. Variable to check. Valid variables are:\n");
  466. printf ("\
  467. CLIENTVERSION = Get the NSClient version\n");
  468. printf ("\
  469. CPULOAD = Average CPU load on last x minutes.\n\
  470. Request a -l parameter with the following syntax:\n\
  471. -l <minutes range>,<warning threshold>,<critical threshold>.\n\
  472. <minute range> should be less than 24*60.\n\
  473. Thresholds are percentage and up to 10 requests can be done in one shot.\n\
  474. ie: -l 60,90,95,120,90,95\n");
  475. printf ("\
  476. UPTIME = Get the uptime of the machine.\n\
  477. No specific parameters. No warning or critical threshold\n");
  478. printf ("\
  479. USEDDISKSPACE = Size and percentage of disk use.\n\
  480. Request a -l parameter containing the drive letter only.\n\
  481. Warning and critical thresholds can be specified with -w and -c.\n");
  482. printf ("\
  483. MEMUSE = Memory use.\n\
  484. Warning and critical thresholds can be specified with -w and -c.\n");
  485. printf ("\
  486. SERVICESTATE = Check the state of one or several services.\n\
  487. Request a -l parameters with the following syntax:\n\
  488. -l <service1>,<service2>,<service3>,...\n\
  489. You can specify -d SHOWALL in case you want to see working services\n\
  490. in the returned string.\n");
  491. printf ("\
  492. PROCSTATE = Check if one or several process are running.\n\
  493. Same syntax as SERVICESTATE.\n");
  494. printf ("\
  495. COUNTER = Check any performance counter of Windows NT/2000.\n\
  496. Request a -l parameters with the following syntax:\n\
  497. -l \"\\\\<performance object>\\\\counter\",\"<description>\n\
  498. The <description> parameter is optional and \n\
  499. is given to a printf output command which require a float parameters.\n\
  500. Some examples:\n\
  501. \"Paging file usage is %%.2f %%%%\"\n\
  502. \"%%.f %%%% paging file used.\"\n");
  503. printf ("Notes:\n\
  504. - The NSClient service should be running on the server to get any information\n\
  505. (http://nsclient.ready2run.nl).\n\
  506. - Critical thresholds should be lower than warning thresholds\n");
  507. }
  508. int strtolarray(unsigned long *array, char *string, char *delim) {
  509. /* split a <delim> delimited string into a long array */
  510. int idx=0;
  511. char *t1;
  512. for (idx=0;idx<MAX_VALUE_LIST;idx++)
  513. array[idx]=-1;
  514. idx=0;
  515. for(t1 = strtok(string,delim);t1 != NULL; t1 = strtok(NULL, delim)) {
  516. if (is_numeric(t1) && idx<MAX_VALUE_LIST) {
  517. array[idx]=strtoul(t1,NULL,10);
  518. idx++;
  519. } else
  520. return FALSE;
  521. }
  522. return TRUE;
  523. }
  524. void preparelist(char *string) {
  525. /* Replace all , with & which is the delimiter for the request */
  526. int i;
  527. for (i = 0; (size_t)i < strlen(string); i++)
  528. if (string[i] == ',') {
  529. string[i]='&';
  530. }
  531. }