Back to index

nagios-plugins  1.4.16
Functions | Variables
util.c File Reference
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <pwd.h>
#include <time.h>
#include <ctype.h>
#include <signal.h>
#include "radiusd.h"

Go to the source code of this file.

Functions

char * ip_hostname (UINT4 ipaddr)
UINT4 get_ipaddr (char *host)
int good_ipaddr (char *addr)
void ipaddr2str (char *buffer, UINT4 ipaddr)
UINT4 ipstr2long (char *ip_str)
struct passwd * rad_getpwnam (char *name)
void pairfree (VALUE_PAIR *pair)
VALUE_PAIRpairfind (VALUE_PAIR *first, int attr)
void pairdelete (VALUE_PAIR **first, int attr)
void pairadd (VALUE_PAIR **first, VALUE_PAIR *new)
void authfree (AUTH_REQ *authreq)
char * strNcpy (char *dest, char *src, int n)

Variables

char util_sccsid [] = " 2.1 Copyright 1997 Cistron Internet Services B.V."

Function Documentation

void authfree ( AUTH_REQ authreq)

Definition at line 278 of file util.c.

{
       pairfree(authreq->request);
       memset(authreq, 0, sizeof(AUTH_REQ));
       free(authreq);
}

Here is the call graph for this function:

UINT4 get_ipaddr ( char *  host)

Definition at line 77 of file util.c.

{
       struct hostent       *hp;
       UINT4         ipstr2long();

       if(good_ipaddr(host) == 0) {
              return(ipstr2long(host));
       }
       else if((hp = gethostbyname(host)) == (struct hostent *)NULL) {
              return((UINT4)0);
       }
       return(ntohl(*(UINT4 *)hp->h_addr));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int good_ipaddr ( char *  addr)

Definition at line 95 of file util.c.

{
       int    dot_count;
       int    digit_count;

       dot_count = 0;
       digit_count = 0;
       while(*addr != '\0' && *addr != ' ') {
              if(*addr == '.') {
                     dot_count++;
                     digit_count = 0;
              }
              else if(!isdigit(*addr)) {
                     dot_count = 5;
              }
              else {
                     digit_count++;
                     if(digit_count > 3) {
                            dot_count = 5;
                     }
              }
              addr++;
       }
       if(dot_count != 3) {
              return(-1);
       }
       else {
              return(0);
       }
}

Here is the caller graph for this function:

char* ip_hostname ( UINT4  ipaddr)

Definition at line 57 of file util.c.

{
       struct        hostent *hp;
       static char   hstname[128];
       UINT4         n_ipaddr;

       n_ipaddr = htonl(ipaddr);
       hp = gethostbyaddr((char *)&n_ipaddr, sizeof (struct in_addr), AF_INET);
       if (hp == 0) {
              ipaddr2str(hstname, ipaddr);
              return(hstname);
       }
       return (char *)hp->h_name;
}

Here is the call graph for this function:

void ipaddr2str ( char *  buffer,
UINT4  ipaddr 
)

Definition at line 131 of file util.c.

{
       int    addr_byte[4];
       int    i;
       UINT4  xbyte;

       for(i = 0;i < 4;i++) {
              xbyte = ipaddr >> (i*8);
              xbyte = xbyte & (UINT4)0x000000FF;
              addr_byte[i] = xbyte;
       }
       sprintf(buffer, "%u.%u.%u.%u", addr_byte[3], addr_byte[2],
              addr_byte[1], addr_byte[0]);
}

Here is the caller graph for this function:

UINT4 ipstr2long ( char *  ip_str)

Definition at line 151 of file util.c.

{
       char   buf[6];
       char   *ptr;
       int    i;
       int    count;
       UINT4  ipaddr;
       int    cur_byte;

       ipaddr = (UINT4)0;
       for(i = 0;i < 4;i++) {
              ptr = buf;
              count = 0;
              *ptr = '\0';
              while(*ip_str != '.' && *ip_str != '\0' && count < 4) {
                     if(!isdigit(*ip_str)) {
                            return((UINT4)0);
                     }
                     *ptr++ = *ip_str++;
                     count++;
              }
              if(count >= 4 || count == 0) {
                     return((UINT4)0);
              }
              *ptr = '\0';
              cur_byte = atoi(buf);
              if(cur_byte < 0 || cur_byte > 255) {
                     return((UINT4)0);
              }
              ip_str++;
              ipaddr = ipaddr << 8 | (UINT4)cur_byte;
       }
       return(ipaddr);
}

Here is the caller graph for this function:

void pairadd ( VALUE_PAIR **  first,
VALUE_PAIR new 
)

Definition at line 261 of file util.c.

{
       VALUE_PAIR *i;

       new->next = NULL;
       if (*first == NULL) {
              *first = new;
              return;
       }
       for(i = *first; i->next; i = i->next)
              ;
       i->next = new;
}
void pairdelete ( VALUE_PAIR **  first,
int  attr 
)

Definition at line 241 of file util.c.

{
       VALUE_PAIR *i, *next, *last = NULL;

       for(i = *first; i; i = next) {
              next = i->next;
              if (i->attribute == attr) {
                     if (last)
                            last->next = next;
                     else
                            *first = next;
                     free(i);
              } else
                     last = i;
       }
}
VALUE_PAIR* pairfind ( VALUE_PAIR first,
int  attr 
)

Definition at line 230 of file util.c.

{
       while(first && first->attribute != attr)
              first = first->next;
       return first;
}
void pairfree ( VALUE_PAIR pair)

Definition at line 215 of file util.c.

{
       VALUE_PAIR    *next;

       while(pair != NULL) {
              next = pair->next;
              free(pair);
              pair = next;
       }
}

Here is the caller graph for this function:

struct passwd* rad_getpwnam ( char *  name) [read]

Definition at line 190 of file util.c.

{
       static struct passwd *lastpwd;
       static char lastname[64];
       static time_t lasttime = 0;
       time_t now;

       now = time(NULL);

       if ((now <= lasttime + 5 ) && strncmp(name, lastname, 64) == 0)
              return lastpwd;

       strncpy(lastname, name, 63);
       lastname[63] = 0;
       lastpwd = getpwnam(name);
       lasttime = now;

       return lastpwd;
}
char* strNcpy ( char *  dest,
char *  src,
int  n 
)

Definition at line 311 of file util.c.

{
       if (n > 0)
              strncpy(dest, src, n);
       else
              n = 1;
       dest[n - 1] = 0;

       return dest;
}

Here is the caller graph for this function:


Variable Documentation

char util_sccsid[] = " 2.1 Copyright 1997 Cistron Internet Services B.V."

Definition at line 34 of file util.c.