aboutsummaryrefslogtreecommitdiff
path: root/plugins-root
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-root')
-rw-r--r--plugins-root/check_dhcp.c60
-rw-r--r--plugins-root/check_icmp.c9
-rw-r--r--plugins-root/pst3.c4
3 files changed, 27 insertions, 46 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c
index b874c555..88b7ca10 100644
--- a/plugins-root/check_dhcp.c
+++ b/plugins-root/check_dhcp.c
@@ -229,7 +229,7 @@ struct in_addr requested_address;
int process_arguments(int, char **);
int call_getopt(int, char **);
-int validate_arguments(void);
+int validate_arguments(int, int);
void print_usage(void);
void print_help(void);
@@ -463,10 +463,9 @@ int send_dhcp_discover(int sock){
discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH;
/*
- * transaction ID is supposed to be random. We won't use the address so
- * we don't care about high entropy here. time(2) is good enough.
+ * transaction ID is supposed to be random.
*/
- srand(time(NULL));
+ srand(time(NULL)^getpid());
packet_xid=random();
discover_packet.xid=htonl(packet_xid);
@@ -692,17 +691,11 @@ int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, st
}
else{
-
- /* why do we need to peek first? i don't know, its a hack. without it, the source address of the first packet received was
- not being interpreted correctly. sigh... */
bzero(&source_address,sizeof(source_address));
address_size=sizeof(source_address);
recv_result=recvfrom(sock,(char *)buffer,buffer_size,MSG_PEEK,(struct sockaddr *)&source_address,&address_size);
if(verbose)
- printf("recv_result_1: %d\n",recv_result);
- recv_result=recvfrom(sock,(char *)buffer,buffer_size,0,(struct sockaddr *)&source_address,&address_size);
- if(verbose)
- printf("recv_result_2: %d\n",recv_result);
+ printf("recv_result: %d\n",recv_result);
if(recv_result==-1){
if(verbose){
@@ -1059,29 +1052,19 @@ int get_results(void){
/* process command-line arguments */
int process_arguments(int argc, char **argv){
- int c;
+ int arg_index;
if(argc<1)
return ERROR;
- c=0;
- while((c+=(call_getopt(argc-c,&argv[c])))<argc){
-
- /*
- if(is_option(argv[c]))
- continue;
- */
- }
-
- return validate_arguments();
+ arg_index = call_getopt(argc,argv);
+ return validate_arguments(argc,arg_index);
}
int call_getopt(int argc, char **argv){
- int c=0;
- int i=0;
-
+ extern int optind;
int option_index = 0;
static struct option long_options[] =
{
@@ -1098,25 +1081,14 @@ int call_getopt(int argc, char **argv){
};
while(1){
- c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index);
+ int c=0;
- i++;
+ c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index);
if(c==-1||c==EOF||c==1)
break;
switch(c){
- case 'w':
- case 'r':
- case 't':
- case 'i':
- i++;
- break;
- default:
- break;
- }
-
- switch(c){
case 's': /* DHCP server address */
resolve_host(optarg,&dhcp_ip);
@@ -1163,11 +1135,11 @@ int call_getopt(int argc, char **argv){
case 'V': /* version */
print_revision(progname, NP_VERSION);
- exit(STATE_OK);
+ exit(STATE_UNKNOWN);
case 'h': /* help */
print_help();
- exit(STATE_OK);
+ exit(STATE_UNKNOWN);
case 'v': /* verbose */
verbose=1;
@@ -1181,12 +1153,14 @@ int call_getopt(int argc, char **argv){
break;
}
}
-
- return i;
+ return optind;
}
-int validate_arguments(void){
+int validate_arguments(int argc, int arg_index){
+
+ if(argc-optind > 0)
+ usage(_("Got unexpected non-option argument"));
return OK;
}
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 3982def9..9ed12ba1 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -526,10 +526,10 @@ main(int argc, char **argv)
break;
case 'V': /* version */
print_revision (progname, NP_VERSION);
- exit (STATE_OK);
+ exit (STATE_UNKNOWN);
case 'h': /* help */
print_help ();
- exit (STATE_OK);
+ exit (STATE_UNKNOWN);
}
}
}
@@ -880,7 +880,12 @@ send_icmp_ping(int sock, struct rta_host *host)
hdr.msg_iov = &iov;
hdr.msg_iovlen = 1;
+/* MSG_CONFIRM is a linux thing and only available on linux kernels >= 2.3.15, see send(2) */
+#ifdef MSG_CONFIRM
len = sendmsg(sock, &hdr, MSG_CONFIRM);
+#else
+ len = sendmsg(sock, &hdr, 0);
+#endif
if(len < 0 || (unsigned int)len != icmp_pkt_size) {
if(debug) printf("Failed to send ping to %s\n",
diff --git a/plugins-root/pst3.c b/plugins-root/pst3.c
index ee9d108d..c3589f0a 100644
--- a/plugins-root/pst3.c
+++ b/plugins-root/pst3.c
@@ -139,8 +139,10 @@ try_again:
if((ps_fd = open(ps_name, O_RDONLY)) == -1)
continue;
- if((as_fd = open(as_name, O_RDONLY)) == -1)
+ if((as_fd = open(as_name, O_RDONLY)) == -1) {
+ close(ps_fd);
continue;
+ }
if(read(ps_fd, &psinfo, sizeof(psinfo)) != sizeof(psinfo)) {
int err = errno;