/[monit]/monit/net.c
ViewVC logotype

Diff of /monit/net.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.45 by rory, Tue Oct 21 21:06:28 2003 UTC revision 1.46 by rory, Tue Oct 21 22:49:04 2003 UTC
# Line 39  Line 39 
39  #define _BSD_SOCKLEN_T_  #define _BSD_SOCKLEN_T_
40  #endif  #endif
41    
42  #ifdef HAVE_NETINET_IN_H  #ifdef HAVE_SOL_IP
43    #define ICMP_SIZE sizeof(struct icmphdr)
44    #else
45    #define ICMP_SIZE sizeof(struct icmp)
46  #include <netinet/in_systm.h>  #include <netinet/in_systm.h>
47    #endif
48    
49    #ifdef HAVE_NETINET_IN_H
50  #include <netinet/in.h>  #include <netinet/in.h>
51  #endif  #endif
52    
# Line 598  int icmp_echo(const char *hostname, int Line 604  int icmp_echo(const char *hostname, int
604    struct hostent *hp;    struct hostent *hp;
605    struct sockaddr_in sin;    struct sockaddr_in sin;
606    struct sockaddr_in sout;    struct sockaddr_in sout;
607    #ifdef HAVE_SOL_IP
608    struct iphdr *iphdrin;    struct iphdr *iphdrin;
609    struct icmphdr *icmphdrin= NULL;    struct icmphdr *icmphdrin= NULL;
610    struct icmphdr *icmphdrout= NULL;    struct icmphdr *icmphdrout= NULL;
611    #else
612      struct ip *iphdrin;
613      struct icmp *icmphdrin= NULL;
614      struct icmp *icmphdrout= NULL;
615    #endif
616    struct timeval tv;    struct timeval tv;
617    size_t size;    size_t size;
618    fd_set rset;    fd_set rset;
# Line 633  int icmp_echo(const char *hostname, int Line 645  int icmp_echo(const char *hostname, int
645      goto error;      goto error;
646    
647    NEW(icmphdrout);    NEW(icmphdrout);
648    #ifdef HAVE_SOL_IP
649    icmphdrout->code= 0;    icmphdrout->code= 0;
650    icmphdrout->type= ICMP_ECHO;    icmphdrout->type= ICMP_ECHO;
651    icmphdrout->un.echo.id= getpid();    icmphdrout->un.echo.id= getpid();
652    icmphdrout->un.echo.sequence= 0;    icmphdrout->un.echo.sequence= 0;
653    icmphdrout->checksum= checksum_ip((unsigned char *)icmphdrout,    icmphdrout->checksum= checksum_ip((unsigned char *)icmphdrout,
654                                      sizeof(struct icmphdr));                                      ICMP_SIZE);
655    #else
656      icmphdrout->icmp_code= 0;
657      icmphdrout->icmp_type= ICMP_ECHO;
658      icmphdrout->icmp_id= getpid();
659      icmphdrout->icmp_seq= 0;
660      icmphdrout->icmp_cksum= checksum_ip((unsigned char *)icmphdrout,
661                                        ICMP_SIZE);
662    #endif
663    sout.sin_family= AF_INET;    sout.sin_family= AF_INET;
664    sout.sin_port= 0;    sout.sin_port= 0;
665    memcpy(&sout.sin_addr, hp->h_addr, hp->h_length);    memcpy(&sout.sin_addr, hp->h_addr, hp->h_length);
666    
667    do {    do {
668      n= sendto(s, (char *)icmphdrout, sizeof(struct icmphdr), 0,      n= sendto(s, (char *)icmphdrout, ICMP_SIZE, 0,
669                (struct sockaddr *)&sout, sizeof(struct sockaddr));                (struct sockaddr *)&sout, sizeof(struct sockaddr));
670    } while(n == -1 && errno == EINTR);    } while(n == -1 && errno == EINTR);
671        
# Line 672  int icmp_echo(const char *hostname, int Line 693  int icmp_echo(const char *hostname, int
693      if(n < 0)      if(n < 0)
694          goto error;          goto error;
695            
696    #ifdef HAVE_SOL_IP
697      iphdrin= (struct iphdr *)buf;      iphdrin= (struct iphdr *)buf;
698      icmphdrin= (struct icmphdr *)(buf + iphdrin->ihl * 4);      icmphdrin= (struct icmphdr *)(buf + iphdrin->ihl * 4);
   
699      if( (icmphdrin->un.echo.id == icmphdrout->un.echo.id) &&      if( (icmphdrin->un.echo.id == icmphdrout->un.echo.id) &&
700          (icmphdrin->type == ICMP_ECHOREPLY) &&          (icmphdrin->type == ICMP_ECHOREPLY) &&
701          (icmphdrin->un.echo.sequence == icmphdrout->un.echo.sequence) ) {          (icmphdrin->un.echo.sequence == icmphdrout->un.echo.sequence) ) {
702    #else
703        iphdrin= (struct ip *)buf;
704        icmphdrin= (struct icmp *)(buf + iphdrin->ip_hl * 4);
705        if( (icmphdrin->icmp_id == icmphdrout->icmp_id) &&
706            (icmphdrin->icmp_type == ICMP_ECHOREPLY) &&
707            (icmphdrin->icmp_seq == icmphdrout->icmp_seq) ) {
708    #endif
709    
710        rv= TRUE;        rv= TRUE;
711        break;        break;
712    
713      }      }
714    
715    #ifdef HAVE_SOL_IP
716    } while(! ( (icmphdrin->un.echo.id == icmphdrout->un.echo.id) &&    } while(! ( (icmphdrin->un.echo.id == icmphdrout->un.echo.id) &&
717                (icmphdrin->type == ICMP_ECHOREPLY) &&                (icmphdrin->type == ICMP_ECHOREPLY) &&
718                (icmphdrin->un.echo.sequence == icmphdrout->un.echo.sequence) ) );                (icmphdrin->un.echo.sequence == icmphdrout->un.echo.sequence) ) );
719    #else
720      } while(! ( (icmphdrin->icmp_id == icmphdrout->icmp_id) &&
721                  (icmphdrin->icmp_type == ICMP_ECHOREPLY) &&
722                  (icmphdrin->icmp_seq == icmphdrout->icmp_seq) ) );
723    #endif
724    error:    error:
725    FREE(icmphdrout);    FREE(icmphdrout);
726    close_socket(s);    close_socket(s);

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.46

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26