summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_nwstat.c76
-rw-r--r--plugins/netutils.c103
-rw-r--r--plugins/netutils.h4
3 files changed, 109 insertions, 74 deletions
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c
index 4ceb58f..dc8ce21 100644
--- a/plugins/check_nwstat.c
+++ b/plugins/check_nwstat.c
@@ -86,6 +86,7 @@ void print_usage(void);
86int 86int
87main(int argc, char **argv) { 87main(int argc, char **argv) {
88 int result; 88 int result;
89 int sd;
89 char *send_buffer=NULL; 90 char *send_buffer=NULL;
90 char recv_buffer[MAX_INPUT_BUFFER]; 91 char recv_buffer[MAX_INPUT_BUFFER];
91 char *output_message=NULL; 92 char *output_message=NULL;
@@ -129,11 +130,14 @@ main(int argc, char **argv) {
129 130
130 /* set socket timeout */ 131 /* set socket timeout */
131 alarm(socket_timeout); 132 alarm(socket_timeout);
132 133
134 /* open connection */
135 my_tcp_connect (server_address, server_port, &sd);
136
133 /* get OS version string */ 137 /* get OS version string */
134 if (check_netware_version==TRUE) { 138 if (check_netware_version==TRUE) {
135 send_buffer = strdup ("S19\r\n"); 139 send_buffer = strdup ("S19\r\n");
136 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 140 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
137 if (result!=STATE_OK) 141 if (result!=STATE_OK)
138 return result; 142 return result;
139 if (!strcmp(recv_buffer,"-1\n")) 143 if (!strcmp(recv_buffer,"-1\n"))
@@ -162,12 +166,12 @@ main(int argc, char **argv) {
162 } 166 }
163 167
164 asprintf (&send_buffer,"UTIL%s\r\n",temp_buffer); 168 asprintf (&send_buffer,"UTIL%s\r\n",temp_buffer);
165 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 169 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
166 if (result!=STATE_OK) 170 if (result!=STATE_OK)
167 return result; 171 return result;
168 utilization=strtoul(recv_buffer,NULL,10); 172 utilization=strtoul(recv_buffer,NULL,10);
169 send_buffer = strdup ("UPTIME\r\n"); 173 send_buffer = strdup ("UPTIME\r\n");
170 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 174 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
171 if (result!=STATE_OK) 175 if (result!=STATE_OK)
172 return result; 176 return result;
173 recv_buffer[strlen(recv_buffer)-1]=0; 177 recv_buffer[strlen(recv_buffer)-1]=0;
@@ -189,7 +193,7 @@ main(int argc, char **argv) {
189 } else if (vars_to_check==CONNS) { 193 } else if (vars_to_check==CONNS) {
190 194
191 send_buffer = strdup ("CONNECT\r\n"); 195 send_buffer = strdup ("CONNECT\r\n");
192 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 196 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
193 if (result!=STATE_OK) 197 if (result!=STATE_OK)
194 return result; 198 return result;
195 current_connections=strtoul(recv_buffer,NULL,10); 199 current_connections=strtoul(recv_buffer,NULL,10);
@@ -208,7 +212,7 @@ main(int argc, char **argv) {
208 } else if (vars_to_check==LTCH) { 212 } else if (vars_to_check==LTCH) {
209 213
210 send_buffer = strdup ("S1\r\n"); 214 send_buffer = strdup ("S1\r\n");
211 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 215 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
212 if (result!=STATE_OK) 216 if (result!=STATE_OK)
213 return result; 217 return result;
214 cache_hits=atoi(recv_buffer); 218 cache_hits=atoi(recv_buffer);
@@ -227,7 +231,7 @@ main(int argc, char **argv) {
227 } else if (vars_to_check==CBUFF) { 231 } else if (vars_to_check==CBUFF) {
228 232
229 send_buffer = strdup ("S2\r\n"); 233 send_buffer = strdup ("S2\r\n");
230 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 234 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
231 if (result!=STATE_OK) 235 if (result!=STATE_OK)
232 return result; 236 return result;
233 cache_buffers=strtoul(recv_buffer,NULL,10); 237 cache_buffers=strtoul(recv_buffer,NULL,10);
@@ -246,7 +250,7 @@ main(int argc, char **argv) {
246 } else if (vars_to_check==CDBUFF) { 250 } else if (vars_to_check==CDBUFF) {
247 251
248 send_buffer = strdup ("S3\r\n"); 252 send_buffer = strdup ("S3\r\n");
249 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 253 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
250 if (result!=STATE_OK) 254 if (result!=STATE_OK)
251 return result; 255 return result;
252 cache_buffers=strtoul(recv_buffer,NULL,10); 256 cache_buffers=strtoul(recv_buffer,NULL,10);
@@ -265,7 +269,7 @@ main(int argc, char **argv) {
265 } else if (vars_to_check==LRUM) { 269 } else if (vars_to_check==LRUM) {
266 270
267 send_buffer = strdup ("S5\r\n"); 271 send_buffer = strdup ("S5\r\n");
268 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 272 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
269 if (result!=STATE_OK) 273 if (result!=STATE_OK)
270 return result; 274 return result;
271 lru_time=strtoul(recv_buffer,NULL,10); 275 lru_time=strtoul(recv_buffer,NULL,10);
@@ -285,7 +289,7 @@ main(int argc, char **argv) {
285 } else if (vars_to_check==VKF) { 289 } else if (vars_to_check==VKF) {
286 290
287 asprintf (&send_buffer,"VKF%s\r\n",volume_name); 291 asprintf (&send_buffer,"VKF%s\r\n",volume_name);
288 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 292 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
289 if (result!=STATE_OK) 293 if (result!=STATE_OK)
290 return result; 294 return result;
291 295
@@ -309,7 +313,7 @@ main(int argc, char **argv) {
309 } else if (vars_to_check==VPF) { 313 } else if (vars_to_check==VPF) {
310 314
311 asprintf (&send_buffer,"VKF%s\r\n",volume_name); 315 asprintf (&send_buffer,"VKF%s\r\n",volume_name);
312 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 316 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
313 if (result!=STATE_OK) 317 if (result!=STATE_OK)
314 return result; 318 return result;
315 319
@@ -323,7 +327,7 @@ main(int argc, char **argv) {
323 free_disk_space=strtoul(recv_buffer,NULL,10); 327 free_disk_space=strtoul(recv_buffer,NULL,10);
324 328
325 asprintf (&send_buffer,"VKS%s\r\n",volume_name); 329 asprintf (&send_buffer,"VKS%s\r\n",volume_name);
326 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 330 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
327 if (result!=STATE_OK) 331 if (result!=STATE_OK)
328 return result; 332 return result;
329 total_disk_space=strtoul(recv_buffer,NULL,10); 333 total_disk_space=strtoul(recv_buffer,NULL,10);
@@ -342,7 +346,7 @@ main(int argc, char **argv) {
342 } else if (vars_to_check==DSDB) { 346 } else if (vars_to_check==DSDB) {
343 347
344 send_buffer = strdup ("S11\r\n"); 348 send_buffer = strdup ("S11\r\n");
345 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 349 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
346 if (result!=STATE_OK) 350 if (result!=STATE_OK)
347 return result; 351 return result;
348 if (atoi(recv_buffer)==1) 352 if (atoi(recv_buffer)==1)
@@ -351,7 +355,7 @@ main(int argc, char **argv) {
351 result=STATE_WARNING; 355 result=STATE_WARNING;
352 356
353 send_buffer = strdup ("S13\r\n"); 357 send_buffer = strdup ("S13\r\n");
354 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 358 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
355 temp_buffer=strtok(recv_buffer,"\r\n"); 359 temp_buffer=strtok(recv_buffer,"\r\n");
356 360
357 asprintf (&output_message,_("Directory Services Database is %s (DS version %s)"),(result==STATE_OK)?"open":"closed",temp_buffer); 361 asprintf (&output_message,_("Directory Services Database is %s (DS version %s)"),(result==STATE_OK)?"open":"closed",temp_buffer);
@@ -360,7 +364,7 @@ main(int argc, char **argv) {
360 } else if (vars_to_check==LOGINS) { 364 } else if (vars_to_check==LOGINS) {
361 365
362 send_buffer = strdup ("S12\r\n"); 366 send_buffer = strdup ("S12\r\n");
363 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 367 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
364 if (result!=STATE_OK) 368 if (result!=STATE_OK)
365 return result; 369 return result;
366 if (atoi(recv_buffer)==1) 370 if (atoi(recv_buffer)==1)
@@ -374,14 +378,14 @@ main(int argc, char **argv) {
374 } else if (vars_to_check==UPRB || vars_to_check==PUPRB) { 378 } else if (vars_to_check==UPRB || vars_to_check==PUPRB) {
375 379
376 asprintf (&send_buffer,"S15\r\n"); 380 asprintf (&send_buffer,"S15\r\n");
377 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 381 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
378 if (result!=STATE_OK) 382 if (result!=STATE_OK)
379 return result; 383 return result;
380 384
381 used_packet_receive_buffers=atoi(recv_buffer); 385 used_packet_receive_buffers=atoi(recv_buffer);
382 386
383 asprintf (&send_buffer,"S16\r\n"); 387 asprintf (&send_buffer,"S16\r\n");
384 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 388 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
385 if (result!=STATE_OK) 389 if (result!=STATE_OK)
386 return result; 390 return result;
387 391
@@ -410,7 +414,7 @@ main(int argc, char **argv) {
410 asprintf (&send_buffer,"S9\r\n"); 414 asprintf (&send_buffer,"S9\r\n");
411 else 415 else
412 asprintf (&send_buffer,"S9.%d\r\n",sap_number); 416 asprintf (&send_buffer,"S9.%d\r\n",sap_number);
413 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 417 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
414 if (result!=STATE_OK) 418 if (result!=STATE_OK)
415 return result; 419 return result;
416 420
@@ -430,7 +434,7 @@ main(int argc, char **argv) {
430 } else if (vars_to_check==VKP) { 434 } else if (vars_to_check==VKP) {
431 435
432 asprintf (&send_buffer,"VKP%s\r\n",volume_name); 436 asprintf (&send_buffer,"VKP%s\r\n",volume_name);
433 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 437 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
434 if (result!=STATE_OK) 438 if (result!=STATE_OK)
435 return result; 439 return result;
436 440
@@ -450,7 +454,7 @@ main(int argc, char **argv) {
450 } else if (vars_to_check==VPP) { 454 } else if (vars_to_check==VPP) {
451 455
452 asprintf (&send_buffer,"VKP%s\r\n",volume_name); 456 asprintf (&send_buffer,"VKP%s\r\n",volume_name);
453 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 457 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
454 if (result!=STATE_OK) 458 if (result!=STATE_OK)
455 return result; 459 return result;
456 460
@@ -464,7 +468,7 @@ main(int argc, char **argv) {
464 purgeable_disk_space=strtoul(recv_buffer,NULL,10); 468 purgeable_disk_space=strtoul(recv_buffer,NULL,10);
465 469
466 asprintf (&send_buffer,"VKS%s\r\n",volume_name); 470 asprintf (&send_buffer,"VKS%s\r\n",volume_name);
467 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 471 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
468 if (result!=STATE_OK) 472 if (result!=STATE_OK)
469 return result; 473 return result;
470 total_disk_space=strtoul(recv_buffer,NULL,10); 474 total_disk_space=strtoul(recv_buffer,NULL,10);
@@ -483,7 +487,7 @@ main(int argc, char **argv) {
483 } else if (vars_to_check==VKNP) { 487 } else if (vars_to_check==VKNP) {
484 488
485 asprintf (&send_buffer,"VKNP%s\r\n",volume_name); 489 asprintf (&send_buffer,"VKNP%s\r\n",volume_name);
486 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 490 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
487 if (result!=STATE_OK) 491 if (result!=STATE_OK)
488 return result; 492 return result;
489 493
@@ -503,7 +507,7 @@ main(int argc, char **argv) {
503 } else if (vars_to_check==VPNP) { 507 } else if (vars_to_check==VPNP) {
504 508
505 asprintf (&send_buffer,"VKNP%s\r\n",volume_name); 509 asprintf (&send_buffer,"VKNP%s\r\n",volume_name);
506 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 510 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
507 if (result!=STATE_OK) 511 if (result!=STATE_OK)
508 return result; 512 return result;
509 513
@@ -517,7 +521,7 @@ main(int argc, char **argv) {
517 non_purgeable_disk_space=strtoul(recv_buffer,NULL,10); 521 non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
518 522
519 asprintf (&send_buffer,"VKS%s\r\n",volume_name); 523 asprintf (&send_buffer,"VKS%s\r\n",volume_name);
520 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 524 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
521 if (result!=STATE_OK) 525 if (result!=STATE_OK)
522 return result; 526 return result;
523 total_disk_space=strtoul(recv_buffer,NULL,10); 527 total_disk_space=strtoul(recv_buffer,NULL,10);
@@ -536,7 +540,7 @@ main(int argc, char **argv) {
536 } else if (vars_to_check==OFILES) { 540 } else if (vars_to_check==OFILES) {
537 541
538 asprintf (&send_buffer,"S18\r\n"); 542 asprintf (&send_buffer,"S18\r\n");
539 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 543 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
540 if (result!=STATE_OK) 544 if (result!=STATE_OK)
541 return result; 545 return result;
542 546
@@ -553,7 +557,7 @@ main(int argc, char **argv) {
553 } else if (vars_to_check==ABENDS) { 557 } else if (vars_to_check==ABENDS) {
554 558
555 asprintf (&send_buffer,"S17\r\n"); 559 asprintf (&send_buffer,"S17\r\n");
556 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 560 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
557 if (result!=STATE_OK) 561 if (result!=STATE_OK)
558 return result; 562 return result;
559 563
@@ -570,14 +574,14 @@ main(int argc, char **argv) {
570 } else if (vars_to_check==CSPROCS) { 574 } else if (vars_to_check==CSPROCS) {
571 575
572 asprintf (&send_buffer,"S20\r\n"); 576 asprintf (&send_buffer,"S20\r\n");
573 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 577 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
574 if (result!=STATE_OK) 578 if (result!=STATE_OK)
575 return result; 579 return result;
576 580
577 max_service_processes=atoi(recv_buffer); 581 max_service_processes=atoi(recv_buffer);
578 582
579 asprintf (&send_buffer,"S21\r\n"); 583 asprintf (&send_buffer,"S21\r\n");
580 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 584 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
581 if (result!=STATE_OK) 585 if (result!=STATE_OK)
582 return result; 586 return result;
583 587
@@ -597,7 +601,7 @@ main(int argc, char **argv) {
597 } else if (vars_to_check==TSYNC) { 601 } else if (vars_to_check==TSYNC) {
598 602
599 asprintf (&send_buffer,"S22\r\n"); 603 asprintf (&send_buffer,"S22\r\n");
600 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 604 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
601 if (result!=STATE_OK) 605 if (result!=STATE_OK)
602 return result; 606 return result;
603 607
@@ -615,7 +619,7 @@ main(int argc, char **argv) {
615 } else if (vars_to_check==LRUS) { 619 } else if (vars_to_check==LRUS) {
616 620
617 send_buffer = strdup ("S4\r\n"); 621 send_buffer = strdup ("S4\r\n");
618 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 622 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
619 if (result!=STATE_OK) 623 if (result!=STATE_OK)
620 return result; 624 return result;
621 lru_time=strtoul(recv_buffer,NULL,10); 625 lru_time=strtoul(recv_buffer,NULL,10);
@@ -631,7 +635,7 @@ main(int argc, char **argv) {
631 } else if (vars_to_check==DCB) { 635 } else if (vars_to_check==DCB) {
632 636
633 send_buffer = strdup ("S6\r\n"); 637 send_buffer = strdup ("S6\r\n");
634 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 638 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
635 if (result!=STATE_OK) 639 if (result!=STATE_OK)
636 return result; 640 return result;
637 dirty_cache_buffers=atoi(recv_buffer); 641 dirty_cache_buffers=atoi(recv_buffer);
@@ -646,7 +650,7 @@ main(int argc, char **argv) {
646 } else if (vars_to_check==TCB) { 650 } else if (vars_to_check==TCB) {
647 651
648 send_buffer = strdup ("S7\r\n"); 652 send_buffer = strdup ("S7\r\n");
649 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 653 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
650 if (result!=STATE_OK) 654 if (result!=STATE_OK)
651 return result; 655 return result;
652 total_cache_buffers=atoi(recv_buffer); 656 total_cache_buffers=atoi(recv_buffer);
@@ -659,7 +663,7 @@ main(int argc, char **argv) {
659 663
660 } else if (vars_to_check==DSVER) { 664 } else if (vars_to_check==DSVER) {
661 asprintf (&send_buffer,"S13\r\n"); 665 asprintf (&send_buffer,"S13\r\n");
662 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 666 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
663 if (result!=STATE_OK) 667 if (result!=STATE_OK)
664 return result; 668 return result;
665 669
@@ -668,7 +672,7 @@ main(int argc, char **argv) {
668 asprintf (&output_message,_("NDS Version %s"),recv_buffer); 672 asprintf (&output_message,_("NDS Version %s"),recv_buffer);
669 673
670 } else if (vars_to_check==UPTIME) { 674 } else if (vars_to_check==UPTIME) {
671 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 675 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
672 if (result!=STATE_OK) 676 if (result!=STATE_OK)
673 return result; 677 return result;
674 678
@@ -678,7 +682,7 @@ main(int argc, char **argv) {
678 682
679 } else if (vars_to_check==NLM) { 683 } else if (vars_to_check==NLM) {
680 asprintf (&send_buffer,"S24:%s\r\n",nlm_name); 684 asprintf (&send_buffer,"S24:%s\r\n",nlm_name);
681 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); 685 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
682 if (result!=STATE_OK) 686 if (result!=STATE_OK)
683 return result; 687 return result;
684 688
@@ -697,6 +701,8 @@ main(int argc, char **argv) {
697 701
698 } 702 }
699 703
704 close (sd);
705
700 /* reset timeout */ 706 /* reset timeout */
701 alarm(0); 707 alarm(0);
702 708
diff --git a/plugins/netutils.c b/plugins/netutils.c
index 55f02ca..5017eb9 100644
--- a/plugins/netutils.c
+++ b/plugins/netutils.c
@@ -168,11 +168,7 @@ process_request (const char *server_address, int server_port, int proto,
168 const char *send_buffer, char *recv_buffer, int recv_size) 168 const char *send_buffer, char *recv_buffer, int recv_size)
169{ 169{
170 int result; 170 int result;
171 int send_result;
172 int recv_result;
173 int sd; 171 int sd;
174 struct timeval tv;
175 fd_set readfds;
176 172
177 result = STATE_OK; 173 result = STATE_OK;
178 174
@@ -180,41 +176,7 @@ process_request (const char *server_address, int server_port, int proto,
180 if (result != STATE_OK) 176 if (result != STATE_OK)
181 return STATE_CRITICAL; 177 return STATE_CRITICAL;
182 178
183 send_result = send (sd, send_buffer, strlen (send_buffer), 0); 179 result = send_request (sd, proto, send_buffer, recv_buffer, recv_size);
184 if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
185 printf ("send() failed\n");
186 result = STATE_WARNING;
187 }
188
189 /* wait up to the number of seconds for socket timeout minus one
190 for data from the host */
191 tv.tv_sec = socket_timeout - 1;
192 tv.tv_usec = 0;
193 FD_ZERO (&readfds);
194 FD_SET (sd, &readfds);
195 select (sd + 1, &readfds, NULL, NULL, &tv);
196
197 /* make sure some data has arrived */
198 if (!FD_ISSET (sd, &readfds)) {
199 strcpy (recv_buffer, "");
200 printf ("No data was received from host!\n");
201 result = STATE_WARNING;
202 }
203
204 else {
205 recv_result = recv (sd, recv_buffer, (size_t)recv_size - 1, 0);
206 if (recv_result == -1) {
207 strcpy (recv_buffer, "");
208 if (proto != IPPROTO_TCP)
209 printf ("recv() failed\n");
210 result = STATE_WARNING;
211 }
212 else
213 recv_buffer[recv_result] = 0;
214
215 /* die returned string */
216 recv_buffer[recv_size - 1] = 0;
217 }
218 180
219 close (sd); 181 close (sd);
220 182
@@ -315,6 +277,69 @@ my_connect (const char *host_name, int port, int *sd, int proto)
315 } 277 }
316} 278}
317 279
280
281int
282send_tcp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size)
283{
284 return send_request (sd, IPPROTO_TCP, send_buffer, recv_buffer, recv_size);
285}
286
287
288int
289send_udp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size)
290{
291 return send_request (sd, IPPROTO_UDP, send_buffer, recv_buffer, recv_size);
292}
293
294
295int
296send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size)
297{
298 int result;
299 int send_result;
300 int recv_result;
301 struct timeval tv;
302 fd_set readfds;
303
304 send_result = send (sd, send_buffer, strlen (send_buffer), 0);
305 if (send_result<0 || (size_t)send_result!=strlen(send_buffer)) {
306 printf ("send() failed\n");
307 result = STATE_WARNING;
308 }
309
310 /* wait up to the number of seconds for socket timeout minus one
311 for data from the host */
312 tv.tv_sec = socket_timeout - 1;
313 tv.tv_usec = 0;
314 FD_ZERO (&readfds);
315 FD_SET (sd, &readfds);
316 select (sd + 1, &readfds, NULL, NULL, &tv);
317
318 /* make sure some data has arrived */
319 if (!FD_ISSET (sd, &readfds)) {
320 strcpy (recv_buffer, "");
321 printf ("No data was received from host!\n");
322 result = STATE_WARNING;
323 }
324
325 else {
326 recv_result = recv (sd, recv_buffer, (size_t)recv_size - 1, 0);
327 if (recv_result == -1) {
328 strcpy (recv_buffer, "");
329 if (proto != IPPROTO_TCP)
330 printf ("recv() failed\n");
331 result = STATE_WARNING;
332 }
333 else
334 recv_buffer[recv_result] = 0;
335
336 /* die returned string */
337 recv_buffer[recv_size - 1] = 0;
338 }
339 return result;
340}
341
342
318int 343int
319is_host (const char *address) 344is_host (const char *address)
320{ 345{
diff --git a/plugins/netutils.h b/plugins/netutils.h
index 88a5162..b2c2a2f 100644
--- a/plugins/netutils.h
+++ b/plugins/netutils.h
@@ -48,6 +48,10 @@ int process_request (const char *address, int port, int proto,
48int my_tcp_connect (const char *address, int port, int *sd); 48int my_tcp_connect (const char *address, int port, int *sd);
49int my_udp_connect (const char *address, int port, int *sd); 49int my_udp_connect (const char *address, int port, int *sd);
50 50
51int send_tcp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size);
52int send_udp_request (int sd, const char *send_buffer, char *recv_buffer, int recv_size);
53int send_request (int sd, int proto, const char *send_buffer, char *recv_buffer, int recv_size);
54
51int is_host (const char *); 55int is_host (const char *);
52int is_addr (const char *); 56int is_addr (const char *);
53int resolve_host_or_addr (const char *, int); 57int resolve_host_or_addr (const char *, int);