diff --git a/nping/ArgParser.cc b/nping/ArgParser.cc index d3f539d15..bd8fc1b6d 100644 --- a/nping/ArgParser.cc +++ b/nping/ArgParser.cc @@ -300,27 +300,27 @@ char errstr[256]; /* PROBE MODES ***************************************************************/ if (optcmp(long_options[option_index].name, "tcp-connect") == 0) { if( o.issetMode() && o.getMode()!=TCP_CONNECT) - outFatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", + nping_fatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", strdup( o.mode2Ascii(TCP_CONNECT) ), strdup( o.mode2Ascii(o.getMode()) ) ); o.setMode(TCP_CONNECT); } else if (optcmp(long_options[option_index].name, "tcp") == 0) { if( o.issetMode() && o.getMode()!=TCP) - outFatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", + nping_fatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", strdup( o.mode2Ascii(TCP) ), strdup( o.mode2Ascii(o.getMode()) ) ); o.setMode(TCP); } else if (optcmp(long_options[option_index].name, "udp") == 0) { if( o.issetMode() && o.getMode()!=UDP) - outFatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", + nping_fatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", strdup( o.mode2Ascii(UDP) ), strdup( o.mode2Ascii(o.getMode()) ) ); o.setMode(UDP); } else if (optcmp(long_options[option_index].name, "icmp") == 0) { if( o.issetMode() && o.getMode()!=ICMP) - outFatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", + nping_fatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", strdup( o.mode2Ascii(ICMP) ), strdup( o.mode2Ascii(o.getMode()) ) ); o.setMode(ICMP); } else if (optcmp(long_options[option_index].name, "arp") == 0) { if( o.issetMode() && o.getMode()!=ARP) - outFatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", + nping_fatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", strdup( o.mode2Ascii(ARP) ), strdup( o.mode2Ascii(o.getMode()) ) ); o.setMode(ARP); } else if (optcmp(long_options[option_index].name, "traceroute") == 0 || @@ -330,55 +330,55 @@ char errstr[256]; /* Now shortcuts that we support but that are not actual modes */ } else if (optcmp(long_options[option_index].name, "arp-request") == 0) { if( o.issetMode() && o.getMode()!=ARP) - outFatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", + nping_fatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", strdup( o.mode2Ascii(ARP) ), strdup( o.mode2Ascii(o.getMode()) ) ); o.setMode(ARP); o.setARPOpCode(OP_ARP_REQUEST); } else if (optcmp(long_options[option_index].name, "arp-reply") == 0) { if( o.issetMode() && o.getMode()!=ARP) - outFatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", + nping_fatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", strdup( o.mode2Ascii(ARP) ), strdup( o.mode2Ascii(o.getMode()) ) ); o.setMode(ARP); o.setARPOpCode(OP_ARP_REPLY); } else if (optcmp(long_options[option_index].name, "rarp-request") == 0) { if( o.issetMode() && o.getMode()!=ARP) - outFatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", + nping_fatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", strdup( o.mode2Ascii(ARP) ), strdup( o.mode2Ascii(o.getMode()) ) ); o.setMode(ARP); o.setARPOpCode(OP_RARP_REQUEST); } else if (optcmp(long_options[option_index].name, "rarp-reply") == 0) { if( o.issetMode() && o.getMode()!=ARP) - outFatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", + nping_fatal(QT_3,"Cannot specify more than one probe mode. Choose either %s or %s.", strdup( o.mode2Ascii(ARP) ), strdup( o.mode2Ascii(o.getMode()) ) ); o.setMode(ARP); o.setARPOpCode(OP_RARP_REPLY); } else if (optcmp(long_options[option_index].name, "destination-unreachable") == 0 || optcmp(long_options[option_index].name, "dest-unr") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP Destination unreachable messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP Destination unreachable messages.", o.mode2Ascii(o.getMode())); o.setMode(ICMP); o.setICMPType( ICMP_UNREACH ); } else if( optcmp(long_options[option_index].name, "echo-request") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP Echo request messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP Echo request messages.", o.mode2Ascii(o.getMode())); o.setMode(ICMP); o.setICMPType( ICMP_ECHO ); } else if (optcmp(long_options[option_index].name, "timestamp") == 0 || optcmp(long_options[option_index].name, "timestamp-request") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP Timestamp request messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP Timestamp request messages.", o.mode2Ascii(o.getMode())); o.setMode(ICMP); o.setICMPType( ICMP_TSTAMP ); } else if (optcmp(long_options[option_index].name, "information") == 0 || optcmp(long_options[option_index].name, "information-request") == 0 ) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP Information request messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP Information request messages.", o.mode2Ascii(o.getMode())); o.setMode(ICMP); o.setICMPType( ICMP_TSTAMP ); } else if (optcmp(long_options[option_index].name, "netmask") == 0 || optcmp(long_options[option_index].name, "netmask-request") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP Information request messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP Information request messages.", o.mode2Ascii(o.getMode())); o.setMode(ICMP); o.setICMPType( ICMP_MASK ); @@ -387,7 +387,7 @@ char errstr[256]; /* TCP Sequence number */ } else if (optcmp(long_options[option_index].name, "seq") == 0) { if ( parse_u32(optarg, &aux32) != OP_SUCCESS ) - outFatal(QT_3, "Invalid TCP Sequence number. Value must be 0<=N<2^32."); + nping_fatal(QT_3, "Invalid TCP Sequence number. Value must be 0<=N<2^32."); else o.setTCPSequence( aux32 ); /* TCP Flags */ @@ -399,7 +399,7 @@ char errstr[256]; if( meansRandom(optarg) ){ aux8=get_random_u8(); }else if(aux32>255){ - outFatal(QT_3, "Invalid TCP flag specification. Numerical values must be in the range [0,255]."); + nping_fatal(QT_3, "Invalid TCP flag specification. Numerical values must be in the range [0,255]."); }else{ aux8=(u8)aux32; } @@ -426,7 +426,7 @@ char errstr[256]; /* CASE 2: User supplied a list of flags in the format "syn,ack,ecn" */ }else if( contains(optarg, ",") ){ if( ((strlen(optarg)+1)%4) !=0 ) - outFatal(QT_3, "Invalid format in --flag. Make sure you specify a comma-separed list that contains 3-charater flag names (e.g: --flags syn,ack,psh)"); + nping_fatal(QT_3, "Invalid format in --flag. Make sure you specify a comma-separed list that contains 3-charater flag names (e.g: --flags syn,ack,psh)"); for( size_t f=0; f< strlen(optarg); f+=4 ){ if(!strncasecmp((optarg+f), "CWR",3)){ o.setFlagTCP(FLAG_CWR); } @@ -444,7 +444,7 @@ char errstr[256]; char wrongopt[4]; memcpy(wrongopt, (optarg+f), 3); wrongopt[3]='\0'; - outFatal(QT_3, "Invalid TCP flag specification: \"%s\"", wrongopt); + nping_fatal(QT_3, "Invalid TCP flag specification: \"%s\"", wrongopt); } } @@ -488,9 +488,9 @@ char errstr[256]; case 'F': case 'f': o.setFlagTCP(FLAG_FIN); break; default: if( isdigit(optarg[f]) ) - outFatal(QT_3, "Invalid TCP flag supplied (%c). If you want to specify flags using a number you must add prefix \"0x\"", optarg[f]); + nping_fatal(QT_3, "Invalid TCP flag supplied (%c). If you want to specify flags using a number you must add prefix \"0x\"", optarg[f]); else - outFatal(QT_3, "Invalid TCP flag supplied: %c", optarg[f]); + nping_fatal(QT_3, "Invalid TCP flag supplied: %c", optarg[f]); } } @@ -499,13 +499,13 @@ char errstr[256]; /* TCP Acknowledgement number */ } else if (optcmp(long_options[option_index].name, "ack") == 0) { if ( parse_u32(optarg, &aux32) != OP_SUCCESS ) - outFatal(QT_3, "Invalid TCP ACK number. Value must be 0<=N<2^32."); + nping_fatal(QT_3, "Invalid TCP ACK number. Value must be 0<=N<2^32."); else o.setTCPAck( aux32 ); /* TCP Window size */ } else if (optcmp(long_options[option_index].name, "win") == 0) { if ( parse_u16(optarg, &aux16) != OP_SUCCESS ) - outFatal(QT_3, "Invalid TCP Window size. Value must be 0<=N<65535."); + nping_fatal(QT_3, "Invalid TCP Window size. Value must be 0<=N<65535."); else o.setTCPWindow( aux16 ); /* Set a bad TCP checksum */ @@ -523,7 +523,7 @@ char errstr[256]; /* ICMP Type */ } else if (optcmp(long_options[option_index].name, "icmp-type") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); /* User may have supplied type as a number */ if ( parse_u8(optarg, &aux8) == OP_SUCCESS ) o.setICMPType( aux8 ); @@ -532,14 +532,14 @@ char errstr[256]; o.setICMPType( aux8 ); /* Looks like user supplied a bogus value */ else - outFatal(QT_3, "Invalid ICMP Type. Value must be 0<=N<=255."); + nping_fatal(QT_3, "Invalid ICMP Type. Value must be 0<=N<=255."); /* Warn if ICMP Type is not RFC-compliant */ if( !isICMPType(aux8) ) - outError(QT_1, "Warning: Specified ICMP type (%d) is not RFC compliant.", aux8); + nping_warning(QT_1, "Warning: Specified ICMP type (%d) is not RFC compliant.", aux8); /* ICMP Code */ } else if (optcmp(long_options[option_index].name, "icmp-code") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); /* User may have supplied code as a number */ if ( parse_u8(optarg, &aux8) == OP_SUCCESS ) o.setICMPCode( aux8 ); @@ -548,56 +548,56 @@ char errstr[256]; o.setICMPCode( aux8 ); /* Looks like user supplied a bogus value */ else - outFatal(QT_3, "Invalid ICMP Code. Value must be 0<=N<=255."); + nping_fatal(QT_3, "Invalid ICMP Code. Value must be 0<=N<=255."); /* ICMP Identification field */ } else if (optcmp(long_options[option_index].name, "icmp-id") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); if ( parse_u16(optarg, &aux16) == OP_SUCCESS ) o.setICMPIdentifier( aux16 ); else - outFatal(QT_3, "Invalid ICMP Identifier. Value must be 0<=N<2^16."); + nping_fatal(QT_3, "Invalid ICMP Identifier. Value must be 0<=N<2^16."); /* ICMP Sequence number */ } else if (optcmp(long_options[option_index].name, "icmp-seq") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); if ( parse_u16(optarg, &aux16) == OP_SUCCESS ) o.setICMPSequence( aux16 ); else - outFatal(QT_3, "Invalid ICMP Sequence number. Value must be 0<=N<2^16."); + nping_fatal(QT_3, "Invalid ICMP Sequence number. Value must be 0<=N<2^16."); /* ICMP Redirect Address */ } else if (optcmp(long_options[option_index].name, "icmp-redirect-addr") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); if( meansRandom(optarg) ){ while ( (aux_ip4.s_addr=get_random_u32()) == 0 ); o.setICMPRedirectAddress( aux_ip4 ); }else{ if ( atoIP(optarg, &aux_ip4) != OP_SUCCESS) - outFatal(QT_3, "Could not resolve specified ICMP Redirect Address."); + nping_fatal(QT_3, "Could not resolve specified ICMP Redirect Address."); else o.setICMPRedirectAddress( aux_ip4 ); } /* ICMP Parameter problem pointer */ } else if (optcmp(long_options[option_index].name, "icmp-param-pointer") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); if ( parse_u8(optarg, &aux8) == OP_SUCCESS ) o.setICMPParamProblemPointer( aux8 ); else - outFatal(QT_3, "Invalid ICMP Parameter problem pointer. Value must be 0<=N<=255.."); + nping_fatal(QT_3, "Invalid ICMP Parameter problem pointer. Value must be 0<=N<=255.."); /* ICMP Router Advertisement lifetime */ } else if (optcmp(long_options[option_index].name, "icmp-advert-lifetime") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); if ( parse_u16(optarg, &aux16) == OP_SUCCESS ) o.setICMPRouterAdvLifetime( aux16 ); else - outFatal(QT_3, "Invalid ICMP Router advertisement lifetime. Value must be 0<=N<2^16.."); + nping_fatal(QT_3, "Invalid ICMP Router advertisement lifetime. Value must be 0<=N<2^16.."); /* ICMP Router Advertisement entry */ } else if (optcmp(long_options[option_index].name, "icmp-advert-entry") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); /* Format should be "IPADDR,PREF": "192.168.10.99,31337" */ if( meansRandom(optarg) ){ while( (aux_ip4.s_addr=get_random_u32()) == 0); @@ -611,19 +611,19 @@ char errstr[256]; /* ICMP Timestamp originate timestamp */ } else if (optcmp(long_options[option_index].name, "icmp-orig-time") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); this->parseICMPTimestamp(optarg, &aux32); o.setICMPOriginateTimestamp(aux32); /* ICMP Timestamp receive timestamp */ } else if (optcmp(long_options[option_index].name, "icmp-recv-time") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); this->parseICMPTimestamp(optarg, &aux32); o.setICMPReceiveTimestamp(aux32); /* ICMP Timestamp trasnmit timestamp */ } else if (optcmp(long_options[option_index].name, "icmp-trans-time") == 0) { if ( o.issetMode() && o.getMode() != ICMP ) - outFatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ICMP messages.", o.mode2Ascii(o.getMode())); this->parseICMPTimestamp(optarg, &aux32); o.setICMPTransmitTimestamp(aux32); /* TODO: Add more relevant flags for different ICMP options */ @@ -640,12 +640,12 @@ char errstr[256]; optcmp(long_options[option_index].name, "rarp-operation") == 0 || optcmp(long_options[option_index].name, "rarp-op") == 0 ){ if ( o.issetMode() && o.getMode() != ARP ){ - outFatal(QT_3,"You cannot specify mode %s if you want to send ARP messages.", o.mode2Ascii(o.getMode())); + nping_fatal(QT_3,"You cannot specify mode %s if you want to send ARP messages.", o.mode2Ascii(o.getMode())); }else if( !o.issetMode() ){ o.setMode(ARP); } if( atoARPOpCode(optarg, &aux16) != OP_SUCCESS ){ - outFatal(QT_3, "Invalid ARP type/operation code"); + nping_fatal(QT_3, "Invalid ARP type/operation code"); }else{ o.setARPOpCode(aux16); } @@ -653,7 +653,7 @@ char errstr[256]; } else if (optcmp(long_options[option_index].name, "arp-sender-mac") == 0 || optcmp(long_options[option_index].name, "rarp-sender-mac") == 0 ){ if ( parseMAC(optarg, auxmac) != OP_SUCCESS ){ - outFatal(QT_3, "Invalid ARP Sender MAC address."); + nping_fatal(QT_3, "Invalid ARP Sender MAC address."); }else{ o.setARPSenderHwAddr(auxmac); } @@ -661,7 +661,7 @@ char errstr[256]; } else if (optcmp(long_options[option_index].name, "arp-sender-ip") == 0 || optcmp(long_options[option_index].name, "rarp-sender-ip") == 0 ){ if ( atoIP(optarg, &aux_ip4)!=OP_SUCCESS ){ - outFatal(QT_3, "Invalid ARP Sender IP address."); + nping_fatal(QT_3, "Invalid ARP Sender IP address."); }else{ o.setARPSenderProtoAddr(aux_ip4); } @@ -669,7 +669,7 @@ char errstr[256]; } else if (optcmp(long_options[option_index].name, "arp-target-mac") == 0 || optcmp(long_options[option_index].name, "rarp-target-mac") == 0 ){ if ( parseMAC(optarg, auxmac) != OP_SUCCESS ){ - outFatal(QT_3, "Invalid ARP Target MAC address."); + nping_fatal(QT_3, "Invalid ARP Target MAC address."); }else{ o.setARPTargetHwAddr(auxmac); } @@ -677,7 +677,7 @@ char errstr[256]; } else if (optcmp(long_options[option_index].name, "arp-target-ip") == 0 || optcmp(long_options[option_index].name, "rarp-target-ip") == 0 ){ if ( atoIP(optarg, &aux_ip4)!=OP_SUCCESS ){ - outFatal(QT_3, "Invalid ARP Target IP address."); + nping_fatal(QT_3, "Invalid ARP Target IP address."); }else{ o.setARPTargetProtoAddr(aux_ip4); } @@ -687,7 +687,7 @@ char errstr[256]; /* Destination MAC address */ } else if (optcmp(long_options[option_index].name, "dest-mac") == 0 ){ if ( parseMAC(optarg, auxmac) != OP_SUCCESS ){ - outFatal(QT_3, "Invalid Ethernet Destination MAC address."); + nping_fatal(QT_3, "Invalid Ethernet Destination MAC address."); }else{ o.setDestMAC(auxmac); } @@ -697,7 +697,7 @@ char errstr[256]; } else if (optcmp(long_options[option_index].name, "source-mac") == 0 || optcmp(long_options[option_index].name, "spoof-mac") == 0 ){ if ( parseMAC(optarg, auxmac) != OP_SUCCESS ){ - outFatal(QT_3, "Invalid Ethernet Source MAC address."); + nping_fatal(QT_3, "Invalid Ethernet Source MAC address."); }else{ o.setSourceMAC(auxmac); } @@ -712,7 +712,7 @@ char errstr[256]; }else if ( atoEtherType(optarg, &aux16) == OP_SUCCESS ){ o.setEtherType(aux16); }else{ - outFatal(QT_3, "Invalid Ethernet Type."); + nping_fatal(QT_3, "Invalid Ethernet Type."); } if( !o.issetSendPreference() ) o.setSendPreference(PACKET_SEND_ETH_STRONG); @@ -728,14 +728,14 @@ char errstr[256]; if ( parse_u8(optarg, &aux8) == OP_SUCCESS ){ o.setTOS(aux8); }else{ - outFatal(QT_3,"TOS option must be a number between 0 and 255 (inclusive)"); + nping_fatal(QT_3,"TOS option must be a number between 0 and 255 (inclusive)"); } /* IP Identification field */ } else if (optcmp(long_options[option_index].name, "id") == 0 ){ if ( parse_u16(optarg, &aux16) == OP_SUCCESS ){ o.setIdentification(aux16); }else{ - outFatal(QT_3,"Identification must be a number between 0 and 65535 (inclusive)"); + nping_fatal(QT_3,"Identification must be a number between 0 and 65535 (inclusive)"); } /* Don't fragment bit */ } else if (optcmp(long_options[option_index].name, "df") == 0 ){ @@ -752,7 +752,7 @@ char errstr[256]; if ( parse_u8(optarg, &aux8) == OP_SUCCESS ){ o.setTTL(aux8); }else{ - outFatal(QT_3,"%s option must be a number between 0 and 255 (inclusive)", + nping_fatal(QT_3,"%s option must be a number between 0 and 255 (inclusive)", optcmp(long_options[option_index].name, "ttl")==0 ? "TTL" : "Hop Limit" ); } @@ -772,7 +772,7 @@ char errstr[256]; int foo=0, bar=0; u8 buffer[128]; if( parse_ip_options(optarg, buffer, 128, &foo, &bar, errstr, sizeof(errstr)) < 0 ) - outFatal(QT_3, "Incorrect IP options specification."); + nping_fatal(QT_3, "Incorrect IP options specification."); /* If we get here it's safe to store the options */ o.setIPOptions( optarg ); /* Maximum Transmission Unit */ @@ -789,7 +789,7 @@ char errstr[256]; }else if ( (parse_u32(optarg, &aux32)==OP_SUCCESS) && aux32!=0 && aux32%8==0){ o.setMTU(aux32); }else{ - outFatal(QT_3,"MTU must be >0 and multiple of 8"); + nping_fatal(QT_3,"MTU must be >0 and multiple of 8"); } @@ -800,18 +800,18 @@ char errstr[256]; if ( parse_u8(optarg, &aux8) == OP_SUCCESS ) o.setTrafficClass(aux8); else - outFatal(QT_3,"IPv6 Traffic Class must be a number between 0 and 255 (inclusive)"); + nping_fatal(QT_3,"IPv6 Traffic Class must be a number between 0 and 255 (inclusive)"); /* IPv6 Flow label */ } else if (optcmp(long_options[option_index].name, "flow") == 0 ){ if( meansRandom(optarg) ){ o.setFlowLabel( get_random_u32()%1048575 ); /* Mod 2^20 so it doesn't exceed 20bits */ }else if ( parse_u32(optarg, &aux32) == OP_SUCCESS ){ if( aux32>1048575 ) - outFatal(QT_3, "IPv6 Flow Label cannot be greater than 1048575 "); + nping_fatal(QT_3, "IPv6 Flow Label cannot be greater than 1048575 "); else o.setFlowLabel(aux32); }else{ - outFatal(QT_3,"IPv6 Flow Label must be a number between 0 and 1048575"); + nping_fatal(QT_3,"IPv6 Flow Label must be a number between 0 and 1048575"); } @@ -821,7 +821,7 @@ char errstr[256]; u8 *tempbuff=NULL; size_t len=0; if( (tempbuff=parseBufferSpec(optarg, &len))==NULL) - outFatal(QT_3,"Invalid hex string specification\n"); + nping_fatal(QT_3,"Invalid hex string specification\n"); else{ u8 *buff = (u8 *) safe_malloc(len); memcpy(buff, tempbuff, len); @@ -831,34 +831,34 @@ char errstr[256]; /* Read payload from a file */ } else if (optcmp(long_options[option_index].name, "data-file") == 0 ){ if ( o.issetPayloadFilename() ) { - outFatal(QT_3,"Only one payload input filename allowed"); + nping_fatal(QT_3,"Only one payload input filename allowed"); }else { int tmp = file_is_readable(optarg); if ( tmp == 1 ) o.setPayloadFilename(optarg); else if ( tmp==2) - outFatal(QT_3,"Specified payload file is a directory, not a file."); + nping_fatal(QT_3,"Specified payload file is a directory, not a file."); else - outFatal(QT_3,"Specified payload file does not exist or couldn't be opened for reading."); + nping_fatal(QT_3,"Specified payload file does not exist or couldn't be opened for reading."); } /* Random payload */ } else if (optcmp(long_options[option_index].name, "data-length") == 0 ){ if( o.issetPayloadType() != false ) - outFatal(QT_3,"Only one type of payload may be selected."); + nping_fatal(QT_3,"Only one type of payload may be selected."); if( meansRandom(optarg) ){ /* We do not generate more than Ethernet standard MTU */ aux32 = 1 + get_random_u16() % (MAX_RANDOM_PAYLOAD-1); }else if ( parse_u32(optarg, &aux32) != OP_SUCCESS ){ - outFatal(QT_3,"Invalid payload length specification"); + nping_fatal(QT_3,"Invalid payload length specification"); } if ( aux32 > MAX_PAYLOAD_ALLOWED ) - outFatal(QT_3,"data-length must be a value between 0 and %d.", MAX_PAYLOAD_ALLOWED); + nping_fatal(QT_3,"data-length must be a value between 0 and %d.", MAX_PAYLOAD_ALLOWED); if ( aux32 > MAX_RECOMMENDED_PAYLOAD ) - outPrint(QT_3, "WARNING: Payload exceeds maximum recommended payload (%d)", MAX_RECOMMENDED_PAYLOAD); + nping_print(QT_3, "WARNING: Payload exceeds maximum recommended payload (%d)", MAX_RECOMMENDED_PAYLOAD); o.setPayloadType(PL_RAND); /* Allocate a buffer big enough to hold the desired payload */ if( (auxbuff=(u8 *)safe_malloc(aux32)) == NULL ) - outFatal(QT_3,"Not enough memory to store payload."); + nping_fatal(QT_3,"Not enough memory to store payload."); /* Generate random data and store the payload */ get_random_bytes(auxbuff, aux32); o.setPayloadBuffer(auxbuff, aux32); @@ -867,9 +867,9 @@ char errstr[256]; o.setPayloadType(PL_STRING); int plen=strlen(optarg); if ( plen>MAX_PAYLOAD_ALLOWED ) - outFatal(QT_3,"data-string must be between 0 and %d characters.", MAX_PAYLOAD_ALLOWED); + nping_fatal(QT_3,"data-string must be between 0 and %d characters.", MAX_PAYLOAD_ALLOWED); if ( plen > MAX_RECOMMENDED_PAYLOAD ) - outPrint(QT_3, "WARNING: Payload exceeds maximum recommended payload (%d)", MAX_RECOMMENDED_PAYLOAD); + nping_print(QT_3, "WARNING: Payload exceeds maximum recommended payload (%d)", MAX_RECOMMENDED_PAYLOAD); if( meansRandom(optarg) ){ auxbuff=(u8*)strdup(getRandomTextPayload()); plen=strlen((char*)auxbuff); @@ -893,11 +893,11 @@ char errstr[256]; optcmp(long_options[option_index].name, "ep")==0 ){ if ( parse_u16(optarg, &aux16) == OP_SUCCESS ){ if(aux16==0) - outFatal(QT_3, "Invalid echo port. Port can't be zero."); + nping_fatal(QT_3, "Invalid echo port. Port can't be zero."); else o.setEchoPort( aux16 ); }else{ - outFatal(QT_3, "Invalid echo port. Value must be 0= 10 * 1000 && tval_unit(optarg) == NULL) - outFatal(QT_3,"Since April 2010, the default unit for --delay is seconds, so your time of \"%s\" is %g seconds. Use \"%sms\" for %g milliseconds.", optarg, l / 1000.0, optarg, l / 1000.0); + nping_fatal(QT_3,"Since April 2010, the default unit for --delay is seconds, so your time of \"%s\" is %g seconds. Use \"%sms\" for %g milliseconds.", optarg, l / 1000.0, optarg, l / 1000.0); o.setDelay(l); /* Tx rate */ } else if (optcmp(long_options[option_index].name, "rate") == 0 ){ if (parse_u32(optarg, &aux32)==OP_SUCCESS){ if(aux32==0){ - outFatal(QT_3,"Invalid rate supplied. Rate can never be zero."); + nping_fatal(QT_3,"Invalid rate supplied. Rate can never be zero."); }else{ /* Compute delay from rate: delay= 1000ms/rate*/ aux32 = 1000 / aux32; o.setDelay(aux32); } }else{ - outFatal(QT_3,"Invalid rate supplied. Rate must be a valid, positive integer"); + nping_fatal(QT_3,"Invalid rate supplied. Rate must be a valid, positive integer"); } /* Host timeout */ } else if (optcmp(long_options[option_index].name, "host-timeout") == 0 ){ l = tval2msecs(optarg); if (l >= 10000 * 1000 && tval_unit(optarg) == NULL) - outFatal(QT_3,"Since April 2010, the default unit for --host-timeout is seconds, so your time of \"%s\" is %.1f hours. Use \"%sms\" for %g milliseconds.", optarg, l / 1000.0 / 60 / 60, optarg, l / 1000.0); + nping_fatal(QT_3,"Since April 2010, the default unit for --host-timeout is seconds, so your time of \"%s\" is %.1f hours. Use \"%sms\" for %g milliseconds.", optarg, l / 1000.0 / 60 / 60, optarg, l / 1000.0); o.setHostTimeout(l); @@ -953,10 +953,10 @@ char errstr[256]; } else if (optcmp(long_options[option_index].name, "bpf-filter") == 0 || optcmp(long_options[option_index].name, "filter") == 0){ o.setBPFFilterSpec( optarg ); if( o.issetDisablePacketCapture() && o.disablePacketCapture()==true ) - outError(QT_2, "Warning: There is no point on specifying a BPF filter if you disable packet capture. BPF filter will be ignored."); + nping_warning(QT_2, "Warning: There is no point on specifying a BPF filter if you disable packet capture. BPF filter will be ignored."); } else if (optcmp(long_options[option_index].name, "nsock-engine") == 0){ if (nsock_set_default_engine(optarg) < 0) - outFatal(QT_3, "Unknown or non-available engine: %s", optarg); + nping_fatal(QT_3, "Unknown or non-available engine: %s", optarg); /* Output Options */ } else if (optcmp(long_options[option_index].name, "quiet") == 0 ){ o.setVerbosity(-4); @@ -985,23 +985,23 @@ char errstr[256]; case 'f': /* Fragment packets */ if( o.issetMTU() == true ){ - outError(QT_3,"WARNING: -f is irrelevant if an MTU has been previously specified"); + nping_warning(QT_3,"WARNING: -f is irrelevant if an MTU has been previously specified"); } else{ - outPrint(DBG_1, "Setting default MTU=%d", DEFAULT_MTU_FOR_FRAGMENTATION); + nping_print(DBG_1, "Setting default MTU=%d", DEFAULT_MTU_FOR_FRAGMENTATION); o.setMTU( DEFAULT_MTU_FOR_FRAGMENTATION ); } break; case 'g': /* Source port */ if( o.issetSourcePort() ){ - outFatal(QT_3,"Cannot specify source port twice."); + nping_fatal(QT_3,"Cannot specify source port twice."); }else if ( parse_u16(optarg, &aux16) == OP_SUCCESS ){ o.setSourcePort(aux16); if(aux16==0) - outError(QT_1, "WARNING: a source port of zero may not work on all systems."); + nping_warning(QT_1, "WARNING: a source port of zero may not work on all systems."); }else{ - outFatal(QT_3,"Source port must be a number between 0 and 65535 (inclusive)"); + nping_fatal(QT_3,"Source port must be a number between 0 and 65535 (inclusive)"); } break; /* case 'g': */ @@ -1009,7 +1009,7 @@ char errstr[256]; /* Parse port spec */ nping_getpts_simple(optarg, &portlist, &auxint); if( portlist == NULL || auxint <= 0 ){ - outFatal(QT_3,"Invalid target ports specification."); + nping_fatal(QT_3,"Invalid target ports specification."); }else{ o.setTargetPorts(portlist, auxint); } @@ -1029,7 +1029,7 @@ char errstr[256]; } /* Set user supplied address (if we manage to resolve it) */ else if ( atoIP(optarg, &sourceaddr, PF_INET6) != OP_SUCCESS){ - outFatal(QT_3, "Could not resolve source IPv6 address."); + nping_fatal(QT_3, "Could not resolve source IPv6 address."); }else{ ipv6addr = source6->sin6_addr; } @@ -1040,7 +1040,7 @@ char errstr[256]; if( meansRandom(optarg) ) while ( (aux_ip4.s_addr=get_random_u32()) == 0 ); else if ( atoIP(optarg, &aux_ip4) != OP_SUCCESS) - outFatal(QT_3, "Could not resolve source IPv4 address."); + nping_fatal(QT_3, "Could not resolve source IPv4 address."); o.setIPv4SourceAddress(aux_ip4); o.setSpoofSource(); } @@ -1067,13 +1067,13 @@ char errstr[256]; }else if( parse_u32(optarg, &aux32) == OP_SUCCESS ){ o.setPacketCount(aux32); }else{ - outFatal(QT_3,"Packet count must be an integer greater than 0."); + nping_fatal(QT_3,"Packet count must be an integer greater than 0."); } break; /* case 'c': */ case 'e': /* Network interface */ if(strlen(optarg)==0) - outFatal(QT_3,"Invalid network interface supplied. Interface name cannot be NULL."); + nping_fatal(QT_3,"Invalid network interface supplied. Interface name cannot be NULL."); else o.setDevice( strdup(optarg) ); break; /* case 'e': */ @@ -1081,7 +1081,7 @@ char errstr[256]; case 'N': /* Don't capture packets */ o.setDisablePacketCapture(true); if( o.issetBPFFilterSpec() ) - outError(QT_2, "Warning: A custom BPF filter was specified before disabling packet capture. BPF filter will be ignored."); + nping_warning(QT_2, "Warning: A custom BPF filter was specified before disabling packet capture. BPF filter will be ignored."); break; /* case 'N': */ case 'H': /* Hide sent packets */ @@ -1093,7 +1093,7 @@ char errstr[256]; if (isdigit(optarg[0]) || optarg[0]=='-'){ auxint = strtol( optarg, NULL, 10); if ( ((auxint==0) && (optarg[0] != '0')) || auxint<0 || auxint > 9) - outFatal(QT_3,"Debugging level must be an integer between 0 and 9."); + nping_fatal(QT_3,"Debugging level must be an integer between 0 and 9."); else{ o.setDebugging( auxint ); /* When user specifies a debugging level, if no verbosity was specified, @@ -1111,7 +1111,7 @@ char errstr[256]; o.increaseDebugging(); } if (*p != '\0') - outFatal(QT_3,"Invalid argument to -d: \"%s\".", optarg); + nping_fatal(QT_3,"Invalid argument to -d: \"%s\".", optarg); } }else{ o.increaseVerbosity(); @@ -1124,7 +1124,7 @@ char errstr[256]; if (isdigit(optarg[0]) || optarg[0]=='-'){ auxint = strtol( optarg, NULL, 10); if ( ((auxint==0) && (optarg[0] != '0')) || auxint<(-4) || auxint > 4) - outFatal(QT_3,"Verbosity level must be an integer between -4 and +4."); + nping_fatal(QT_3,"Verbosity level must be an integer between -4 and +4."); else o.setVerbosity( auxint ); }else { @@ -1133,7 +1133,7 @@ char errstr[256]; for (p = optarg != NULL ? optarg : ""; *p == 'v'; p++) o.increaseVerbosity(); if (*p != '\0') - outFatal(QT_3,"Invalid argument to -v: \"%s\".", optarg); + nping_fatal(QT_3,"Invalid argument to -v: \"%s\".", optarg); } }else{ o.increaseVerbosity(); @@ -1145,7 +1145,7 @@ char errstr[256]; if (isdigit(optarg[0])){ auxint = strtol( optarg, NULL, 10); if ( ((auxint==0) && (optarg[0] != '0')) || auxint<0 || auxint > 4) - outFatal(QT_3,"You can only reduce verbosity from level 0 to level -4."); + nping_fatal(QT_3,"You can only reduce verbosity from level 0 to level -4."); else o.setVerbosity( -auxint ); }else { @@ -1154,7 +1154,7 @@ char errstr[256]; for (p = optarg != NULL ? optarg : ""; *p == 'q'; p++) o.decreaseVerbosity(); if (*p != '\0') - outFatal(QT_3,"Invalid argument to -q: \"%s\".", optarg); + nping_fatal(QT_3,"Invalid argument to -q: \"%s\".", optarg); } }else{ o.decreaseVerbosity(); @@ -1350,29 +1350,29 @@ int ArgParser::parseAdvertEntry(char *str, struct in_addr *addr, u32 *pref){ /* I guess one can try to lookup something as short as a single char */ if ( len < strlen("a,1") ) - outFatal(QT_3, "Invalid Router Advertising Entry specification: too short"); + nping_fatal(QT_3, "Invalid Router Advertising Entry specification: too short"); /* Im going to limit this to 255 chars. */ if( len > 255 ) - outFatal(QT_3, "Invalid Router Advertising Entry specification: too long"); + nping_fatal(QT_3, "Invalid Router Advertising Entry specification: too long"); /* Let's find the comma */ aux=strstr(str, ","); if(aux==NULL ) - outFatal(QT_3, "Invalid Router Advertising Entry specification: Bad syntax, missing comma delimiter"); + nping_fatal(QT_3, "Invalid Router Advertising Entry specification: Bad syntax, missing comma delimiter"); if(aux==str) - outFatal(QT_3, "Invalid Router Advertising Entry specification: Bad syntax, comma cannot be placed at start"); + nping_fatal(QT_3, "Invalid Router Advertising Entry specification: Bad syntax, comma cannot be placed at start"); if(aux>=str+len-1 ) - outFatal(QT_3, "Invalid Router Advertising Entry specification: Bad syntax, comma cannot be placed at the end"); + nping_fatal(QT_3, "Invalid Router Advertising Entry specification: Bad syntax, comma cannot be placed at the end"); /* Looks like at least the syntax is corect */ memcpy(first, str, aux-str); memcpy(last, aux+1, len-(aux-str) ); if( atoIP(first, &auxIP) == OP_FAILURE ) - outFatal(QT_3, "Invalid Router Advertising Entry specification: Unable to resolve %s", first); + nping_fatal(QT_3, "Invalid Router Advertising Entry specification: Unable to resolve %s", first); if( isNumber_u32( last ) == false ) - outFatal(QT_3, "Invalid Router Advertising Entry specification: %s is not a valid preference number", last); + nping_fatal(QT_3, "Invalid Router Advertising Entry specification: %s is not a valid preference number", last); auxPref=strtoul( last, NULL, 10); *pref=auxPref; @@ -1853,28 +1853,28 @@ int ArgParser::parseICMPTimestamp(char *optarg, u32 *dst){ long diff=0; if(optarg==NULL || dst==NULL) - outFatal(QT_3, "parseICMPTimestamp(): NULL pointer supplied."); + nping_fatal(QT_3, "parseICMPTimestamp(): NULL pointer supplied."); if( meansRandom(optarg) ){ while( (*dst=get_random_u32()) == 0); } else if( !strncmp("now-", optarg, 4) ){ if ( (diff= tval2msecs(optarg+4)) < 0 ) - outFatal(QT_3,"You must specify a valid time value after now- (e.g. 1000, 2s, 25m, etc.)"); + nping_fatal(QT_3,"You must specify a valid time value after now- (e.g. 1000, 2s, 25m, etc.)"); struct timeval now; gettimeofday(&now, NULL); if( ((((u32)now.tv_sec)%86400)*1000) < (u32)diff ) - outFatal(QT_3,"Value is %s is too high for current time.", optarg+4 ); + nping_fatal(QT_3,"Value is %s is too high for current time.", optarg+4 ); else *dst= ((((u32)now.tv_sec)%86400)*1000) - diff; } else if( !strncmp("now+", optarg, 4) ) { if ( (diff= tval2msecs(optarg+4)) < 0 ) - outFatal(QT_3,"You must specify a valid time value after now+ (e.g. 1000, 2s, 25m, etc.)"); + nping_fatal(QT_3,"You must specify a valid time value after now+ (e.g. 1000, 2s, 25m, etc.)"); struct timeval now; gettimeofday(&now, NULL); if( ((((u32)now.tv_sec)%86400)*1000) + diff > 0xFFFFFFFF ) - outFatal(QT_3,"Value is %s is too high for current time.", optarg+4 ); + nping_fatal(QT_3,"Value is %s is too high for current time.", optarg+4 ); else *dst= ((((u32)now.tv_sec)%86400)*1000) + diff; } @@ -1885,7 +1885,7 @@ long diff=0; } else { if ( (diff= tval2msecs(optarg)) == -1) - outFatal(QT_3,"Invalid time supplied"); + nping_fatal(QT_3,"Invalid time supplied"); else *dst=diff; } diff --git a/nping/Crypto.cc b/nping/Crypto.cc index ebeba149e..aa42c5eaa 100755 --- a/nping/Crypto.cc +++ b/nping/Crypto.cc @@ -138,7 +138,7 @@ int Crypto::hmac_sha256(u8 *inbuff, size_t inlen, u8 *dst_buff, u8 *key, size_t int Crypto::aes128_cbc_encrypt(u8 *inbuff, size_t inlen, u8 *dst_buff, u8 *key, size_t key_len, u8 *iv){ - outPrint(DBG_4, "%s(%p, %lu, %p, %p, %lu, %p)", __func__, inbuff, (unsigned long)inlen, dst_buff, key, (unsigned long)key_len, iv); + nping_print(DBG_4, "%s(%p, %lu, %p, %p, %lu, %p)", __func__, inbuff, (unsigned long)inlen, dst_buff, key, (unsigned long)key_len, iv); if(inbuff==NULL || dst_buff==NULL || key==NULL || iv==NULL) return OP_FAILURE; if( ((inlen%AES_BLOCK_SIZE)!=0) || key_lenprobe.init_nsock() != OP_SUCCESS ){ - outError(QT_2, "Couln't initialize Nsock."); + nping_warning(QT_2, "Couln't initialize Nsock."); return OP_FAILURE; }else{ /* Extract the nsock pool handler and store it here */ @@ -148,25 +148,25 @@ int EchoClient::start(NpingTarget *target, u16 port){ /* Schedule a TCP connection attempt */ if( this->nep_connect(target, port) != OP_SUCCESS ){ - outError(QT_2, "Connection failed."); + nping_warning(QT_2, "Connection failed."); return OP_FAILURE; } /* Perform NEP authentication handshake */ if( this->nep_handshake() != OP_SUCCESS ){ - outError(QT_2, "Handshake failed."); + nping_warning(QT_2, "Handshake failed."); return OP_FAILURE; } /* Send packet specification */ if( this->nep_send_packet_spec() != OP_SUCCESS ){ - outError(QT_2, "Couldn't send packet specification."); + nping_warning(QT_2, "Couldn't send packet specification."); return OP_FAILURE; } /* Wait for confirmation */ if( this->nep_recv_ready() != OP_SUCCESS ){ - outError(QT_2, "Didn't receive server's OK."); + nping_warning(QT_2, "Didn't receive server's OK."); return OP_FAILURE; } @@ -185,7 +185,7 @@ int EchoClient::start(NpingTarget *target, u16 port){ * connect to the remote host (this can be because the server rejected the * connection or because the connect() timed out). */ int EchoClient::nep_connect(NpingTarget *target, u16 port){ - outPrint(DBG_4, "%s(%p, %u)", __func__, target, port); + nping_print(DBG_4, "%s(%p, %u)", __func__, target, port); struct sockaddr_storage ss; struct sockaddr_storage src; size_t ss_len; @@ -194,7 +194,7 @@ int EchoClient::nep_connect(NpingTarget *target, u16 port){ enum nsock_loopstatus loopstatus; if(target==NULL) - outFatal(QT_3, "nep_connect(): NULL parameter supplied."); + nping_fatal(QT_3, "nep_connect(): NULL parameter supplied."); else target->getTargetSockAddr(&ss, &ss_len); @@ -244,7 +244,7 @@ int EchoClient::nep_connect(NpingTarget *target, u16 port){ /** Attempts to perform the NEP authentication handshake with the server. * Returns OP_SUCCESS if the authentication went well and OP_FAILURE otherwise */ int EchoClient::nep_handshake(){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); enum nsock_loopstatus loopstatus; EchoHeader h; @@ -262,10 +262,10 @@ int EchoClient::nep_handshake(){ this->ctx.generateMacKeyC2S(); this->ctx.generateMacKeyS2C(); - outPrint(DBG_4,"Session Key MAC_C2S:"); print_hexdump(DBG_4,ctx.getMacKeyC2S(), MAC_KEY_LEN); - outPrint(DBG_4,"Session Key MAC_S2C:"); print_hexdump(DBG_4,ctx.getMacKeyS2C(), MAC_KEY_LEN); - outPrint(DBG_4,"Session Key CIPHER_C2S:"); print_hexdump(DBG_4,ctx.getCipherKeyC2S(), MAC_KEY_LEN); - outPrint(DBG_4,"Session Key CIPHER_S2C:"); print_hexdump(DBG_4,ctx.getCipherKeyS2C(), MAC_KEY_LEN); + nping_print(DBG_4,"Session Key MAC_C2S:"); print_hexdump(DBG_4,ctx.getMacKeyC2S(), MAC_KEY_LEN); + nping_print(DBG_4,"Session Key MAC_S2C:"); print_hexdump(DBG_4,ctx.getMacKeyS2C(), MAC_KEY_LEN); + nping_print(DBG_4,"Session Key CIPHER_C2S:"); print_hexdump(DBG_4,ctx.getCipherKeyC2S(), MAC_KEY_LEN); + nping_print(DBG_4,"Session Key CIPHER_S2C:"); print_hexdump(DBG_4,ctx.getCipherKeyS2C(), MAC_KEY_LEN); /* Send NEP_HANDSHAKE_CLIENT message */ @@ -282,7 +282,7 @@ int EchoClient::nep_handshake(){ if(loopstatus!=NSOCK_LOOP_QUIT) return OP_FAILURE; - outPrint(DBG_1, "===NEP Handshake completed successfully==="); + nping_print(DBG_1, "===NEP Handshake completed successfully==="); return OP_SUCCESS; } /* End of nep_handshake() */ @@ -290,7 +290,7 @@ int EchoClient::nep_handshake(){ /** Sends the appropriate NEP_PACKET_SPEC message to the server. Returns * OP_SUCCESS on success and OP_FAILURE in case of error. */ int EchoClient::nep_send_packet_spec(){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); enum nsock_loopstatus loopstatus; EchoHeader h; @@ -310,7 +310,7 @@ int EchoClient::nep_send_packet_spec(){ /** Receives and parses a NEP_READY message from the server. Returns OP_SUCCESS * on success and OP_FAILURE in case of error. */ int EchoClient::nep_recv_ready(){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); enum nsock_loopstatus loopstatus; /* Receive NEP_READY message */ nsock_readbytes(this->nsp, this->nsi, recv_ready_handler, ECHO_READ_TIMEOUT, NULL, NEP_READY_LEN); @@ -325,7 +325,7 @@ int EchoClient::nep_recv_ready(){ /** Reads and parses a NEP_ECHO message from the server. Returns OP_SUCCESS * on success and OP_FAILURE in case of error. */ int EchoClient::nep_recv_echo(u8 *packet, size_t packetlen){ - outPrint(DBG_4, "%s(%p, %lu)", __func__, packet, (unsigned long)packetlen); + nping_print(DBG_4, "%s(%p, %lu)", __func__, packet, (unsigned long)packetlen); EchoHeader pkt_in; char *delayedstr=NULL; nsock_event_id ev_id; @@ -342,11 +342,11 @@ int EchoClient::nep_recv_echo(u8 *packet, size_t packetlen){ /* Once we have authenticated the received message, extract the echoed packet */ if(pkt_in.storeRecvData(packet, packetlen)==OP_FAILURE){ - outPrint(VB_0, "Unexpected error dealing with the NEP_ECHO message,"); + nping_print(VB_0, "Unexpected error dealing with the NEP_ECHO message,"); return OP_FAILURE; } if((pkt=pkt_in.getEchoedPacket(&pktlen))==NULL){ - outPrint(VB_0, "Error displaying received NEP_ECHO message)"); + nping_print(VB_0, "Error displaying received NEP_ECHO message)"); return OP_FAILURE; } o.stats.addEchoedPacket(pktlen); @@ -363,7 +363,7 @@ int EchoClient::nep_recv_echo(u8 *packet, size_t packetlen){ /* @todo: compute the link layer offset from the DLT type and discard * link layer headers */ getPacketStrInfo("IP", pkt, pktlen, pktinfobuffer, 512); - outPrint(VB_0,"CAPT (%.4fs) %s", final_time, pktinfobuffer ); + nping_print(VB_0,"CAPT (%.4fs) %s", final_time, pktinfobuffer ); if( o.getVerbosity() >= VB_3) luis_hdump((char*)pkt, pktlen); @@ -381,39 +381,39 @@ int EchoClient::nep_recv_echo(u8 *packet, size_t packetlen){ * it returns OP_SUCCESS. OP_FAILURE is returned in case the received packet * is not valid. */ int EchoClient::parse_hs_server(u8 *pkt, size_t pktlen){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); EchoHeader h; if(pkt==NULL){ - outPrint(DBG_1,"%s(): NULL parameter supplied.", __func__ ); + nping_print(DBG_1,"%s(): NULL parameter supplied.", __func__ ); return OP_FAILURE; } if(pktlen!=NEP_HANDSHAKE_SERVER_LEN){ - outPrint(DBG_1,"%s(): Unexpected length supplied.", __func__ ); + nping_print(DBG_1,"%s(): Unexpected length supplied.", __func__ ); return OP_FAILURE; } h.storeRecvData(pkt, pktlen); /* Validate version number */ if( h.getVersion() != ECHO_CURRENT_PROTO_VER ){ - outPrint(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); + nping_print(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); return OP_FAILURE; } /* Ensure the expected message type was received */ if(h.getMessageType()!=TYPE_NEP_HANDSHAKE_SERVER){ - outPrint(DBG_1, "Expected NEP_HANDSHAKE_SERVER but received %02X", h.getMessageType() ); + nping_print(DBG_1, "Expected NEP_HANDSHAKE_SERVER but received %02X", h.getMessageType() ); return OP_FAILURE; } /* Ensure the received timestamp falls into the allowed time window */ //if( h.verifyTimestamp()!=OP_SUCCESS ){ - // outPrint(DBG_1, "NEP_HANDSHAKE_SERVER timestamp is too old", h.getMessageType() ); + // nping_print(DBG_1, "NEP_HANDSHAKE_SERVER timestamp is too old", h.getMessageType() ); // return OP_FAILURE; //} /* Ensure message length is correct */ if( h.getTotalLength()!=(NEP_HANDSHAKE_SERVER_LEN/4)){ - outPrint(DBG_1, "Received NEP_HANDSHAKE_SERVER specifies an incorrect length (%u)", h.getTotalLength()*4 ); + nping_print(DBG_1, "Received NEP_HANDSHAKE_SERVER specifies an incorrect length (%u)", h.getTotalLength()*4 ); return OP_FAILURE; } @@ -421,7 +421,7 @@ int EchoClient::parse_hs_server(u8 *pkt, size_t pktlen){ this->ctx.setServerNonce(h.getServerNonce()); this->ctx.generateMacKeyS2CInitial(); if( h.verifyMessageAuthenticationCode(this->ctx.getMacKeyS2C(), MAC_KEY_LEN )!=OP_SUCCESS ){ - outPrint(DBG_1, "NEP_HANDSHAKE_SERVER authentication failed" ); + nping_print(DBG_1, "NEP_HANDSHAKE_SERVER authentication failed" ); return OP_FAILURE; } this->ctx.setLastServerSequence( h.getSequenceNumber() ); @@ -433,34 +433,34 @@ int EchoClient::parse_hs_server(u8 *pkt, size_t pktlen){ * it returns OP_SUCCESS. OP_FAILURE is returned in case the received packet * is not valid. */ int EchoClient::parse_hs_final(u8 *pkt, size_t pktlen){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); EchoHeader h; u8 *next_iv=NULL; if(pkt==NULL){ - outPrint(DBG_1,"%s(): NULL parameter supplied.", __func__ ); + nping_print(DBG_1,"%s(): NULL parameter supplied.", __func__ ); return OP_FAILURE; } if(pktlen!=NEP_HANDSHAKE_FINAL_LEN){ - outPrint(DBG_1,"%s(): Unexpected length supplied.", __func__ ); + nping_print(DBG_1,"%s(): Unexpected length supplied.", __func__ ); return OP_FAILURE; } h.storeRecvData(pkt, pktlen); /* Validate version number */ if( h.getVersion() != ECHO_CURRENT_PROTO_VER ){ - outPrint(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); + nping_print(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); return OP_FAILURE; } /* Ensure the expected message type was received */ if(h.getMessageType()!=TYPE_NEP_HANDSHAKE_FINAL){ - outPrint(DBG_1, "Expected NEP_HANDSHAKE_FINAL but received %02X", h.getMessageType() ); + nping_print(DBG_1, "Expected NEP_HANDSHAKE_FINAL but received %02X", h.getMessageType() ); return OP_FAILURE; } /* Ensure the received sequence number is the previous+1 */ if( h.getSequenceNumber()!=(this->ctx.getLastServerSequence()+1)){ - outPrint(DBG_1, "Expected sequence number %d but received %d", this->ctx.getLastServerSequence()+1, h.getSequenceNumber() ); + nping_print(DBG_1, "Expected sequence number %d but received %d", this->ctx.getLastServerSequence()+1, h.getSequenceNumber() ); return OP_FAILURE; }else{ /* Increment next expected sequence number*/ @@ -469,32 +469,32 @@ int EchoClient::parse_hs_final(u8 *pkt, size_t pktlen){ /* Ensure the received timestamp falls into the allowed time window */ //if( h.verifyTimestamp()!=OP_SUCCESS ){ - // outPrint(DBG_1, "NEP_HANDSHAKE_FINAL timestamp is too old", h.getMessageType() ); + // nping_print(DBG_1, "NEP_HANDSHAKE_FINAL timestamp is too old", h.getMessageType() ); // return OP_FAILURE; //} /* Ensure message length is correct */ if( h.getTotalLength()!=(NEP_HANDSHAKE_FINAL_LEN/4)){ - outPrint(DBG_1, "Received NEP_HANDSHAKE_FINAL specifies an incorrect length (%u)", h.getTotalLength()*4 ); + nping_print(DBG_1, "Received NEP_HANDSHAKE_FINAL specifies an incorrect length (%u)", h.getTotalLength()*4 ); return OP_FAILURE; } /* Ensure the server echoed the nonce we sent in our NEP_HANDSHAKE_CLIENT */ if( memcmp(h.getClientNonce(), this->ctx.getClientNonce(), NONCE_LEN)!=0 ){ - outPrint(DBG_1, "Echoed nonce in NEP_HANDSHAKE_FINAL message does not match client generate nonce"); + nping_print(DBG_1, "Echoed nonce in NEP_HANDSHAKE_FINAL message does not match client generate nonce"); return OP_FAILURE; } /* Decrypt the encrypted part of the message before validating the MAC */ if((next_iv=h.decrypt(this->ctx.getCipherKeyS2C(), CIPHER_KEY_LEN, this->ctx.getServerNonce(), TYPE_NEP_HANDSHAKE_FINAL))==NULL){ - outPrint(DBG_1, "Failed to decrypt NEP_HANDSHAKE_FINAL data." ); + nping_print(DBG_1, "Failed to decrypt NEP_HANDSHAKE_FINAL data." ); return OP_FAILURE; } this->ctx.setNextDecryptionIV(next_iv); /* Check the authenticity of the received message */ if( h.verifyMessageAuthenticationCode(this->ctx.getMacKeyS2C(), MAC_KEY_LEN )!=OP_SUCCESS ){ - outPrint(DBG_1, "NEP_HANDSHAKE_FINAL authentication failed" ); + nping_print(DBG_1, "NEP_HANDSHAKE_FINAL authentication failed" ); return OP_FAILURE; } @@ -506,41 +506,41 @@ int EchoClient::parse_hs_final(u8 *pkt, size_t pktlen){ * it returns OP_SUCCESS. OP_FAILURE is returned in case the received packet * is not valid. */ int EchoClient::parse_ready(u8 *pkt, size_t pktlen){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); EchoHeader h; u8 *next_iv=NULL; if(pkt==NULL){ - outPrint(DBG_1,"%s(): NULL parameter supplied.", __func__ ); + nping_print(DBG_1,"%s(): NULL parameter supplied.", __func__ ); return OP_FAILURE; } if(pktlen!=NEP_READY_LEN){ - outPrint(DBG_1,"%s(): Unexpected length supplied.", __func__ ); + nping_print(DBG_1,"%s(): Unexpected length supplied.", __func__ ); return OP_FAILURE; } h.storeRecvData(pkt, pktlen); /* Decrypt message */ if((next_iv=h.decrypt(this->ctx.getCipherKeyS2C(), CIPHER_KEY_LEN, this->ctx.getNextDecryptionIV(), TYPE_NEP_READY))==NULL){ - outPrint(DBG_1, "Failed to decrypt NEP_READY data." ); + nping_print(DBG_1, "Failed to decrypt NEP_READY data." ); return OP_FAILURE; } this->ctx.setNextDecryptionIV(next_iv); /* Validate version number */ if( h.getVersion() != ECHO_CURRENT_PROTO_VER ){ - outPrint(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); + nping_print(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); return OP_FAILURE; } /* Ensure the expected message type was received */ if(h.getMessageType()!=TYPE_NEP_READY){ - outPrint(DBG_1, "Expected NEP_READY but received %02X", h.getMessageType() ); + nping_print(DBG_1, "Expected NEP_READY but received %02X", h.getMessageType() ); return OP_FAILURE; } /* Ensure the received sequence number is the previous+1 */ if( h.getSequenceNumber()!=(this->ctx.getLastServerSequence()+1)){ - outPrint(DBG_1, "Expected sequence number %d but received %d", this->ctx.getLastServerSequence()+1, h.getSequenceNumber() ); + nping_print(DBG_1, "Expected sequence number %d but received %d", this->ctx.getLastServerSequence()+1, h.getSequenceNumber() ); return OP_FAILURE; }else{ /* Increment next expected sequence number*/ @@ -549,19 +549,19 @@ int EchoClient::parse_ready(u8 *pkt, size_t pktlen){ /* Ensure the received timestamp falls into the allowed time window */ //if( h.verifyTimestamp()!=OP_SUCCESS ){ - // outPrint(DBG_1, "NEP_READY timestamp is too old", h.getMessageType() ); + // nping_print(DBG_1, "NEP_READY timestamp is too old", h.getMessageType() ); // return OP_FAILURE; //} /* Ensure message length is correct */ if( h.getTotalLength()!=(NEP_READY_LEN/4)){ - outPrint(DBG_1, "Received NEP_READY specifies an incorrect length (%u)", h.getTotalLength()*4 ); + nping_print(DBG_1, "Received NEP_READY specifies an incorrect length (%u)", h.getTotalLength()*4 ); return OP_FAILURE; } /* Check the authenticity of the received message */ if( h.verifyMessageAuthenticationCode(this->ctx.getMacKeyS2C(), MAC_KEY_LEN )!=OP_SUCCESS ){ - outPrint(DBG_1, "NEP_READY authentication failed" ); + nping_print(DBG_1, "NEP_READY authentication failed" ); return OP_FAILURE; } @@ -573,41 +573,41 @@ int EchoClient::parse_ready(u8 *pkt, size_t pktlen){ * it returns OP_SUCCESS. OP_FAILURE is returned in case the received packet * is not valid. */ int EchoClient::parse_echo(u8 *pkt, size_t pktlen){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); EchoHeader h; u8 *next_iv=NULL; if(pkt==NULL){ - outPrint(DBG_1,"%s(): NULL parameter supplied.", __func__ ); + nping_print(DBG_1,"%s(): NULL parameter supplied.", __func__ ); return OP_FAILURE; } if(pktlenctx.getCipherKeyS2C(), CIPHER_KEY_LEN, this->ctx.getNextDecryptionIV(), TYPE_NEP_ECHO))==NULL){ - outPrint(DBG_1, "Failed to decrypt NEP_ECHO data." ); + nping_print(DBG_1, "Failed to decrypt NEP_ECHO data." ); return OP_FAILURE; } this->ctx.setNextDecryptionIV(next_iv); /* Validate version number */ if( h.getVersion() != ECHO_CURRENT_PROTO_VER ){ - outPrint(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); + nping_print(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); return OP_FAILURE; } /* Ensure the expected message type was received */ if(h.getMessageType()!=TYPE_NEP_ECHO){ - outPrint(DBG_1, "Expected NEP_ECHO but received %02X", h.getMessageType() ); + nping_print(DBG_1, "Expected NEP_ECHO but received %02X", h.getMessageType() ); return OP_FAILURE; } /* Ensure the received sequence number is the previous+1 */ if( h.getSequenceNumber()!=(this->ctx.getLastServerSequence()+1)){ - outPrint(DBG_1, "Expected sequence number %d but received %d", this->ctx.getLastServerSequence()+1, h.getSequenceNumber() ); + nping_print(DBG_1, "Expected sequence number %d but received %d", this->ctx.getLastServerSequence()+1, h.getSequenceNumber() ); return OP_FAILURE; }else{ /* Increment next expected sequence number*/ @@ -616,13 +616,13 @@ int EchoClient::parse_echo(u8 *pkt, size_t pktlen){ /* Ensure the received timestamp falls into the allowed time window */ //if( h.verifyTimestamp()!=OP_SUCCESS ){ - // outPrint(DBG_1, "NEP_ECHO timestamp is too old", h.getMessageType() ); + // nping_print(DBG_1, "NEP_ECHO timestamp is too old", h.getMessageType() ); // return OP_FAILURE; //} // /* Ensure message length is correct */ // if( h.getTotalLength()!=(pktlen/4)){ -// outPrint(DBG_1, "Received NEP_ECHO specifies an incorrect length (%u)", h.getTotalLength()*4 ); +// nping_print(DBG_1, "Received NEP_ECHO specifies an incorrect length (%u)", h.getTotalLength()*4 ); // return OP_FAILURE; // } @@ -632,10 +632,10 @@ int EchoClient::parse_echo(u8 *pkt, size_t pktlen){ /* Check the authenticity of the received message */ if( h.verifyMessageAuthenticationCode(this->ctx.getMacKeyS2C(), MAC_KEY_LEN )!=OP_SUCCESS ){ - outPrint(DBG_1, "NEP_ECHO authentication failed" ); + nping_print(DBG_1, "NEP_ECHO authentication failed" ); return OP_FAILURE; }else{ - outPrint(DBG_1, "Received NEP_ECHO was authenticated successfully"); + nping_print(DBG_1, "Received NEP_ECHO was authenticated successfully"); } /* Overwrite the received buffer with the decrypted data */ @@ -649,7 +649,7 @@ int EchoClient::parse_echo(u8 *pkt, size_t pktlen){ * it returns OP_SUCCESS. OP_FAILURE is returned in case the received packet * is not valid. */ int EchoClient::parse_error(u8 *pkt, size_t pktlen){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); return OP_SUCCESS; } /* End of parse_hs_final() */ @@ -657,7 +657,7 @@ int EchoClient::parse_error(u8 *pkt, size_t pktlen){ /** Generates a NEP_HANDSHAKE_CLIENT message. On success it returns OP_SUCCESS. * OP_FAILURE is returned in case of error. */ int EchoClient::generate_hs_client(EchoHeader *h){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); u8 *next_iv=NULL; if(h==NULL) return OP_FAILURE; @@ -686,7 +686,7 @@ int EchoClient::generate_hs_client(EchoHeader *h){ /** Generates a NEP_PACKET_SPEC message. On success it returns OP_SUCCESS. * OP_FAILURE is returned in case of error. */ int EchoClient::generate_packet_spec(EchoHeader *h){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); int ports=-1; u8 nxthdr=0; u8 aux8=0; @@ -781,7 +781,7 @@ int EchoClient::generate_packet_spec(EchoHeader *h){ case TCP_CONNECT: case ARP: default: - outFatal(QT_3, "%s packets are not supported in Echo Mode", o.mode2Ascii(o.getMode()) ); + nping_fatal(QT_3, "%s packets are not supported in Echo Mode", o.mode2Ascii(o.getMode()) ); break; } /* Next protocol number */ @@ -811,7 +811,7 @@ int EchoClient::generate_packet_spec(EchoHeader *h){ * the nep_recv_echo() method, which is the one in charge of processing * NEP_ECHO packets */ int EchoClient::nep_echoed_packet_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); EchoHeader pkt_in; u8 *recvbuff=NULL; int recvbytes=0; @@ -820,19 +820,19 @@ int EchoClient::nep_echoed_packet_handler(nsock_pool nsp, nsock_event nse, void enum nse_status status=nse_status(nse); if (status!=NSE_STATUS_SUCCESS){ if(status!=NSE_STATUS_KILL){ - outError(QT_2, "==========================================================================="); - outError(QT_2, "ERROR: Server closed the connection. No more CAPT packets will be received."); - outError(QT_2, "==========================================================================="); + nping_warning(QT_2, "==========================================================================="); + nping_warning(QT_2, "ERROR: Server closed the connection. No more CAPT packets will be received."); + nping_warning(QT_2, "==========================================================================="); } return OP_FAILURE; } /* Read the remaining data */ if( (recvbuff=(u8 *)nse_readbuf(nse, &recvbytes))==NULL ){ - outPrint(DBG_4,"nep_echoed_packet_handler(): nse_readbuf failed!\n"); + nping_print(DBG_4,"nep_echoed_packet_handler(): nse_readbuf failed!\n"); return OP_FAILURE; }else{ - outPrint(DBG_4, "%s() Received %d bytes", __func__, recvbytes); + nping_print(DBG_4, "%s() Received %d bytes", __func__, recvbytes); } /* When we get here we'll have part of the packet stored in this->lasthdr and @@ -845,11 +845,11 @@ int EchoClient::nep_echoed_packet_handler(nsock_pool nsp, nsock_event nse, void Crypto::aes128_cbc_decrypt(pkt_start, 16, aux, this->ctx.getCipherKeyS2C(), CIPHER_KEY_LEN, this->ctx.getNextDecryptionIV()); pkt_in.storeRecvData(aux, 16); int plen=pkt_in.getTotalLength()*4; - outPrint(DBG_4, "%s() Packet claims to have a length of %d bytes", __func__, plen); + nping_print(DBG_4, "%s() Packet claims to have a length of %d bytes", __func__, plen); /* If the packet is bigger than the maximum NEP packet, discard it. */ if(plen>MAX_NEP_PACKET_LENGTH){ - outError(DBG_1,"Warning. Received NEP packet (%dB) is bigger than %d bytes.", plen, MAX_NEP_PACKET_LENGTH); + nping_warning(DBG_1,"Warning. Received NEP packet (%dB) is bigger than %d bytes.", plen, MAX_NEP_PACKET_LENGTH); return OP_FAILURE; } @@ -857,7 +857,7 @@ int EchoClient::nep_echoed_packet_handler(nsock_pool nsp, nsock_event nse, void if (plen==((int)this->readbytes+recvbytes)){ memcpy(this->lasthdr+this->readbytes, recvbuff, recvbytes); this->readbytes+=recvbytes; - outPrint(DBG_4,"%s(): Received exact length (%d).", __func__, recvbytes); + nping_print(DBG_4,"%s(): Received exact length (%d).", __func__, recvbytes); this->nep_recv_echo(this->lasthdr, this->readbytes); nsock_readbytes(this->nsp, this->nsi, recv_std_header_handler, NSOCK_INFINITE, NULL, STD_NEP_HEADER_LEN); return OP_SUCCESS; @@ -868,12 +868,12 @@ int EchoClient::nep_echoed_packet_handler(nsock_pool nsp, nsock_event nse, void }else if(recvbyteslasthdr, recvbuff, recvbytes); this->readbytes=recvbytes; - outPrint(DBG_4,"%s(): Missing %d bytes. Scheduled read operation for remaining bytes", __func__, plen-recvbytes); + nping_print(DBG_4,"%s(): Missing %d bytes. Scheduled read operation for remaining bytes", __func__, plen-recvbytes); nsock_readbytes(nsp, nsi, echoed_packet_handler, NSOCK_INFINITE, NULL, plen-recvbytes); return OP_SUCCESS; }else{ /* Received more than one packet */ - outPrint(DBG_4,"%s(): Received more than one packet", __func__); + nping_print(DBG_4,"%s(): Received more than one packet", __func__); memcpy(this->lasthdr+this->readbytes, recvbuff, plen-this->readbytes); this->nep_recv_echo(this->lasthdr, plen); recvbuff+=plen-this->readbytes; @@ -895,7 +895,7 @@ int EchoClient::nep_echoed_packet_handler(nsock_pool nsp, nsock_event nse, void * control to nep_recv_echo(), which is the one in charge of processing * NEP_ECHO packets */ int EchoClient::nep_recv_std_header_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); nsock_iod nsi = nse_iod(nse); EchoHeader pkt_in; u8 *recvbuff=NULL; @@ -904,18 +904,18 @@ int EchoClient::nep_recv_std_header_handler(nsock_pool nsp, nsock_event nse, voi enum nse_status status=nse_status(nse); if (status!=NSE_STATUS_SUCCESS){ if(status!=NSE_STATUS_KILL){ - outError(QT_2, "==========================================================================="); - outError(QT_2, "ERROR: Server closed the connection. No more CAPT packets will be received."); - outError(QT_2, "==========================================================================="); + nping_warning(QT_2, "==========================================================================="); + nping_warning(QT_2, "ERROR: Server closed the connection. No more CAPT packets will be received."); + nping_warning(QT_2, "==========================================================================="); } return OP_FAILURE; } /* Read data */ if( (recvbuff=(u8 *)nse_readbuf(nse, &recvbytes))==NULL ){ - outPrint(DBG_4,"%s(): nse_readbuf failed.", __func__); + nping_print(DBG_4,"%s(): nse_readbuf failed.", __func__); return OP_FAILURE; }else{ - outPrint(DBG_4, "%s() Received %d bytes", __func__, recvbytes); + nping_print(DBG_4, "%s() Received %d bytes", __func__, recvbytes); } /* Here there are different possibilites. We may have received exactly one @@ -932,13 +932,13 @@ int EchoClient::nep_recv_std_header_handler(nsock_pool nsp, nsock_event nse, voi /* If the packet is bigger than the maximum NEP packet, discard it. */ if(plen>MAX_NEP_PACKET_LENGTH){ - outError(DBG_1,"Warning. Received NEP packet (%dB) is bigger than %d bytes.", plen, MAX_NEP_PACKET_LENGTH); + nping_warning(DBG_1,"Warning. Received NEP packet (%dB) is bigger than %d bytes.", plen, MAX_NEP_PACKET_LENGTH); return OP_FAILURE; } /* If we have read the whole packet, give it to nep_recv_echo for processing */ if (plen==recvbytes){ - outPrint(DBG_4,"%s(): Received exact length (%d).", __func__, recvbytes); + nping_print(DBG_4,"%s(): Received exact length (%d).", __func__, recvbytes); this->nep_recv_echo(recvbuff, recvbytes); nsock_readbytes(this->nsp, this->nsi, recv_std_header_handler, NSOCK_INFINITE, NULL, STD_NEP_HEADER_LEN); return OP_SUCCESS; @@ -946,12 +946,12 @@ int EchoClient::nep_recv_std_header_handler(nsock_pool nsp, nsock_event nse, voi }else if(recvbyteslasthdr, recvbuff, recvbytes); this->readbytes=recvbytes; - outPrint(DBG_4,"%s(): Missing %d bytes. Scheduled read operation for remaining bytes", __func__, plen-recvbytes); + nping_print(DBG_4,"%s(): Missing %d bytes. Scheduled read operation for remaining bytes", __func__, plen-recvbytes); nsock_readbytes(nsp, nsi, echoed_packet_handler, NSOCK_INFINITE, NULL, plen-recvbytes); return OP_SUCCESS; }else{ /* Received more than one packet */ - outPrint(DBG_4,"%s(): Received more than one packet", __func__); + nping_print(DBG_4,"%s(): Received more than one packet", __func__); this->nep_recv_echo(recvbuff, plen); recvbuff+=plen; recvbytes-=plen; @@ -972,7 +972,7 @@ int EchoClient::nep_recv_std_header_handler(nsock_pool nsp, nsock_event nse, voi * the internal context accordingly. Returns OP_SUCCESS on success and * OP_FAILURE in case of error. */ int EchoClient::nep_recv_hs_server_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); u8 *inbuff=NULL; int inlen=0; /* Ask nsock to provide received data */ @@ -992,7 +992,7 @@ int EchoClient::nep_recv_hs_server_handler(nsock_pool nsp, nsock_event nse, void * the internal context accordingly. Returns OP_SUCCESS on success and * OP_FAILURE in case of error. */ int EchoClient::nep_recv_hs_final_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); u8 *inbuff=NULL; int inlen=0; /* Ask nsock to provide received data */ @@ -1012,7 +1012,7 @@ int EchoClient::nep_recv_hs_final_handler(nsock_pool nsp, nsock_event nse, void * the internal context accordingly. Returns OP_SUCCESS on success and * OP_FAILURE in case of error. */ int EchoClient::nep_recv_ready_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); u8 *inbuff=NULL; int inlen=0; /* Ask nsock to provide received data */ @@ -1035,7 +1035,7 @@ int EchoClient::nep_recv_ready_handler(nsock_pool nsp, nsock_event nse, void *ar * method. We need this because C++ does not allow to use class methods as * callback functions for things like signal() or the Nsock lib. */ void echoed_packet_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); ec.nep_echoed_packet_handler(nsp, nse, arg); return; } /* End of echoed_packet_handler() */ @@ -1045,7 +1045,7 @@ void echoed_packet_handler(nsock_pool nsp, nsock_event nse, void *arg){ * method. We need this because C++ does not allow to use class methods as * callback functions for things like signal() or the Nsock lib. */ void recv_std_header_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); ec.nep_recv_std_header_handler(nsp, nse, arg); return; } /* End of recv_std_header_handler() */ @@ -1056,10 +1056,10 @@ void recv_std_header_handler(nsock_pool nsp, nsock_event nse, void *arg){ * it was, we call nsock_loop_quit(), which indicates the success to * the method that scheduled the event and called nsock_loop() */ void connect_done_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); enum nse_status status=nse_status(nse); if (status!=NSE_STATUS_SUCCESS){ - outPrint(DBG_4, "%s(): Failed to connect.", __func__); + nping_print(DBG_4, "%s(): Failed to connect.", __func__); }else{ nsock_loop_quit(nsp); } @@ -1072,10 +1072,10 @@ void connect_done_handler(nsock_pool nsp, nsock_event nse, void *arg){ * in that case it calls nsock_loop_quit(), which indicates the success to * the method that scheduled the event and called nsock_loop() */ void write_done_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); enum nse_status status=nse_status(nse); if (status!=NSE_STATUS_SUCCESS){ - outPrint(DBG_4, "%s(): Write operation failed.", __func__); + nping_print(DBG_4, "%s(): Write operation failed.", __func__); }else{ nsock_loop_quit(nsp); } @@ -1087,10 +1087,10 @@ void write_done_handler(nsock_pool nsp, nsock_event nse, void *arg){ * method. We need this because C++ does not allow to use class methods as * callback functions for things like signal() or the Nsock lib. */ void recv_hs_server_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); enum nse_status status=nse_status(nse); if (status!=NSE_STATUS_SUCCESS){ - outPrint(DBG_4, "%s(): Read operation failed.", __func__); + nping_print(DBG_4, "%s(): Read operation failed.", __func__); }else if(ec.nep_recv_hs_server_handler(nsp, nse, arg)==OP_SUCCESS){ nsock_loop_quit(nsp); } @@ -1102,10 +1102,10 @@ void recv_hs_server_handler(nsock_pool nsp, nsock_event nse, void *arg){ * method. We need this because C++ does not allow to use class methods as * callback functions for things like signal() or the Nsock lib. */ void recv_hs_final_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); enum nse_status status=nse_status(nse); if (status!=NSE_STATUS_SUCCESS){ - outPrint(DBG_4, "%s(): Read operation failed.", __func__); + nping_print(DBG_4, "%s(): Read operation failed.", __func__); }else if(ec.nep_recv_hs_final_handler(nsp, nse, arg)==OP_SUCCESS){ nsock_loop_quit(nsp); } @@ -1118,10 +1118,10 @@ void recv_hs_final_handler(nsock_pool nsp, nsock_event nse, void *arg){ * method. We need this because C++ does not allow to use class methods as * callback functions for things like signal() or the Nsock lib. */ void recv_ready_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); enum nse_status status=nse_status(nse); if (status!=NSE_STATUS_SUCCESS){ - outPrint(DBG_4, "%s(): Read operation failed.", __func__); + nping_print(DBG_4, "%s(): Read operation failed.", __func__); }else if(ec.nep_recv_ready_handler(nsp, nse, arg)==OP_SUCCESS){ nsock_loop_quit(nsp); } diff --git a/nping/EchoHeader.cc b/nping/EchoHeader.cc index d59688a1d..0a000caf2 100755 --- a/nping/EchoHeader.cc +++ b/nping/EchoHeader.cc @@ -952,7 +952,7 @@ u8 *EchoHeader::getCiphertextBounds(size_t *final_len, int message_type){ * block. This should be stored by the caller and used as the IV for the * next encrypted data. It returns NULL in case of error. */ u8 *EchoHeader::encrypt(u8 *key, size_t key_len, u8 *iv){ - outPrint(DBG_4, "%s(%p, %lu, %p)", __func__, key, (long unsigned)key_len, iv); + nping_print(DBG_4, "%s(%p, %lu, %p)", __func__, key, (long unsigned)key_len, iv); u8 *start=NULL; size_t len=0; @@ -976,7 +976,7 @@ u8 *EchoHeader::encrypt(u8 *key, size_t key_len, u8 *iv){ u8 *EchoHeader::decrypt(u8 *key, size_t key_len, u8 *iv, int message_type){ - outPrint(DBG_4, "%s(%p, %lu, %p)", __func__, key, (long unsigned)key_len, iv); + nping_print(DBG_4, "%s(%p, %lu, %p)", __func__, key, (long unsigned)key_len, iv); u8 *start=NULL; size_t len=0; static u8 lastblock[CIPHER_BLOCK_SIZE]; @@ -999,4 +999,4 @@ u8 *EchoHeader::decrypt(u8 *key, size_t key_len, u8 *iv, int message_type){ }else{ return NULL; } -} /* End of decrypt() */ \ No newline at end of file +} /* End of decrypt() */ diff --git a/nping/EchoServer.cc b/nping/EchoServer.cc index 0608c11c5..170140511 100644 --- a/nping/EchoServer.cc +++ b/nping/EchoServer.cc @@ -121,7 +121,7 @@ void EchoServer::reset() { /** Adds a new client context object to the server context list */ int EchoServer::addClientContext(NEPContext ctx){ - outPrint(DBG_4, "%s(ctx->id=%d)", __func__, ctx.getIdentifier()); + nping_print(DBG_4, "%s(ctx->id=%d)", __func__, ctx.getIdentifier()); this->client_ctx.push_back(ctx); return OP_SUCCESS; } /* End of addClientContext() */ @@ -131,14 +131,14 @@ int EchoServer::addClientContext(NEPContext ctx){ * On success, it returns a pointer to the client's context object. NULL is * returned when no context could be found. */ NEPContext *EchoServer::getClientContext(clientid_t clnt){ - outPrint(DBG_4, "%s(%d) %lu", __func__, clnt, (unsigned long)this->client_ctx.size()); + nping_print(DBG_4, "%s(%d) %lu", __func__, clnt, (unsigned long)this->client_ctx.size()); for(unsigned int i=0; iclient_ctx.size(); i++){ if(this->client_ctx[i].getIdentifier() == clnt ){ - outPrint(DBG_3, "Found client with ID #%d at p%d. Total clients %lu", clnt, i, (unsigned long)this->client_ctx.size()); + nping_print(DBG_3, "Found client with ID #%d at p%d. Total clients %lu", clnt, i, (unsigned long)this->client_ctx.size()); return &(this->client_ctx[i]); } } - outPrint(DBG_3, "No client with ID #%d was found. Total clients %lu", clnt, (unsigned long)this->client_ctx.size()); + nping_print(DBG_3, "No client with ID #%d was found. Total clients %lu", clnt, (unsigned long)this->client_ctx.size()); return NULL; } /* End of getClientContext() */ @@ -147,7 +147,7 @@ NEPContext *EchoServer::getClientContext(clientid_t clnt){ * On success, it returns a pointer to the client's context object. NULL is * returned when no context could be found. */ NEPContext *EchoServer::getClientContext(nsock_iod iod){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); clientid_t *id=NULL; if( (id=(clientid_t *)nsi_getud(iod))==NULL ) return NULL; @@ -176,7 +176,7 @@ int EchoServer::destroyClientContext(clientid_t clnt){ /** Returns the Nsock IOD associated with a given client ID. */ nsock_iod EchoServer::getClientNsockIOD(clientid_t clnt){ - outPrint(DBG_4, "%s(%d)", __func__, clnt); + nping_print(DBG_4, "%s(%d)", __func__, clnt); NEPContext *ctx; if((ctx=this->getClientContext(clnt))==NULL ) return NULL; @@ -198,7 +198,7 @@ nsock_iod EchoServer::getClientNsockIOD(clientid_t clnt){ * there is a tiny chance that after the 4,294,967,296th client, the assigned * number conflicts with an active session ;-) */ clientid_t EchoServer::getNewClientID(){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); if(this->client_id_count==0xFFFF) /* Wrap back to zero. */ this->client_id_count=0; else @@ -209,7 +209,7 @@ clientid_t EchoServer::getNewClientID(){ /** Returns a socket suitable to be passed to accept() */ int EchoServer::nep_listen_socket(){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); int one=1; /**< Dummy var for setsockopt() call */ int master_sd=-1; /**< Master socket. Server listens on it */ struct sockaddr_in server_addr4; /**< For our own IPv4 address */ @@ -227,12 +227,12 @@ int EchoServer::nep_listen_socket(){ /* Obtain a regular TCP socket for IPv6 */ if( (master_sd=socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP))<0 ) - outFatal(QT_3, "Could not obtain AF_INET/SOCK_STREAM/IPPROTO_TCP socket"); + nping_fatal(QT_3, "Could not obtain AF_INET/SOCK_STREAM/IPPROTO_TCP socket"); /* Set SO_REUSEADDR on socket so the bind does not fail if we had used * this port in a previous execution, not long ago. */ if( setsockopt(master_sd, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(int))!=0 ) - outError(QT_3, "Failed to set SO_REUSEADDR on master socket."); + nping_warning(QT_3, "Failed to set SO_REUSEADDR on master socket."); memset(&server_addr6, 0, sizeof(struct sockaddr_in6)); server_addr6.sin6_addr = (o.spoofSource()) ? o.getIPv6SourceAddress() : in6addr_any; @@ -244,18 +244,18 @@ int EchoServer::nep_listen_socket(){ #endif /* Bind to local address and the specified port */ if( bind(master_sd, (struct sockaddr *)&server_addr6, sizeof(server_addr6)) != 0 ){ - outError(QT_3, "Failed to bind to source address %s. Trying to bind to port %d...", IPtoa(server_addr6.sin6_addr), port); + nping_warning(QT_3, "Failed to bind to source address %s. Trying to bind to port %d...", IPtoa(server_addr6.sin6_addr), port); /* If the bind failed for the supplied address, just try again with in6addr_any */ if( o.spoofSource() ){ server_addr6.sin6_addr = in6addr_any; if( bind(master_sd, (struct sockaddr *)&server_addr6, sizeof(server_addr6)) != 0 ){ - outFatal(QT_3, "Could not bind to port %d (%s).", port, strerror(errno)); + nping_fatal(QT_3, "Could not bind to port %d (%s).", port, strerror(errno)); }else{ - outPrint(VB_1, "Server bound to port %d", port); + nping_print(VB_1, "Server bound to port %d", port); } } }else{ - outPrint(VB_1, "Server bound to %s:%d", IPtoa(server_addr6.sin6_addr), port); + nping_print(VB_1, "Server bound to %s:%d", IPtoa(server_addr6.sin6_addr), port); } @@ -264,12 +264,12 @@ int EchoServer::nep_listen_socket(){ /* Obtain a regular TCP socket for IPv4 */ if( (master_sd=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))<0 ) - outFatal(QT_3, "Could not obtain AF_INET/SOCK_STREAM/IPPROTO_TCP socket"); + nping_fatal(QT_3, "Could not obtain AF_INET/SOCK_STREAM/IPPROTO_TCP socket"); /* Set SO_REUSEADDR on socket so the bind does not fail if we had used * this port in a previous execution, not long ago. */ if( setsockopt(master_sd, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(int))!=0 ) - outError(QT_3, "Failed to set SO_REUSEADDR on master socket."); + nping_warning(QT_3, "Failed to set SO_REUSEADDR on master socket."); memset(&server_addr4, 0, sizeof(struct sockaddr_in)); @@ -282,25 +282,25 @@ int EchoServer::nep_listen_socket(){ /* Bind to local address and the specified port */ if( bind(master_sd, (struct sockaddr *)&server_addr4, sizeof(server_addr4)) != 0 ){ - outError(QT_3, "Failed to bind to source address %s. Trying to bind to port %d...", IPtoa(server_addr4.sin_addr), port); + nping_warning(QT_3, "Failed to bind to source address %s. Trying to bind to port %d...", IPtoa(server_addr4.sin_addr), port); /* If the bind failed for the supplied address, just try again with in6addr_any */ if( o.spoofSource() ){ server_addr4.sin_addr.s_addr=INADDR_ANY; if( bind(master_sd, (struct sockaddr *)&server_addr4, sizeof(server_addr4)) != 0 ){ - outFatal(QT_3, "Could not bind to port %d (%s).", port, strerror(errno)); + nping_fatal(QT_3, "Could not bind to port %d (%s).", port, strerror(errno)); }else{ - outPrint(VB_1, "Server bound to port %d", port); + nping_print(VB_1, "Server bound to port %d", port); } } }else{ - outPrint(VB_1, "Server bound to %s:%d", IPtoa(server_addr4.sin_addr), port); + nping_print(VB_1, "Server bound to %s:%d", IPtoa(server_addr4.sin_addr), port); } } /* Listen for incoming TCP connections... */ if( listen(master_sd, LISTEN_QUEUE_SIZE) != 0 ){ - outFatal(QT_3, "[E] Failed to listen() on port %d (%s)", port, strerror(errno)); + nping_fatal(QT_3, "[E] Failed to listen() on port %d (%s)", port, strerror(errno)); } return master_sd; } /* End of nep_listen() */ @@ -336,7 +336,7 @@ int EchoServer::nep_listen_socket(){ #define MIN_ACCEPTABLE_SCORE_ICMP 6.0 clientid_t EchoServer::nep_match_headers(IPv4Header *ip4, IPv6Header *ip6, TCPHeader *tcp, UDPHeader *udp, ICMPv4Header *icmp4, RawData *payload){ - outPrint(DBG_4, "%s(%p,%p,%p,%p,%p,%p)", __func__, ip4, ip6, tcp, udp, icmp4, payload); + nping_print(DBG_4, "%s(%p,%p,%p,%p,%p,%p)", __func__, ip4, ip6, tcp, udp, icmp4, payload); unsigned int i=0, k=0; u8 *buff=NULL; int bufflen=-1; @@ -351,175 +351,175 @@ clientid_t EchoServer::nep_match_headers(IPv4Header *ip4, IPv6Header *ip6, TCPHe for(i=0; iclient_ctx.size(); i++ ){ current_score=0; ctx=&(this->client_ctx[i]); - outPrint(DBG_2, "%s() Trying to match packet against client #%d", __func__, ctx->getIdentifier()); + nping_print(DBG_2, "%s() Trying to match packet against client #%d", __func__, ctx->getIdentifier()); if( ctx->ready() ){ /* Iterate through client's list of packet field specifiers */ for(k=0; (fspec=ctx->getClientFieldSpec(k))!=NULL; k++){ switch(fspec->field){ case PSPEC_IPv4_TOS: if(ip4==NULL)break; - outPrint(DBG_3, "%s() Trying to match IP TOS", __func__); + nping_print(DBG_3, "%s() Trying to match IP TOS", __func__); if( ip4->getTOS()==fspec->value[0] ){ - outPrint(DBG_3, "[Match] IP TOS=%02x", ip4->getTOS()); + nping_print(DBG_3, "[Match] IP TOS=%02x", ip4->getTOS()); current_score += 1 * FACTOR_IPv4_TOS * ((ip4->getTOS()==0) ? ZERO_PENALTY : 1); } break; case PSPEC_IPv4_PROTO: if(ip4==NULL)break; - outPrint(DBG_3, "%s() Trying to match IP Next Protocol", __func__); + nping_print(DBG_3, "%s() Trying to match IP Next Protocol", __func__); if( ip4->getNextProto()==fspec->value[0] ){ - outPrint(DBG_3, "[Match] IP Proto=%02x", ip4->getNextProto()); + nping_print(DBG_3, "[Match] IP Proto=%02x", ip4->getNextProto()); current_score += 1 * FACTOR_IPv4_PROTO; } break; case PSPEC_IPv4_ID: if(ip4==NULL)break; - outPrint(DBG_3, "%s() Trying to match IP Identification", __func__); + nping_print(DBG_3, "%s() Trying to match IP Identification", __func__); if( ip4->getIdentification()==ntohs( *((u16 *)fspec->value) ) ){ - outPrint(DBG_3, "[Match] IP Id=%u", ip4->getIdentification()); + nping_print(DBG_3, "[Match] IP Id=%u", ip4->getIdentification()); current_score += 2 * FACTOR_IPv4_ID; } break; case PSPEC_IPv4_FRAGOFF: if(ip4==NULL)break; - outPrint(DBG_3, "%s() Trying to match IP Fragment offset", __func__); + nping_print(DBG_3, "%s() Trying to match IP Fragment offset", __func__); if( ip4->getFragOffset()==ntohs( *((u16 *)fspec->value)) ){ - outPrint(DBG_3, "[Match] IP FragOff=%u", ip4->getFragOffset() ); + nping_print(DBG_3, "[Match] IP FragOff=%u", ip4->getFragOffset() ); current_score += 2 * FACTOR_IPv4_FRAGOFF * ((ip4->getFragOffset()==0) ? ZERO_PENALTY : 1); } break; case PSPEC_IPv6_TCLASS: if(ip6==NULL)break; - outPrint(DBG_3, "%s() Trying to match IPv6 Traffic Class", __func__); + nping_print(DBG_3, "%s() Trying to match IPv6 Traffic Class", __func__); if( ip6->getTrafficClass()==fspec->value[0] ){ - outPrint(DBG_3, "[Match] IPv6 TClass=%u", ip6->getTrafficClass() ); + nping_print(DBG_3, "[Match] IPv6 TClass=%u", ip6->getTrafficClass() ); current_score += 1 * FACTOR_IPv6_TCLASS * ((ip6->getTrafficClass()==0) ? ZERO_PENALTY : 1); } break; case PSPEC_IPv6_FLOW: if(ip6==NULL)break; - outPrint(DBG_3, "%s() Trying to match IPv6 Flow Label", __func__); + nping_print(DBG_3, "%s() Trying to match IPv6 Flow Label", __func__); if( ip6->getFlowLabel()==ntohl( *((u32 *)fspec->value)) ){ - outPrint(DBG_3, "[Match] IPv6 Flow=%lu", (long unsigned)ip6->getFlowLabel() ); + nping_print(DBG_3, "[Match] IPv6 Flow=%lu", (long unsigned)ip6->getFlowLabel() ); current_score += 3 * FACTOR_IPv6_FLOW * ((ip6->getFlowLabel()==0) ? ZERO_PENALTY : 1); } break; case PSPEC_IPv6_NHDR: if(ip6==NULL)break; - outPrint(DBG_3, "%s() Trying to match IPv6 Next Header", __func__); + nping_print(DBG_3, "%s() Trying to match IPv6 Next Header", __func__); if( ip6->getNextHeader()==fspec->value[0] ){ - outPrint(DBG_3, "[Match] IPv6 NextHdr=%02x", ip6->getNextHeader()); + nping_print(DBG_3, "[Match] IPv6 NextHdr=%02x", ip6->getNextHeader()); current_score += 1 * FACTOR_IPv6_NHDR; } break; case PSPEC_TCP_SPORT: if(tcp==NULL)break; - outPrint(DBG_3, "%s() Trying to match TCP Source Port", __func__); + nping_print(DBG_3, "%s() Trying to match TCP Source Port", __func__); if( tcp->getSourcePort()==ntohs( *((u16 *)fspec->value) ) ){ - outPrint(DBG_3, "[Match] TCP Src=%u", tcp->getSourcePort()); + nping_print(DBG_3, "[Match] TCP Src=%u", tcp->getSourcePort()); current_score += 2 * FACTOR_TCP_SPORT; } break; case PSPEC_TCP_DPORT: if(tcp==NULL)break; - outPrint(DBG_3, "%s() Trying to match TCP Destination Port", __func__); + nping_print(DBG_3, "%s() Trying to match TCP Destination Port", __func__); if( tcp->getDestinationPort()==ntohs( *((u16 *)fspec->value) ) ){ - outPrint(DBG_3, "[Match] TCP Dst=%u", tcp->getDestinationPort()); + nping_print(DBG_3, "[Match] TCP Dst=%u", tcp->getDestinationPort()); current_score += 2 * FACTOR_TCP_DPORT; } break; case PSPEC_TCP_SEQ: if(tcp==NULL)break; - outPrint(DBG_3, "%s() Trying to match TCP Sequence Number", __func__); + nping_print(DBG_3, "%s() Trying to match TCP Sequence Number", __func__); if( tcp->getSeq()==ntohl( *((u32 *)fspec->value) ) ){ - outPrint(DBG_3, "[Match] TCP Seq=%u", tcp->getSeq()); + nping_print(DBG_3, "[Match] TCP Seq=%u", tcp->getSeq()); current_score += 4 * FACTOR_TCP_SEQ * ((tcp->getSeq()==0) ? ZERO_PENALTY : 1); } break; case PSPEC_TCP_ACK: if(tcp==NULL)break; - outPrint(DBG_3, "%s() Trying to match TCP Acknowledgment", __func__); + nping_print(DBG_3, "%s() Trying to match TCP Acknowledgment", __func__); if( tcp->getAck()==ntohl( *((u32 *)fspec->value) ) ){ - outPrint(DBG_3, "[Match] TCP Ack=%u", tcp->getAck()); + nping_print(DBG_3, "[Match] TCP Ack=%u", tcp->getAck()); current_score += 4 * FACTOR_TCP_ACK * ((tcp->getAck()==0) ? ZERO_PENALTY : 1); } break; case PSPEC_TCP_FLAGS: if(tcp==NULL)break; if( tcp->getFlags()==fspec->value[0] ){ - outPrint(DBG_3, "%s() Trying to match TCP Flags", __func__); - outPrint(DBG_3, "[Match] TCP Flags=%02x", tcp->getFlags()); + nping_print(DBG_3, "%s() Trying to match TCP Flags", __func__); + nping_print(DBG_3, "[Match] TCP Flags=%02x", tcp->getFlags()); current_score += 1 * FACTOR_TCP_FLAGS; } break; case PSPEC_TCP_WIN: if(tcp==NULL)break; - outPrint(DBG_3, "%s() Trying to match TCP Window", __func__); + nping_print(DBG_3, "%s() Trying to match TCP Window", __func__); if( tcp->getWindow()==ntohs( *((u16 *)fspec->value) ) ){ - outPrint(DBG_3, "[Match] TCP Win=%u", tcp->getWindow()); + nping_print(DBG_3, "[Match] TCP Win=%u", tcp->getWindow()); current_score += 2 * FACTOR_TCP_WIN * ((tcp->getWindow()==0) ? ZERO_PENALTY : 1); } break; case PSPEC_TCP_URP: if(tcp==NULL)break; - outPrint(DBG_3, "%s() Trying to match TCP Urgent Pointer", __func__); + nping_print(DBG_3, "%s() Trying to match TCP Urgent Pointer", __func__); if( tcp->getUrgPointer()==ntohs( *((u16 *)fspec->value) ) ){ - outPrint(DBG_3, "[Match] TCP Win=%u", tcp->getUrgPointer()); + nping_print(DBG_3, "[Match] TCP Win=%u", tcp->getUrgPointer()); current_score += 2 * FACTOR_TCP_URP * ((tcp->getUrgPointer()==0) ? ZERO_PENALTY : 1); } break; case PSPEC_ICMP_TYPE: if(icmp4==NULL)break; - outPrint(DBG_3, "%s() Trying to match ICMPv4 Type", __func__); + nping_print(DBG_3, "%s() Trying to match ICMPv4 Type", __func__); if( icmp4->getType()==fspec->value[0] ){ - outPrint(DBG_3, "[Match] ICMPv4 Type=%02x", icmp4->getType()); + nping_print(DBG_3, "[Match] ICMPv4 Type=%02x", icmp4->getType()); current_score += 1 * FACTOR_ICMP_TYPE; } break; case PSPEC_ICMP_CODE: if(icmp4==NULL)break; - outPrint(DBG_3, "%s() Trying to match ICMPv4 Code", __func__); + nping_print(DBG_3, "%s() Trying to match ICMPv4 Code", __func__); if( icmp4->getCode()==fspec->value[0] ){ - outPrint(DBG_3, "[Match] ICMPv4 Code=%02x", icmp4->getCode()); + nping_print(DBG_3, "[Match] ICMPv4 Code=%02x", icmp4->getCode()); current_score += 1 * FACTOR_ICMP_CODE * ((icmp4->getCode()==0) ? ZERO_PENALTY : 1); } break; case PSPEC_UDP_SPORT: if(udp==NULL)break; - outPrint(DBG_3, "%s() Trying to match UDP Source Port", __func__); + nping_print(DBG_3, "%s() Trying to match UDP Source Port", __func__); if( udp->getSourcePort()==ntohs( *((u16 *)fspec->value) ) ){ - outPrint(DBG_3, "[Match] UDP Src=%u", udp->getSourcePort()); + nping_print(DBG_3, "[Match] UDP Src=%u", udp->getSourcePort()); current_score += 2 * FACTOR_UDP_SPORT; } break; case PSPEC_UDP_DPORT: if(udp==NULL)break; - outPrint(DBG_3, "%s() Trying to match UDP Destination Port", __func__); + nping_print(DBG_3, "%s() Trying to match UDP Destination Port", __func__); if( udp->getDestinationPort()==ntohs( *((u16 *)fspec->value) ) ){ - outPrint(DBG_3, "[Match] UDP Dst=%u", udp->getDestinationPort()); + nping_print(DBG_3, "[Match] UDP Dst=%u", udp->getDestinationPort()); current_score += 2 * FACTOR_UDP_DPORT; } break; case PSPEC_UDP_LEN: if(udp==NULL)break; - outPrint(DBG_3, "%s() Trying to match UDP Length", __func__); + nping_print(DBG_3, "%s() Trying to match UDP Length", __func__); if( udp->getTotalLength()==ntohs( *((u16 *)fspec->value) ) ){ - outPrint(DBG_3, "[Match] UDP Len=%u", udp->getTotalLength()); + nping_print(DBG_3, "[Match] UDP Len=%u", udp->getTotalLength()); current_score += 2 * FACTOR_UDP_LEN * ((udp->getTotalLength()==8) ? ZERO_PENALTY : 1); } break; case PSPEC_PAYLOAD_MAGIC: if(payload==NULL)break; - outPrint(DBG_3, "%s() Trying to match Payload Magic value", __func__); + nping_print(DBG_3, "%s() Trying to match Payload Magic value", __func__); buff=payload->getBinaryBuffer(&bufflen); if(buff==NULL || bufflen<=0 || fspec->len>bufflen) break; if( memcmp(buff, fspec->value, fspec->len)==0 ){ - outPrint(DBG_3|NO_NEWLINE, "[Match] Payload magic=0x"); + nping_print(DBG_3|NO_NEWLINE, "[Match] Payload magic=0x"); for(unsigned int i=0; ilen; i++) - outPrint(DBG_3|NO_NEWLINE,"%02x", fspec->value[i]); - outPrint(DBG_3, ";"); + nping_print(DBG_3|NO_NEWLINE,"%02x", fspec->value[i]); + nping_print(DBG_3, ";"); /* The payload magic may affect the score only between * zero and 4 bytes. This is done to prevent long * common strings like "GET / HTTP/1.1\r\n" @@ -530,16 +530,16 @@ clientid_t EchoServer::nep_match_headers(IPv4Header *ip4, IPv6Header *ip6, TCPHe break; default: - outError(QT_2, "Bogus field specifier found in client #%d context. Please report a bug", ctx->getIdentifier()); + nping_warning(QT_2, "Bogus field specifier found in client #%d context. Please report a bug", ctx->getIdentifier()); break; } } /* End of field specifiers loop */ - outPrint(DBG_3, "%s() current_score=%.02f candidate_score=%.02f", __func__, current_score, candidate_score); + nping_print(DBG_3, "%s() current_score=%.02f candidate_score=%.02f", __func__, current_score, candidate_score); if( (current_score>0) && (current_score>=candidate_score)){ candidate_score=current_score; candidate=ctx->getIdentifier(); - outPrint(DBG_3, "%s() Found better candidate (client #%d; score=%.02f)", __func__, candidate, candidate_score); + nping_print(DBG_3, "%s() Found better candidate (client #%d; score=%.02f)", __func__, candidate, candidate_score); } } } /* End of connected clients loop */ @@ -555,13 +555,13 @@ clientid_t EchoServer::nep_match_headers(IPv4Header *ip4, IPv6Header *ip6, TCPHe /* Check if we managed to match packet and client */ if (candidate>=0 && candidate_score>=minimum_score){ - outPrint(DBG_2, "%s() Packet matched successfully with client #%d", __func__, candidate); + nping_print(DBG_2, "%s() Packet matched successfully with client #%d", __func__, candidate); return candidate; }else{ if(candidate<0) - outPrint(DBG_2, "%s() Couldn't match packet with any client.", __func__); + nping_print(DBG_2, "%s() Couldn't match packet with any client.", __func__); else - outPrint(DBG_2, "%s() Found matching client but score is too low. Discarded.", __func__); + nping_print(DBG_2, "%s() Found matching client but score is too low. Discarded.", __func__); return CLIENT_NOT_FOUND; } return CLIENT_NOT_FOUND; @@ -569,7 +569,7 @@ clientid_t EchoServer::nep_match_headers(IPv4Header *ip4, IPv6Header *ip6, TCPHe clientid_t EchoServer::nep_match_packet(const u8 *pkt, size_t pktlen){ - outPrint(DBG_4, "%s(%p, %lu)", __func__, pkt, (long unsigned)pktlen); + nping_print(DBG_4, "%s(%p, %lu)", __func__, pkt, (long unsigned)pktlen); int iplen=0, ip6len=0, tcplen=0, udplen=0; bool payload_included=false; IPv4Header ip4; @@ -580,10 +580,10 @@ clientid_t EchoServer::nep_match_packet(const u8 *pkt, size_t pktlen){ RawData payload; if(this->client_id_count<0){ - outPrint(DBG_1, "Error trying to match the packet. No clients connected."); + nping_print(DBG_1, "Error trying to match the packet. No clients connected."); return CLIENT_NOT_FOUND; }else if(pktlenclient_ctx.size()>0){ nsock_pcap_read_packet(nsp, nsi, capture_handler, NSOCK_INFINITE, &arg); - outPrint(DBG_3, "Scheduled next capture event"); + nping_print(DBG_3, "Scheduled next capture event"); } /* Get the actual captured packet */ nse_readpcap(nse, &link, &linklen, &packet, &packetlen, NULL, &pcaptime); - outPrint(DBG_3, "Captured %lu bytes", (unsigned long)packetlen); + nping_print(DBG_3, "Captured %lu bytes", (unsigned long)packetlen); /* Update Rx stats */ o.stats.addRecvPacket(packetlen); /* Try to match received packet with a connected client. */ if( (clnt=this->nep_match_packet(packet, packetlen)) == CLIENT_NOT_FOUND ){ - outPrint(DBG_3, "Couldn't match captured packet with a client"); + nping_print(DBG_3, "Couldn't match captured packet with a client"); return OP_FAILURE; }else{ - outPrint(DBG_4, "Captured packet belongs to client #%d", clnt); + nping_print(DBG_4, "Captured packet belongs to client #%d", clnt); } /* Fetch client context */ if( (ctx=this->getClientContext(clnt)) == NULL ){ - outPrint(DBG_2, "Error: no context found for client #%d", clnt); + nping_print(DBG_2, "Error: no context found for client #%d", clnt); return OP_FAILURE; } /* Lookup client's IOD */ if( (clnt_iod=ctx->getNsockIOD()) == NULL ){ - outPrint(DBG_2, "Error: no IOD found for client #%d", clnt); + nping_print(DBG_2, "Error: no IOD found for client #%d", clnt); return OP_FAILURE; } @@ -892,25 +892,25 @@ int EchoServer::nep_capture_handler(nsock_pool nsp, nsock_event nse, void *param int EchoServer::nep_echo_handler(nsock_pool nsp, nsock_event nse, void *param){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); enum nse_status status=nse_status(nse); if (status!=NSE_STATUS_SUCCESS){ - outPrint(DBG_1, "Couldn't send NEP_ECHO. Terminating client session\n"); + nping_print(DBG_1, "Couldn't send NEP_ECHO. Terminating client session\n"); this->nep_session_ended_handler(nsp, nse, param); }else{ - outPrint(DBG_1, "SENT: NEP_ECHO"); + nping_print(DBG_1, "SENT: NEP_ECHO"); } return OP_SUCCESS; } /* End of nep_echo_handler() */ int EchoServer::nep_hs_server_handler(nsock_pool nsp, nsock_event nse, void *param){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); nsock_iod nsi = nse_iod(nse); NEPContext *ctx=NULL; enum nse_status status=nse_status(nse); if (status!=NSE_STATUS_SUCCESS){ - outPrint(DBG_1, "Couldn't send NEP_HANDSHAKE_SERVER. Terminating client session\n"); + nping_print(DBG_1, "Couldn't send NEP_HANDSHAKE_SERVER. Terminating client session\n"); this->nep_session_ended_handler(nsp, nse, param); return OP_FAILURE; } @@ -918,7 +918,7 @@ int EchoServer::nep_hs_server_handler(nsock_pool nsp, nsock_event nse, void *par * NEP_HANDSHAKE_CLIENT message */ if( (ctx=this->getClientContext(nsi))!=NULL ){ ctx->setState(STATE_HS_SERVER_SENT); - outPrint(DBG_1, "SENT: NEP_HANDSHAKE_SERVER to %s", IPtoa(ctx->getAddress())); + nping_print(DBG_1, "SENT: NEP_HANDSHAKE_SERVER to %s", IPtoa(ctx->getAddress())); nsock_readbytes(nsp, nsi, hs_client_handler, NSOCK_INFINITE, NULL, NEP_HANDSHAKE_CLIENT_LEN); } return OP_SUCCESS; @@ -926,7 +926,7 @@ int EchoServer::nep_hs_server_handler(nsock_pool nsp, nsock_event nse, void *par int EchoServer::nep_hs_client_handler(nsock_pool nsp, nsock_event nse, void *param){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); nsock_iod nsi = nse_iod(nse); NEPContext *ctx=NULL; EchoHeader pkt_out; @@ -934,11 +934,11 @@ int EchoServer::nep_hs_client_handler(nsock_pool nsp, nsock_event nse, void *par int inlen=0; enum nse_status status=nse_status(nse); if (status!=NSE_STATUS_SUCCESS){ - outPrint(DBG_1, "Failed to receive NEP_HANDSHAKE_CLIENT. Terminating client session"); + nping_print(DBG_1, "Failed to receive NEP_HANDSHAKE_CLIENT. Terminating client session"); this->nep_session_ended_handler(nsp, nse, param); return OP_FAILURE; }else{ - outPrint(DBG_1, "RCVD: NEP_HANDSHAKE_CLIENT"); + nping_print(DBG_1, "RCVD: NEP_HANDSHAKE_CLIENT"); } /* Lookup client context */ @@ -971,9 +971,9 @@ int EchoServer::nep_hs_client_handler(nsock_pool nsp, nsock_event nse, void *par int EchoServer::nep_hs_final_handler(nsock_pool nsp, nsock_event nse, void *param){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); nsock_iod nsi = nse_iod(nse); - outPrint(DBG_1, "SENT: NEP_HANDSHAKE_FINAL"); + nping_print(DBG_1, "SENT: NEP_HANDSHAKE_FINAL"); /* Receive NEP_PACKETSPEC */ nsock_readbytes(nsp, nsi, packetspec_handler, NSOCK_INFINITE, NULL, NEP_PACKETSPEC_LEN); return OP_SUCCESS; @@ -981,7 +981,7 @@ int EchoServer::nep_hs_final_handler(nsock_pool nsp, nsock_event nse, void *para int EchoServer::nep_packetspec_handler(nsock_pool nsp, nsock_event nse, void *param){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); nsock_iod nsi = nse_iod(nse); EchoHeader pkt_in; EchoHeader pkt_out; @@ -990,11 +990,11 @@ int EchoServer::nep_packetspec_handler(nsock_pool nsp, nsock_event nse, void *pa int recvbytes=0; enum nse_status status=nse_status(nse); if (status!=NSE_STATUS_SUCCESS){ - outPrint(DBG_1, "Failed to receive NEP_PACKET_SPEC message. Terminating client session\n"); + nping_print(DBG_1, "Failed to receive NEP_PACKET_SPEC message. Terminating client session\n"); this->nep_session_ended_handler(nsp, nse, param); return OP_FAILURE; }else{ - outPrint(DBG_1, "RCVD: NEP_PACKETSPEC"); + nping_print(DBG_1, "RCVD: NEP_PACKETSPEC"); } /* Lookup client context */ @@ -1012,11 +1012,11 @@ int EchoServer::nep_packetspec_handler(nsock_pool nsp, nsock_event nse, void *pa /* Validate received NEP_PACKET_SPEC message */ if( this->parse_packet_spec(recvbuff, recvbytes, ctx)!=OP_SUCCESS ){ this->nep_session_ended_handler(nsp, nse, param); - outPrint(VB_1, "[%lu] Couldn't establish NEP session with client #%d (%s:%d).", (unsigned long)time(NULL), ctx->getIdentifier(), IPtoa(ctx->getAddress()), sockaddr2port(ctx->getAddress())); + nping_print(VB_1, "[%lu] Couldn't establish NEP session with client #%d (%s:%d).", (unsigned long)time(NULL), ctx->getIdentifier(), IPtoa(ctx->getAddress()), sockaddr2port(ctx->getAddress())); return OP_FAILURE; } ctx->setState(STATE_READY_SENT); - outPrint(VB_1, "[%lu] NEP handshake with client #%d (%s:%d) was performed successfully", (unsigned long)time(NULL), ctx->getIdentifier(), IPtoa(ctx->getAddress()), sockaddr2port(ctx->getAddress())); + nping_print(VB_1, "[%lu] NEP handshake with client #%d (%s:%d) was performed successfully", (unsigned long)time(NULL), ctx->getIdentifier(), IPtoa(ctx->getAddress()), sockaddr2port(ctx->getAddress())); /* Craft response and send it */ this->generate_ready(&pkt_out, ctx); @@ -1036,26 +1036,26 @@ int EchoServer::nep_packetspec_handler(nsock_pool nsp, nsock_event nse, void *pa int EchoServer::nep_ready_handler(nsock_pool nsp, nsock_event nse, void *param){ - outPrint(DBG_4, "%s()", __func__); - outPrint(DBG_1, "SENT: NEP_READY"); + nping_print(DBG_4, "%s()", __func__); + nping_print(DBG_1, "SENT: NEP_READY"); return OP_SUCCESS; } /* End of nep_ready_handler() */ int EchoServer::nep_session_ended_handler(nsock_pool nsp, nsock_event nse, void *param){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); nsock_iod nsi = nse_iod(nse); clientid_t clnt; NEPContext *ctx=NULL; /* Lookup client context */ if( (ctx=this->getClientContext(nsi))!=NULL ){ - outPrint(VB_0, "[%lu] Client #%d (%s:%d) disconnected", (unsigned long)time(NULL), ctx->getIdentifier(), IPtoa(ctx->getAddress()), sockaddr2port(ctx->getAddress())); + nping_print(VB_0, "[%lu] Client #%d (%s:%d) disconnected", (unsigned long)time(NULL), ctx->getIdentifier(), IPtoa(ctx->getAddress()), sockaddr2port(ctx->getAddress())); clnt=ctx->getIdentifier(); if(this->destroyClientContext(clnt)!=OP_SUCCESS) - outPrint(DBG_2, "Client #%d disconnected but no context found. This may be a bug.", clnt); + nping_print(DBG_2, "Client #%d disconnected but no context found. This may be a bug.", clnt); else - outPrint(DBG_2, "Deleted client #%d context.", clnt); + nping_print(DBG_2, "Deleted client #%d context.", clnt); } nsi_delete(nsi, NSOCK_PENDING_SILENT); @@ -1075,46 +1075,46 @@ int EchoServer::nep_session_ended_handler(nsock_pool nsp, nsock_event nse, void * it returns OP_SUCCESS. OP_FAILURE is returned in case the received packet * is not valid. */ int EchoServer::parse_hs_client(u8 *pkt, size_t pktlen, NEPContext *ctx){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); u8 *next_iv=NULL; EchoHeader h; if(pkt==NULL || ctx==NULL){ - outPrint(DBG_1,"%s(): NULL parameter supplied.", __func__ ); + nping_print(DBG_1,"%s(): NULL parameter supplied.", __func__ ); return OP_FAILURE; } if(pktlen!=NEP_HANDSHAKE_CLIENT_LEN){ - outPrint(DBG_1,"%s(): Unexpected length supplied.", __func__ ); + nping_print(DBG_1,"%s(): Unexpected length supplied.", __func__ ); return OP_FAILURE; } h.storeRecvData(pkt, pktlen); /* Validate version number */ if( h.getVersion() != ECHO_CURRENT_PROTO_VER ){ - outPrint(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); + nping_print(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); return OP_FAILURE; } /* Ensure the expected message type was received */ if(h.getMessageType()!=TYPE_NEP_HANDSHAKE_CLIENT){ - outPrint(DBG_1, "Expected NEP_HANDSHAKE_CLIENT but received %02X", h.getMessageType() ); + nping_print(DBG_1, "Expected NEP_HANDSHAKE_CLIENT but received %02X", h.getMessageType() ); return OP_FAILURE; } /* Ensure the received timestamp falls into the allowed time window */ //if( h.verifyTimestamp()!=OP_SUCCESS ){ - // outPrint(DBG_1, "NEP_HANDSHAKE_CLIENT timestamp is too old", h.getMessageType() ); + // nping_print(DBG_1, "NEP_HANDSHAKE_CLIENT timestamp is too old", h.getMessageType() ); // return OP_FAILURE; //} /* Ensure message length is correct */ if( h.getTotalLength()!=(NEP_HANDSHAKE_CLIENT_LEN/4)){ - outPrint(DBG_1, "Received NEP_HANDSHAKE_CLIENT specifies an incorrect length (%u)", h.getTotalLength()*4 ); + nping_print(DBG_1, "Received NEP_HANDSHAKE_CLIENT specifies an incorrect length (%u)", h.getTotalLength()*4 ); return OP_FAILURE; } /* Ensure the client echoed the nonce we sent in our NEP_HANDSHAKE_SERVER */ if( memcmp(h.getServerNonce(), ctx->getServerNonce(), NONCE_LEN)!=0 ){ - outPrint(DBG_1, "Echoed nonce in NEP_HANDSHAKE_CLIENT message does not match client generate nonce"); + nping_print(DBG_1, "Echoed nonce in NEP_HANDSHAKE_CLIENT message does not match client generate nonce"); return OP_FAILURE; } /* Store the received nonce */ @@ -1129,22 +1129,22 @@ int EchoServer::parse_hs_client(u8 *pkt, size_t pktlen, NEPContext *ctx){ ctx->generateMacKeyC2S(); ctx->generateMacKeyS2C(); - outPrint(DBG_3,"Session Key MAC_C2S:"); print_hexdump(DBG_3,ctx->getMacKeyC2S(), MAC_KEY_LEN); - outPrint(DBG_3,"Session Key MAC_S2C:"); print_hexdump(DBG_3,ctx->getMacKeyS2C(), MAC_KEY_LEN); - outPrint(DBG_3,"Session Key CIPHER_C2S:"); print_hexdump(DBG_3,ctx->getCipherKeyC2S(), MAC_KEY_LEN); - outPrint(DBG_3,"Session Key CIPHER_S2C:"); print_hexdump(DBG_3,ctx->getCipherKeyS2C(), MAC_KEY_LEN); + nping_print(DBG_3,"Session Key MAC_C2S:"); print_hexdump(DBG_3,ctx->getMacKeyC2S(), MAC_KEY_LEN); + nping_print(DBG_3,"Session Key MAC_S2C:"); print_hexdump(DBG_3,ctx->getMacKeyS2C(), MAC_KEY_LEN); + nping_print(DBG_3,"Session Key CIPHER_C2S:"); print_hexdump(DBG_3,ctx->getCipherKeyC2S(), MAC_KEY_LEN); + nping_print(DBG_3,"Session Key CIPHER_S2C:"); print_hexdump(DBG_3,ctx->getCipherKeyS2C(), MAC_KEY_LEN); /* Decrypt the encrypted part of the message before validating the MAC */ if((next_iv=h.decrypt(ctx->getCipherKeyC2S(), CIPHER_KEY_LEN, ctx->getClientNonce(), TYPE_NEP_HANDSHAKE_CLIENT))==NULL){ - outPrint(DBG_1, "Failed to decrypt NEP_HANDSHAKE_CLIENT data." ); + nping_print(DBG_1, "Failed to decrypt NEP_HANDSHAKE_CLIENT data." ); return OP_FAILURE; } ctx->setNextDecryptionIV(next_iv); /* Check the authenticity of the received message */ if( h.verifyMessageAuthenticationCode( ctx->getMacKeyC2S(), MAC_KEY_LEN)!=OP_SUCCESS ){ - outPrint(DBG_1, "NEP_HANDSHAKE_CLIENT authentication failed" ); + nping_print(DBG_1, "NEP_HANDSHAKE_CLIENT authentication failed" ); return OP_FAILURE; } @@ -1156,7 +1156,7 @@ int EchoServer::parse_hs_client(u8 *pkt, size_t pktlen, NEPContext *ctx){ * it returns OP_SUCCESS. OP_FAILURE is returned in case the received packet * is not valid. */ int EchoServer::parse_packet_spec(u8 *pkt, size_t pktlen, NEPContext *ctx){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); EchoHeader h; int recvspecs=0; bool id_received=false; @@ -1165,49 +1165,49 @@ int EchoServer::parse_packet_spec(u8 *pkt, size_t pktlen, NEPContext *ctx){ u8 *next_iv=NULL; u8 specbuff[PACKETSPEC_FIELD_LEN]; if(pkt==NULL){ - outPrint(DBG_1,"%s(): NULL parameter supplied.", __func__ ); + nping_print(DBG_1,"%s(): NULL parameter supplied.", __func__ ); return OP_FAILURE; } if(pktlen!=NEP_PACKETSPEC_LEN){ - outPrint(DBG_1,"%s(): Unexpected length supplied.", __func__ ); + nping_print(DBG_1,"%s(): Unexpected length supplied.", __func__ ); return OP_FAILURE; } h.storeRecvData(pkt, pktlen); /* Decrypt message */ if((next_iv=h.decrypt(ctx->getCipherKeyC2S(), CIPHER_KEY_LEN, ctx->getNextDecryptionIV(), TYPE_NEP_PACKET_SPEC))==NULL){ - outPrint(DBG_1, "Failed to decrypt NEP_PACKET_SPEC data." ); + nping_print(DBG_1, "Failed to decrypt NEP_PACKET_SPEC data." ); return OP_FAILURE; } ctx->setNextDecryptionIV(next_iv); /* Validate version number */ if( h.getVersion() != ECHO_CURRENT_PROTO_VER ){ - outPrint(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); + nping_print(DBG_1, "Expected NEP version %02x but message used %02x", ECHO_CURRENT_PROTO_VER, h.getVersion() ); return OP_FAILURE; } /* Ensure the expected message type was received */ if(h.getMessageType()!=TYPE_NEP_PACKET_SPEC){ - outPrint(DBG_1, "Expected NEP_PACKET_SPEC but received %02X", h.getMessageType() ); + nping_print(DBG_1, "Expected NEP_PACKET_SPEC but received %02X", h.getMessageType() ); return OP_FAILURE; } /* Ensure the received timestamp falls into the allowed time window */ //if( h.verifyTimestamp()!=OP_SUCCESS ){ - // outPrint(DBG_1, "NEP_PACKET_SPEC timestamp is too old", h.getMessageType() ); + // nping_print(DBG_1, "NEP_PACKET_SPEC timestamp is too old", h.getMessageType() ); // return OP_FAILURE; //} /* Ensure message length is correct */ if( h.getTotalLength()!=(NEP_PACKETSPEC_LEN/4)){ - outPrint(DBG_1, "Received NEP_PACKET_SPEC specifies an incorrect length (%u)", h.getTotalLength()*4 ); + nping_print(DBG_1, "Received NEP_PACKET_SPEC specifies an incorrect length (%u)", h.getTotalLength()*4 ); return OP_FAILURE; } /* Ensure the received sequence number is the previous+1 */ if( h.getSequenceNumber()!=(ctx->getLastClientSequence()+1)){ - outPrint(DBG_1, "Expected sequence number %d but received %d", ctx->getLastClientSequence()+1, h.getSequenceNumber() ); + nping_print(DBG_1, "Expected sequence number %d but received %d", ctx->getLastClientSequence()+1, h.getSequenceNumber() ); return OP_FAILURE; }else{ /* Increment next expected sequence number*/ @@ -1216,7 +1216,7 @@ int EchoServer::parse_packet_spec(u8 *pkt, size_t pktlen, NEPContext *ctx){ /* Check the authenticity of the received message */ if( h.verifyMessageAuthenticationCode( ctx->getMacKeyC2S(), MAC_KEY_LEN)!=OP_SUCCESS ){ - outPrint(DBG_1, "NEP_PACKET_SPEC authentication failed" ); + nping_print(DBG_1, "NEP_PACKET_SPEC authentication failed" ); return OP_FAILURE; } @@ -1230,7 +1230,7 @@ int EchoServer::parse_packet_spec(u8 *pkt, size_t pktlen, NEPContext *ctx){ /* Ensure the field spec is unique. Malicious users could try to supply * the same spec more than once in order to get higher packet scores. */ if( ctx->isDuplicateFieldSpec(field) ){ - outPrint(DBG_1, "Detected duplicate field specs in NEP_PACKET_SPEC message" ); + nping_print(DBG_1, "Detected duplicate field specs in NEP_PACKET_SPEC message" ); return OP_FAILURE; }else{ ctx->addClientFieldSpec(field, len, specbuff); @@ -1242,15 +1242,15 @@ int EchoServer::parse_packet_spec(u8 *pkt, size_t pktlen, NEPContext *ctx){ id_received=true; else if(h.getIPVersion()==0x06 && field==PSPEC_IPv6_FLOW) id_received=true; - outPrint(DBG_3|NO_NEWLINE,"RCVD FieldSpec: Type=%02X Len=%02x Data=0x", field, (u8)len); + nping_print(DBG_3|NO_NEWLINE,"RCVD FieldSpec: Type=%02X Len=%02x Data=0x", field, (u8)len); for(unsigned int i=0; i=4){ - outPrint(VB_2, "[%lu] Good packet specification received from client #%d (Specs=%d,IP=%d,Proto=%d,Cnt=%d)", + nping_print(VB_2, "[%lu] Good packet specification received from client #%d (Specs=%d,IP=%d,Proto=%d,Cnt=%d)", (unsigned long)time(NULL), ctx->getIdentifier(), recvspecs, h.getIPVersion(), h.getProtocol(), h.getPacketCount() ); return OP_SUCCESS; @@ -1265,7 +1265,7 @@ int EchoServer::parse_packet_spec(u8 *pkt, size_t pktlen, NEPContext *ctx){ * @warning the caller must ensure that the supplied context object * already contains an initial sequence number and a server nonce. */ int EchoServer::generate_hs_server(EchoHeader *h, NEPContext *ctx){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); if(h==NULL || ctx==NULL) return OP_FAILURE; @@ -1283,7 +1283,7 @@ int EchoServer::generate_hs_server(EchoHeader *h, NEPContext *ctx){ /** Generates a NEP_HANDSHAKE_FINAL message. On success it returns OP_SUCCESS. * OP_FAILURE is returned in case of error. */ int EchoServer::generate_hs_final(EchoHeader *h, NEPContext *ctx){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); struct sockaddr_storage ss; u8 *next_iv=NULL; if(h==NULL || ctx==NULL) @@ -1318,7 +1318,7 @@ int EchoServer::generate_hs_final(EchoHeader *h, NEPContext *ctx){ /** Generates a NEP_READY message. On success it returns OP_SUCCESS. * OP_FAILURE is returned in case of error. */ int EchoServer::generate_ready(EchoHeader *h, NEPContext *ctx){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); u8 *next_iv=NULL; if(h==NULL || ctx==NULL) return OP_FAILURE; @@ -1342,7 +1342,7 @@ int EchoServer::generate_ready(EchoHeader *h, NEPContext *ctx){ /** Generates a NEP_ECHO message. On success it returns OP_SUCCESS. * OP_FAILURE is returned in case of error. */ int EchoServer::generate_echo(EchoHeader *h, const u8 *pkt, size_t pktlen, NEPContext *ctx){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); u8 *next_iv=NULL; if(h==NULL || ctx==NULL || pkt==NULL || pktlen==0) return OP_FAILURE; @@ -1363,11 +1363,11 @@ int EchoServer::generate_echo(EchoHeader *h, const u8 *pkt, size_t pktlen, NEPCo /* If the packet does not have application data, don't touch it */ if(offset==0){ - outPrint(DBG_3, "No payload found. Echoing the whole packet\n"); + nping_print(DBG_3, "No payload found. Echoing the whole packet\n"); h->setEchoedPacket(pkt, pktlen); /* If we found application data, zero it */ }else{ - outPrint(DBG_3, "Erasing %d payload bytes\n", (int)pktlen-offset); + nping_print(DBG_3, "Erasing %d payload bytes\n", (int)pktlen-offset); /* Allocate a new buffer, big enough to hold the packet */ u8 *new_pkt=(u8 *)safe_zalloc(pktlen); /* Copy the initial header, and leave the rest as 0x00 bytes */ @@ -1397,7 +1397,7 @@ int EchoServer::generate_echo(EchoHeader *h, const u8 *pkt, size_t pktlen, NEPCo /** This is the server's main method. It sets up nsock and pcap, waits for * client connections and handles all the events of the client sessions. */ int EchoServer::start() { - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); nsock_pool nsp; /**< Nsock pool */ enum nsock_loopstatus loopret; /**< Stores nsock_loop returned status */ nsock_iod client_nsi; /**< Stores connected client IOD */ @@ -1415,7 +1415,7 @@ int EchoServer::start() { /* Create a new nsock pool */ if ((nsp = nsp_new(NULL)) == NULL) - outFatal(QT_3, "Failed to create new pool. QUITTING.\n"); + nping_fatal(QT_3, "Failed to create new pool. QUITTING.\n"); /* Set nsock trace level */ gettimeofday(&now, NULL); @@ -1426,16 +1426,16 @@ int EchoServer::start() { /* Create new IOD for pcap */ if ((pcap_nsi = nsi_new(nsp, NULL)) == NULL) - outFatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n"); + nping_fatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n"); /* Open pcap */ - outPrint(DBG_2,"Opening pcap device %s", o.getDevice() ); + nping_print(DBG_2,"Opening pcap device %s", o.getDevice() ); Strncpy(pcapdev, o.getDevice(), sizeof(pcapdev)); if( (auxpnt=nsock_pcap_open(nsp, pcap_nsi, pcapdev, MAX_ECHOED_PACKET_LEN, 1, ProbeMode::getBPFFilterString() )) != NULL ) - outFatal(QT_3, "Error opening capture device %s --> %s\n", o.getDevice(), auxpnt); + nping_fatal(QT_3, "Error opening capture device %s --> %s\n", o.getDevice(), auxpnt); else - outPrint(VB_0,"Packet capture will be performed using network interface %s.", o.getDevice()); - outPrint(VB_0,"Waiting for connections..."); + nping_print(VB_0,"Packet capture will be performed using network interface %s.", o.getDevice()); + nping_print(VB_0,"Waiting for connections..."); /* Get a socket suitable for an accept() call */ listen_sd=this->nep_listen_socket(); @@ -1446,15 +1446,15 @@ int EchoServer::start() { /* Check if we have received a connection*/ unblock_socket(listen_sd); if ((client_sd=accept(listen_sd, (struct sockaddr *)&ss, &sslen)) >= 0){ - outPrint(VB_0, "[%lu] Connection received from %s:%d", (unsigned long)time(NULL), IPtoa(&ss), sockaddr2port(&ss)); + nping_print(VB_0, "[%lu] Connection received from %s:%d", (unsigned long)time(NULL), IPtoa(&ss), sockaddr2port(&ss)); /* Assign a new client identifier. The ID is bound to the IOD */ if( (idpnt=(clientid_t *)calloc(1, sizeof(clientid_t)))==NULL ){ - outError(QT_2, "Not enough memory for new clients."); + nping_warning(QT_2, "Not enough memory for new clients."); return OP_FAILURE; } *idpnt=this->getNewClientID(); if( (client_nsi=nsi_new2(nsp, client_sd, idpnt))==NULL ){ - outError(QT_2, "Not enough memory for new clients."); + nping_warning(QT_2, "Not enough memory for new clients."); return OP_FAILURE; }else{ close(client_sd); /* nsi_new2() dups the socket */ @@ -1471,7 +1471,7 @@ int EchoServer::start() { ctx.generateServerNonce(); ctx.generateInitialServerSequence(); ctx.generateMacKeyS2CInitial(); - outPrint(DBG_3,"Session Key MAC_S2C_INITIAL:"); print_hexdump(DBG_3,ctx.getMacKeyS2C(), MAC_KEY_LEN); + nping_print(DBG_3,"Session Key MAC_S2C_INITIAL:"); print_hexdump(DBG_3,ctx.getMacKeyS2C(), MAC_KEY_LEN); /* Craft NEP_HANDSHAKE_SERVER message */ if( this->generate_hs_server(&h, &ctx)!=OP_SUCCESS) @@ -1493,7 +1493,7 @@ int EchoServer::start() { loopret=nsock_loop(nsp, 1000); //If something went wrong in nsock_loop, let's just bail out. if (loopret == NSOCK_LOOP_ERROR) { - outError(QT_3, "Unexpected nsock_loop error.\n"); + nping_warning(QT_3, "Unexpected nsock_loop error.\n"); return OP_FAILURE; } } @@ -1515,7 +1515,7 @@ int EchoServer::cleanup(){ * need this because C++ does not allow to use class methods as callback * functions for things like signal() or the Nsock lib. */ void capture_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); es.nep_capture_handler(nsp, nse, arg); return; } /* End of capture_handler() */ @@ -1525,7 +1525,7 @@ void capture_handler(nsock_pool nsp, nsock_event nse, void *arg){ * need this because C++ does not allow to use class methods as callback * functions for things like signal() or the Nsock lib. */ void echo_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); es.nep_echo_handler(nsp, nse, arg); return; } /* End of echo_handler() */ @@ -1535,7 +1535,7 @@ void echo_handler(nsock_pool nsp, nsock_event nse, void *arg){ * need this because C++ does not allow to use class methods as callback * functions for things like signal() or the Nsock lib. */ void hs_server_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); es.nep_hs_server_handler(nsp, nse, arg); return; } /* End of hs_server_handler() */ @@ -1545,7 +1545,7 @@ void hs_server_handler(nsock_pool nsp, nsock_event nse, void *arg){ * need this because C++ does not allow to use class methods as callback * functions for things like signal() or the Nsock lib. */ void hs_client_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); es.nep_hs_client_handler(nsp, nse, arg); return; } /* End of hs_client_handler() */ @@ -1555,7 +1555,7 @@ void hs_client_handler(nsock_pool nsp, nsock_event nse, void *arg){ * need this because C++ does not allow to use class methods as callback * functions for things like signal() or the Nsock lib. */ void hs_final_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); es.nep_hs_final_handler(nsp, nse, arg); return; } /* End of hs_final_handler() */ @@ -1565,7 +1565,7 @@ void hs_final_handler(nsock_pool nsp, nsock_event nse, void *arg){ * need this because C++ does not allow to use class methods as callback * functions for things like signal() or the Nsock lib. */ void packetspec_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); es.nep_packetspec_handler(nsp, nse, arg); return; } /* End of packetspec_handler() */ @@ -1575,7 +1575,7 @@ void packetspec_handler(nsock_pool nsp, nsock_event nse, void *arg){ * need this because C++ does not allow to use class methods as callback * functions for things like signal() or the Nsock lib. */ void ready_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); es.nep_ready_handler(nsp, nse, arg); return; } /* End of ready_handler() */ @@ -1585,7 +1585,7 @@ void ready_handler(nsock_pool nsp, nsock_event nse, void *arg){ * need this because C++ does not allow to use class methods as callback * functions for things like signal() or the Nsock lib. */ void session_ended_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); es.nep_session_ended_handler(nsp, nse, arg); return; } /* End of ready_handler() */ diff --git a/nping/NpingOps.cc b/nping/NpingOps.cc index e2493bc1a..73a20e327 100644 --- a/nping/NpingOps.cc +++ b/nping/NpingOps.cc @@ -491,7 +491,7 @@ bool NpingOps::issetTraceroute(){ * @return OP_SUCCESS on success and OP_FAILURE in case of error. */ int NpingOps::setVerbosity(int level){ if( level < -4 || level > 4 ){ - outFatal(QT_3,"setVerbosity(): Invalid verbosity level supplied\n"); + nping_fatal(QT_3,"setVerbosity(): Invalid verbosity level supplied\n"); return OP_FAILURE; }else{ switch(level){ @@ -505,7 +505,7 @@ int NpingOps::setVerbosity(int level){ case 3: vb=VB_3; break; case 4: vb=VB_4; break; default: - outFatal(QT_3,"setVerbosity():2: Invalid verbosity level supplied\n"); + nping_fatal(QT_3,"setVerbosity():2: Invalid verbosity level supplied\n"); break; } } @@ -560,7 +560,7 @@ int NpingOps::decreaseVerbosity(){ * @return OP_SUCCESS on success and OP_FAILURE in case of error. */ int NpingOps::setDebugging(int level){ if( level < 0 || level > 9){ - outFatal(QT_3,"setDebugging(): Invalid debugging level supplied\n"); + nping_fatal(QT_3,"setDebugging(): Invalid debugging level supplied\n"); return OP_FAILURE; }else{ this->dbg= DBG_0 + level; @@ -659,7 +659,7 @@ int NpingOps::setSendPreference(int v){ v!=PACKET_SEND_ETH_STRONG && v!=PACKET_SEND_ETH && v!=PACKET_SEND_IP_WEAK && v!=PACKET_SEND_IP_STRONG && v!=PACKET_SEND_IP ){ - outFatal(QT_3,"setSendPreference(): Invalid value supplied\n"); + nping_fatal(QT_3,"setSendPreference(): Invalid value supplied\n"); return OP_FAILURE; }else{ sendpref=v; @@ -735,7 +735,7 @@ bool NpingOps::issetSendEth(){ * @return OP_SUCCESS on success and OP_FAILURE in case of error. */ int NpingOps::setHostTimeout(long t){ if( t < 0 ){ - outFatal(QT_3,"setHostTimeout(): Invalid time supplied\n"); + nping_fatal(QT_3,"setHostTimeout(): Invalid time supplied\n"); return OP_FAILURE; }else{ this->host_timeout=t; @@ -764,7 +764,7 @@ bool NpingOps::issetHostTimeout(){ * @return OP_SUCCESS on success and OP_FAILURE in case of error. */ int NpingOps::setDelay(long t){ if( t < 0 ) - outFatal(QT_3,"setDelay(): Invalid time supplied\n"); + nping_fatal(QT_3,"setDelay(): Invalid time supplied\n"); this->delay=t; this->delay_set=true; return OP_SUCCESS; @@ -788,7 +788,7 @@ bool NpingOps::issetDelay(){ * @return OP_SUCCESS on success and OP_FAILURE in case of error. */ int NpingOps::setDevice(char *n){ if( n==NULL ){ - outFatal(QT_3,"setDevice(): Invalid value supplied\n"); + nping_fatal(QT_3,"setDevice(): Invalid value supplied\n"); }else{ Strncpy(this->device, n, MAX_DEV_LEN-1); } @@ -904,7 +904,7 @@ bool NpingOps::issetDisablePacketCapture(){ * @return OP_SUCCESS on success and OP_FAILURE in case of error. */ int NpingOps::setIPVersion(u8 val){ if( val!=IP_VERSION_4 && val!=IP_VERSION_6 ){ - outFatal(QT_3,"setIPVersion(): Invalid value supplied\n"); + nping_fatal(QT_3,"setIPVersion(): Invalid value supplied\n"); return OP_FAILURE; }else{ this-> ipversion=val; @@ -1009,7 +1009,7 @@ bool NpingOps::issetIsRoot(){ * @return OP_SUCCESS on success and OP_FAILURE in case of error. */ int NpingOps::setPayloadType(int t){ if( t!=PL_RAND && t!=PL_HEX && t!=PL_FILE && t!=PL_STRING){ - outFatal(QT_3,"setPayloadType(): Invalid value supplied\n"); + nping_fatal(QT_3,"setPayloadType(): Invalid value supplied\n"); return OP_FAILURE; }else{ payload_type=t; @@ -1036,7 +1036,7 @@ bool NpingOps::issetPayloadType(){ * @return OP_SUCCESS on success and OP_FAILURE in case of error. */ int NpingOps::setPayloadBuffer(u8 *p, int len){ if( p==NULL || len < 0 ){ - outFatal(QT_3,"setPayloadBuffer(): Invalid value supplied\n"); + nping_fatal(QT_3,"setPayloadBuffer(): Invalid value supplied\n"); return OP_FAILURE; }else{ this->payload_buff=p; @@ -1074,7 +1074,7 @@ bool NpingOps::issetPayloadLen(){ int NpingOps::setPayloadFilename(char *name){ if( name==NULL ){ - outFatal(QT_3,"setPayloadFile(): Invalid value supplied\n"); + nping_fatal(QT_3,"setPayloadFile(): Invalid value supplied\n"); return OP_FAILURE; }else{ this->payload_file= strdup(name); @@ -1107,7 +1107,7 @@ bool NpingOps::issetPayloadFilename(){ int NpingOps::setRole(int r){ int prev = this->role; if (r!=ROLE_NORMAL && r!=ROLE_CLIENT && r!=ROLE_SERVER){ - outError(QT_2,"setRoleClient(): Invalid role supplied"); + nping_warning(QT_2,"setRoleClient(): Invalid role supplied"); return OP_FAILURE; } else @@ -1291,7 +1291,7 @@ bool NpingOps::issetDF(){ * @return OP_SUCCESS on success and OP_FAILURE in case of error. */ int NpingOps::setMTU(u32 t){ if(t==0 || (t%8)!=0){ - outFatal(QT_3,"setMTU(): Invalid mtu supplied\n"); + nping_fatal(QT_3,"setMTU(): Invalid mtu supplied\n"); }else{ this->mtu=t; this->mtu_set=true; @@ -1369,7 +1369,7 @@ bool NpingOps::issetIPv4SourceAddress(){ * be free()ed by the NpingOps destructor. */ int NpingOps::setIPOptions(char *txt){ if (txt==NULL) - outFatal(QT_3,"setIPOptions(): NULL pointer supplied\n"); + nping_fatal(QT_3,"setIPOptions(): NULL pointer supplied\n"); this->ip_options=strdup(txt) ; this->ip_options_set=true; return OP_SUCCESS; @@ -1434,7 +1434,7 @@ bool NpingOps::issetFlowLabel(){ int NpingOps::setIPv6SourceAddress(u8 *val){ if(val==NULL) - outFatal(QT_3,"setIPv6SourceAddress(): NULL pointer supplied\n"); + nping_fatal(QT_3,"setIPv6SourceAddress(): NULL pointer supplied\n"); memcpy(this->ipv6_src_address.s6_addr, val, 16); this->ipv6_src_address_set=true; return OP_SUCCESS; @@ -1499,7 +1499,7 @@ struct sockaddr_storage *NpingOps::getSourceSockAddr(struct sockaddr_storage *ss else s6->sin6_port=0; }else{ - outFatal(QT_3, "NpingOps::getSourceSockAddr(): IP version unset."); + nping_fatal(QT_3, "NpingOps::getSourceSockAddr(): IP version unset."); } return ss; } /* End of getSourceSockAddr() */ @@ -1523,7 +1523,7 @@ u16 *NpingOps::getTargetPorts( int *len ){ /** @warning ports in the supplied array must be in HOST byte order */ int NpingOps::setTargetPorts( u16 *pnt, int n ){ if(this->tportcount>65536 || this->tportcount<0) - outFatal(QT_3, "setTargetPorts():: Invalid number of ports supplied."); + nping_fatal(QT_3, "setTargetPorts():: Invalid number of ports supplied."); this->target_ports=pnt; this->tportcount=n; this->target_ports_set=true; @@ -1609,7 +1609,7 @@ bool NpingOps::issetTCPAck(){ int NpingOps::setFlagTCP(int flag){ if (flag < FLAG_CWR || flag > FLAG_FIN) - outFatal(QT_3,"setFlagTCP(): Invalid flag supplied\n"); + nping_fatal(QT_3,"setFlagTCP(): Invalid flag supplied\n"); else this->tcpflags[flag]=1; this->tcpflags_set=true; @@ -1635,7 +1635,7 @@ int NpingOps::unsetAllFlagsTCP(){ int NpingOps::getFlagTCP(int flag){ if (flag < FLAG_CWR || flag > FLAG_FIN) - outFatal(QT_3,"setFlagTCP(): Invalid flag supplied\n"); + nping_fatal(QT_3,"setFlagTCP(): Invalid flag supplied\n"); return this->tcpflags[flag]; } /* End of getFlagTCP() */ @@ -1987,9 +1987,9 @@ int NpingOps::addICMPAdvertEntry(struct in_addr addr, u32 pref ){ * 0 <= num < getICMPAdvertEntryCount() */ int NpingOps::getICMPAdvertEntry(int num, struct in_addr *addr, u32 *pref){ if( num<0 || num>=icmp_advert_entry_count ) - outFatal(QT_3,"getICMPAdvertEntry(): Supplied index is out of bounds.\n"); + nping_fatal(QT_3,"getICMPAdvertEntry(): Supplied index is out of bounds.\n"); if( addr==NULL || pref==NULL) - outFatal(QT_3,"getICMPAdvertEntry(): NULL pointer supplied\n"); + nping_fatal(QT_3,"getICMPAdvertEntry(): NULL pointer supplied\n"); *addr = this->icmp_advert_entry_addr[num]; *pref = this->icmp_advert_entry_pref[num]; return OP_SUCCESS; @@ -2346,9 +2346,9 @@ if( !this->issetIsRoot() ){ if (this->havePcap()==false){ #ifdef WIN32 - outFatal(QT_3, "Nping requires %s", privreq); + nping_fatal(QT_3, "Nping requires %s", privreq); #else - outFatal(QT_3, "Nping requires libpcap to be installed on your system."); + nping_fatal(QT_3, "Nping requires libpcap to be installed on your system."); #endif } @@ -2363,10 +2363,10 @@ if (this->havePcap()==false){ /* Check if user entered at least one target spec */ if( this->getRole() == ROLE_NORMAL ){ if ( this->targets.getTargetSpecCount() <= 0 ) - outFatal(QT_3,"WARNING: No targets were specified, so 0 hosts pinged."); + nping_fatal(QT_3,"WARNING: No targets were specified, so 0 hosts pinged."); }else if( this->getRole() == ROLE_CLIENT ){ if ( this->targets.getTargetSpecCount() <= 0 ) - outFatal(QT_3,"No echo server was specified."); + nping_fatal(QT_3,"No echo server was specified."); } /** IP VERSION ***************************************************************/ @@ -2411,11 +2411,11 @@ if (this->havePcap()==false){ /** CHECK PRIVILEGES FOR CURRENT ROLE ****************************************/ if( !this->isRoot() && (this->getRole()==ROLE_SERVER || this->getRole()==ROLE_CLIENT) ) - outFatal(QT_3,"Echo mode requires %s.", privreq); + nping_fatal(QT_3,"Echo mode requires %s.", privreq); /** CHECK PRIVILEGES FOR CURRENT MODE ****************************************/ if( !this->isRoot() && this->getMode()!=UDP_UNPRIV && this->getMode()!=TCP_CONNECT ) - outFatal(QT_3,"Mode %s requires %s.", this->mode2Ascii( this->getMode() ), privreq); + nping_fatal(QT_3,"Mode %s requires %s.", this->mode2Ascii( this->getMode() ), privreq); /** DEFAULT HEADER PARAMETERS *************************************************/ @@ -2423,13 +2423,13 @@ if (this->havePcap()==false){ /** ARP MODE RELATED PARAMETERS *********************************************/ if(this->getMode()==ARP && this->ipv6()) { - outFatal(QT_3, "Sorry, ARP does not support IPv6 and Nping does not yet support NDP."); + nping_fatal(QT_3, "Sorry, ARP does not support IPv6 and Nping does not yet support NDP."); } /** TCP CONNECT RELATED PARAMETERS *********************************************/ if(this->getMode()==TCP_CONNECT) { if(this->issetPayloadBuffer() || this->issetPayloadFilename()) - outPrint(VB_0, "Warning: Payload supplied in TCP Connect mode. Payload will be ignored."); + nping_print(VB_0, "Warning: Payload supplied in TCP Connect mode. Payload will be ignored."); } /** SOURCE IP, SOURCE MAC and NETWORK DEVICE *********************************/ @@ -2467,7 +2467,7 @@ if( this->getMode()!=TCP_CONNECT && this->getMode()!=UDP_UNPRIV && this->getRole if( this->targets.getNextTargetAddressAndName(&ss, &ss_len, hostname, sizeof(hostname)) == OP_SUCCESS ) break; else if( z>=(this->targets.getTargetSpecCount()-1) ) - outFatal(QT_3,"Cannot find a valid target. Please make sure the specified hosts are either IP addresses in standard notation or hostnames that can be resolved with DNS"); + nping_fatal(QT_3,"Cannot find a valid target. Please make sure the specified hosts are either IP addresses in standard notation or hostnames that can be resolved with DNS"); } this->targets.rewind(); @@ -2476,15 +2476,15 @@ if( this->getMode()!=TCP_CONNECT && this->getMode()!=UDP_UNPRIV && this->getRole /* If that didn't work, ask libpcap */ char errbuf[PCAP_ERRBUF_SIZE]; if ( (dev = pcap_lookupdev(errbuf)) == NULL) - outFatal(QT_3, "Cannot obtain device for packet capture --> %s", errbuf); + nping_fatal(QT_3, "Cannot obtain device for packet capture --> %s", errbuf); else this->setDevice( dev ); /* Libpcap gave us a device name, try to obtain it's IP */ if ( devname2ipaddr_alt(this->getDevice(), &ifaddr) != 0 ){ if( this->isRoot() ) - outFatal(QT_3,"Cannot figure out what source address to use for device %s, does it even exist?", this->getDevice()); + nping_fatal(QT_3,"Cannot figure out what source address to use for device %s, does it even exist?", this->getDevice()); else - outFatal(QT_3,"Cannot figure out what source address to use for device %s, are you root?", this->getDevice()); + nping_fatal(QT_3,"Cannot figure out what source address to use for device %s, are you root?", this->getDevice()); } else{ if( s4->sin_family==AF_INET ) @@ -2498,23 +2498,23 @@ if( this->getMode()!=TCP_CONNECT && this->getMode()!=UDP_UNPRIV && this->getRole }else{ /* In IPv6 we just select one in libpcap and hope is the right one */ char *selected_iface=this->select_network_iface(); if(selected_iface==NULL) - outFatal(QT_3, "Error trying to find a suitable network interface "); + nping_fatal(QT_3, "Error trying to find a suitable network interface "); else this->setDevice( selected_iface ); } } /* CASE 2: User did actually supply a device name */ else{ - outPrint(DBG_2, "Using network interface \"%s\"", this->getDevice() ); + nping_print(DBG_2, "Using network interface \"%s\"", this->getDevice() ); } /* The echo server needs to find out a network interface*/ }else if (this->getRole()==ROLE_SERVER && this->issetDevice()==false){ char *selected_iface=this->select_network_iface(); if(selected_iface==NULL) - outFatal(QT_3, "Error trying to find a suitable network interface "); + nping_fatal(QT_3, "Error trying to find a suitable network interface "); else this->setDevice( selected_iface ); - outPrint(DBG_2, "Using network interface \"%s\"", this->getDevice() ); + nping_print(DBG_2, "Using network interface \"%s\"", this->getDevice() ); } /** RAW IP AND RAW ETHERNET TRANSMISSION MODES *******************************/ @@ -2549,7 +2549,7 @@ if(this->getRole()!=ROLE_SERVER){ this->setSendEth(true); this->setSendPreference( PACKET_SEND_ETH_STRONG ); }else{ - outFatal(QT_3, "If you want to control some of the fields" + nping_fatal(QT_3, "If you want to control some of the fields" " in the IPv6 header you also have to supply source and" " destination MAC address. However, you can always" " choose to let the kernel create the IPv6 header" @@ -2579,7 +2579,7 @@ if(this->getRole()!=ROLE_SERVER){ if( this->getMode()==ARP && !this->sendPreferenceEthernet() ){ this->setSendEth(true); - outError(QT_2, "Warning: ARP mode requieres raw ethernet frame transmission. Specified preference will be ignored."); + nping_warning(QT_2, "Warning: ARP mode requieres raw ethernet frame transmission. Specified preference will be ignored."); } else if( this->ipv6() ){ @@ -2591,7 +2591,7 @@ if(this->getRole()!=ROLE_SERVER){ /* CASE 2: User requested Ethernet but did not really supplied all * the information we need */ }else if( this->sendPreferenceEthernet() && !this->canDoIPv6Ethernet() ){ - outFatal(QT_3, "You requested raw ethernet level transmission and IPv6." + nping_fatal(QT_3, "You requested raw ethernet level transmission and IPv6." " In this case, you need to supply source MAC address," " destination MAC address and IPv6 source address."); @@ -2603,7 +2603,7 @@ if(this->getRole()!=ROLE_SERVER){ /* CASE 4: User requested raw IP transmission but also wanted to * set custom IPv6 header field values. */ }else if (this->sendPreferenceIP() && !this->canDoIPv6ThroughSocket()){ - outFatal(QT_3, "You requested raw IP transmission mode for IPv6." + nping_fatal(QT_3, "You requested raw IP transmission mode for IPv6." " Nping does not currently allow IPv6 header manipulation" " when sending packets at raw IP level due to the limitations" " on raw IPv6 sockets, imposed by RFC 2292. Please" @@ -2619,9 +2619,9 @@ if(this->getRole()!=ROLE_SERVER){ } } if( this->getMode()==TCP_CONNECT || this->getMode()==UDP_UNPRIV ) - outPrint(DBG_2,"Nping will send packets in unprivileged mode using regular system calls"); + nping_print(DBG_2,"Nping will send packets in unprivileged mode using regular system calls"); else - outPrint(DBG_2,"Nping will send packets at %s", this->sendEth() ? "raw ethernet level" : "raw IP level" ); + nping_print(DBG_2,"Nping will send packets at %s", this->sendEth() ? "raw ethernet level" : "raw IP level" ); } /** ECHO MODE ************************************************************/ @@ -2635,9 +2635,9 @@ if(this->getRole()!=ROLE_SERVER){ if(this->getMode()==TCP){ for(int i=0; itarget_ports[i]==this->getEchoPort()) - outFatal(QT_3, "Packets can't be sent to the same port that is used to connect to the echo server (%d)", this->getEchoPort()); + nping_fatal(QT_3, "Packets can't be sent to the same port that is used to connect to the echo server (%d)", this->getEchoPort()); else if(this->getSourcePort()==this->getEchoPort()) - outFatal(QT_3, "Packets can't be sent from the same port that is used to connect to the echo server (%d)", this->getEchoPort()); + nping_fatal(QT_3, "Packets can't be sent from the same port that is used to connect to the echo server (%d)", this->getEchoPort()); } } @@ -2649,14 +2649,14 @@ if(this->getRole()!=ROLE_SERVER){ break; default: - outFatal(QT_3, "The echo client can't be run with protocols other than TCP, UDP or ICMP."); + nping_fatal(QT_3, "The echo client can't be run with protocols other than TCP, UDP or ICMP."); break; } } #ifndef HAVE_OPENSSL if(this->getRole()==ROLE_CLIENT || this->getRole()==ROLE_SERVER ){ if( this->doCrypto()==true ){ - outFatal(QT_3, "Nping was compiled without OpenSSL so authentications need to be transmitted as cleartext. If you wish to continue, please specify --no-crypto."); + nping_fatal(QT_3, "Nping was compiled without OpenSSL so authentications need to be transmitted as cleartext. If you wish to continue, please specify --no-crypto."); } } #endif @@ -2785,13 +2785,13 @@ bool NpingOps::canDoIPv6Ethernet(){ void NpingOps::displayNpingDoneMsg(){ if( this->getRole()==ROLE_SERVER ){ - outPrint(QT_1, "Nping done: %lu %s served in %.2f seconds", + nping_print(QT_1, "Nping done: %lu %s served in %.2f seconds", (unsigned long)this->stats.getEchoClientsServed(), (this->stats.getEchoClientsServed() == 1)? "client" : "clients", this->stats.elapsedRuntime() ); }else{ - outPrint(QT_1, "Nping done: %lu %s pinged in %.2f seconds", + nping_print(QT_1, "Nping done: %lu %s pinged in %.2f seconds", this->targets.getTargetsFetched(), (this->targets.getTargetsFetched() == 1)? "IP address" : "IP addresses", this->stats.elapsedRuntime() @@ -2807,7 +2807,7 @@ void NpingOps::displayStatistics(){ NpingTarget *target=NULL; this->targets.rewind(); - outPrint(VB_0," "); /* Print newline */ + nping_print(VB_0," "); /* Print newline */ /* Per-target statistics */ if( this->targets.getTargetsFetched() > 1){ @@ -2822,87 +2822,87 @@ void NpingOps::displayStatistics(){ #ifdef WIN32 /* Sent/Recv/Echoed Packets */ if(this->getRole()==ROLE_CLIENT){ - outPrint(QT_1|NO_NEWLINE, "Raw packets sent: %I64u ", this->stats.getSentPackets() ); - outPrint(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getSentBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Rcvd: %I64u ", this->stats.getRecvPackets() ); - outPrint(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Lost: %I64u ", this->stats.getLostPackets() ); - outPrint(QT_1|NO_NEWLINE,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); - outPrint(QT_1|NO_NEWLINE,"| Echoed: %I64u ", this->stats.getEchoedPackets() ); - outPrint(QT_1,"(%s) ", format_bytecount(this->stats.getEchoedBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE, "Raw packets sent: %I64u ", this->stats.getSentPackets() ); + nping_print(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getSentBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Rcvd: %I64u ", this->stats.getRecvPackets() ); + nping_print(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Lost: %I64u ", this->stats.getLostPackets() ); + nping_print(QT_1|NO_NEWLINE,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); + nping_print(QT_1|NO_NEWLINE,"| Echoed: %I64u ", this->stats.getEchoedPackets() ); + nping_print(QT_1,"(%s) ", format_bytecount(this->stats.getEchoedBytes(), auxbuff, 256)); }else if(this->getRole()==ROLE_SERVER){ - outPrint(QT_1|NO_NEWLINE, "Raw packets captured: %I64u ", this->stats.getRecvPackets() ); - outPrint(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Echoed: %I64u ", this->stats.getEchoedPackets() ); - outPrint(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getEchoedBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Not Matched: %I64u ", this->stats.getUnmatchedPackets() ); - outPrint(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes()-this->stats.getEchoedBytes(), auxbuff, 256)); - outPrint(QT_1,"(%.2lf%%)", this->stats.getUnmatchedPacketPercentage100() ); + nping_print(QT_1|NO_NEWLINE, "Raw packets captured: %I64u ", this->stats.getRecvPackets() ); + nping_print(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Echoed: %I64u ", this->stats.getEchoedPackets() ); + nping_print(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getEchoedBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Not Matched: %I64u ", this->stats.getUnmatchedPackets() ); + nping_print(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes()-this->stats.getEchoedBytes(), auxbuff, 256)); + nping_print(QT_1,"(%.2lf%%)", this->stats.getUnmatchedPacketPercentage100() ); }else if(this->getMode()==TCP_CONNECT){ - outPrint(QT_1|NO_NEWLINE, "TCP connection attempts: %I64u ", this->stats.getSentPackets() ); - outPrint(QT_1|NO_NEWLINE,"| Successful connections: %I64u ", this->stats.getRecvPackets() ); - outPrint(QT_1|NO_NEWLINE,"| Failed: %I64u ", this->stats.getLostPackets() ); - outPrint(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); + nping_print(QT_1|NO_NEWLINE, "TCP connection attempts: %I64u ", this->stats.getSentPackets() ); + nping_print(QT_1|NO_NEWLINE,"| Successful connections: %I64u ", this->stats.getRecvPackets() ); + nping_print(QT_1|NO_NEWLINE,"| Failed: %I64u ", this->stats.getLostPackets() ); + nping_print(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); } else if (this->getMode()==UDP_UNPRIV){ - outPrint(QT_1|NO_NEWLINE, "UDP packets sent: %I64u ", this->stats.getSentPackets() ); - outPrint(QT_1|NO_NEWLINE,"| Rcvd: %I64u ", this->stats.getRecvPackets() ); - outPrint(QT_1|NO_NEWLINE,"| Lost: %I64u ", this->stats.getLostPackets() ); - outPrint(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); + nping_print(QT_1|NO_NEWLINE, "UDP packets sent: %I64u ", this->stats.getSentPackets() ); + nping_print(QT_1|NO_NEWLINE,"| Rcvd: %I64u ", this->stats.getRecvPackets() ); + nping_print(QT_1|NO_NEWLINE,"| Lost: %I64u ", this->stats.getLostPackets() ); + nping_print(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); } else{ - outPrint(QT_1|NO_NEWLINE, "Raw packets sent: %I64u ", this->stats.getSentPackets() ); - outPrint(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getSentBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Rcvd: %I64u ", this->stats.getRecvPackets() ); - outPrint(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Lost: %I64u ", this->stats.getLostPackets() ); - outPrint(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); + nping_print(QT_1|NO_NEWLINE, "Raw packets sent: %I64u ", this->stats.getSentPackets() ); + nping_print(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getSentBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Rcvd: %I64u ", this->stats.getRecvPackets() ); + nping_print(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Lost: %I64u ", this->stats.getLostPackets() ); + nping_print(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); } #else /* Sent/Recv/Echoed Packets */ if(this->getRole()==ROLE_CLIENT){ - outPrint(QT_1|NO_NEWLINE, "Raw packets sent: %llu ", this->stats.getSentPackets() ); - outPrint(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getSentBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Rcvd: %llu ", this->stats.getRecvPackets() ); - outPrint(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Lost: %llu ", this->stats.getLostPackets() ); - outPrint(QT_1|NO_NEWLINE,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); - outPrint(QT_1|NO_NEWLINE,"| Echoed: %llu ", this->stats.getEchoedPackets() ); - outPrint(QT_1,"(%s) ", format_bytecount(this->stats.getEchoedBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE, "Raw packets sent: %llu ", this->stats.getSentPackets() ); + nping_print(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getSentBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Rcvd: %llu ", this->stats.getRecvPackets() ); + nping_print(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Lost: %llu ", this->stats.getLostPackets() ); + nping_print(QT_1|NO_NEWLINE,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); + nping_print(QT_1|NO_NEWLINE,"| Echoed: %llu ", this->stats.getEchoedPackets() ); + nping_print(QT_1,"(%s) ", format_bytecount(this->stats.getEchoedBytes(), auxbuff, 256)); }else if(this->getRole()==ROLE_SERVER){ - outPrint(QT_1|NO_NEWLINE, "Raw packets captured: %llu ", this->stats.getRecvPackets() ); - outPrint(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Echoed: %llu ", this->stats.getEchoedPackets() ); - outPrint(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getEchoedBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Not Matched: %llu ", this->stats.getUnmatchedPackets() ); - outPrint(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes()-this->stats.getEchoedBytes(), auxbuff, 256)); - outPrint(QT_1,"(%.2lf%%)", this->stats.getUnmatchedPacketPercentage100() ); + nping_print(QT_1|NO_NEWLINE, "Raw packets captured: %llu ", this->stats.getRecvPackets() ); + nping_print(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Echoed: %llu ", this->stats.getEchoedPackets() ); + nping_print(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getEchoedBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Not Matched: %llu ", this->stats.getUnmatchedPackets() ); + nping_print(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes()-this->stats.getEchoedBytes(), auxbuff, 256)); + nping_print(QT_1,"(%.2lf%%)", this->stats.getUnmatchedPacketPercentage100() ); }else if(this->getMode()==TCP_CONNECT){ - outPrint(QT_1|NO_NEWLINE, "TCP connection attempts: %llu ", this->stats.getSentPackets() ); - outPrint(QT_1|NO_NEWLINE,"| Successful connections: %llu ", this->stats.getRecvPackets() ); - outPrint(QT_1|NO_NEWLINE,"| Failed: %llu ", this->stats.getLostPackets() ); - outPrint(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); + nping_print(QT_1|NO_NEWLINE, "TCP connection attempts: %llu ", this->stats.getSentPackets() ); + nping_print(QT_1|NO_NEWLINE,"| Successful connections: %llu ", this->stats.getRecvPackets() ); + nping_print(QT_1|NO_NEWLINE,"| Failed: %llu ", this->stats.getLostPackets() ); + nping_print(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); } else if (this->getMode()==UDP_UNPRIV){ - outPrint(QT_1|NO_NEWLINE, "UDP packets sent: %llu ", this->stats.getSentPackets() ); - outPrint(QT_1|NO_NEWLINE,"| Rcvd: %llu ", this->stats.getRecvPackets() ); - outPrint(QT_1|NO_NEWLINE,"| Lost: %llu ", this->stats.getLostPackets() ); - outPrint(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); + nping_print(QT_1|NO_NEWLINE, "UDP packets sent: %llu ", this->stats.getSentPackets() ); + nping_print(QT_1|NO_NEWLINE,"| Rcvd: %llu ", this->stats.getRecvPackets() ); + nping_print(QT_1|NO_NEWLINE,"| Lost: %llu ", this->stats.getLostPackets() ); + nping_print(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); } else{ - outPrint(QT_1|NO_NEWLINE, "Raw packets sent: %llu ", this->stats.getSentPackets() ); - outPrint(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getSentBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Rcvd: %llu ", this->stats.getRecvPackets() ); - outPrint(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); - outPrint(QT_1|NO_NEWLINE,"| Lost: %llu ", this->stats.getLostPackets() ); - outPrint(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); + nping_print(QT_1|NO_NEWLINE, "Raw packets sent: %llu ", this->stats.getSentPackets() ); + nping_print(QT_1|NO_NEWLINE, "(%s) ", format_bytecount(this->stats.getSentBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Rcvd: %llu ", this->stats.getRecvPackets() ); + nping_print(QT_1|NO_NEWLINE,"(%s) ", format_bytecount(this->stats.getRecvBytes(), auxbuff, 256)); + nping_print(QT_1|NO_NEWLINE,"| Lost: %llu ", this->stats.getLostPackets() ); + nping_print(QT_1,"(%.2lf%%)", this->stats.getLostPacketPercentage100() ); } #endif /* Transmission times & rates */ - outPrint(VB_1|NO_NEWLINE,"Tx time: %.5lfs ", this->stats.elapsedTx() ); - outPrint(VB_1|NO_NEWLINE,"| Tx bytes/s: %.2lf ", this->stats.getOverallTxByteRate() ); - outPrint(VB_1,"| Tx pkts/s: %.2lf", this->stats.getOverallTxPacketRate() ); + nping_print(VB_1|NO_NEWLINE,"Tx time: %.5lfs ", this->stats.elapsedTx() ); + nping_print(VB_1|NO_NEWLINE,"| Tx bytes/s: %.2lf ", this->stats.getOverallTxByteRate() ); + nping_print(VB_1,"| Tx pkts/s: %.2lf", this->stats.getOverallTxPacketRate() ); + nping_print(VB_1|NO_NEWLINE,"Rx time: %.5lfs ", this->stats.elapsedRx() ); + nping_print(VB_1|NO_NEWLINE,"| Rx bytes/s: %.2lf ", this->stats.getOverallRxByteRate() ); + nping_print(VB_1,"| Rx pkts/s: %.2lf", this->stats.getOverallRxPacketRate() ); - outPrint(VB_1|NO_NEWLINE,"Rx time: %.5lfs ", this->stats.elapsedRx() ); - outPrint(VB_1|NO_NEWLINE,"| Rx bytes/s: %.2lf ", this->stats.getOverallRxByteRate() ); - outPrint(VB_1,"| Rx pkts/s: %.2lf", this->stats.getOverallRxPacketRate() ); } /* End of displayStatistics() */ @@ -2938,7 +2938,7 @@ char *NpingOps::select_network_iface(){ /* Ask libpcap for a list of network interfaces */ if( pcap_findalldevs(&pcap_ifaces, errbuf) != 0 ) - outFatal(QT_3, "Cannot obtain device for packet capture --> %s. You may want to specify one explicitly using option -e", errbuf); + nping_fatal(QT_3, "Cannot obtain device for packet capture --> %s. You may want to specify one explicitly using option -e", errbuf); /* Iterate over the interface list and select the best one */ for(curr=pcap_ifaces; curr!=NULL; curr=curr->next){ @@ -3241,7 +3241,7 @@ Initialization for NpingOps::NpingOps() * @return OP_SUCCESS on success and OP_FAILURE in case of error. */ /*int NpingOps::setMETHNAME(TYPE val){ if( 0 ){ - outFatal(QT_3,"setMETHNAME(): Invalid value supplied\n"); + nping_fatal(QT_3,"setMETHNAME(): Invalid value supplied\n"); return OP_FAILURE; }else{ ATTRNAME=val; diff --git a/nping/NpingTarget.cc b/nping/NpingTarget.cc index 6a37a5bc4..50a09c3be 100644 --- a/nping/NpingTarget.cc +++ b/nping/NpingTarget.cc @@ -544,7 +544,7 @@ void NpingTarget::setResolvedHostName(char *name) { // I think only a-z A-Z 0-9 . and - are allowed, but I'll be a little more // generous. if (!isalnum(*p) && !strchr(".-+=:_~*", *p)) { - outError(QT_2, "Illegal character(s) in hostname -- replacing with '*'\n"); + nping_warning(QT_2, "Illegal character(s) in hostname -- replacing with '*'\n"); *p = '*'; } p++; @@ -606,10 +606,10 @@ void NpingTarget::generateIPString() { }else if(sin->sin_family == AF_INET6){ ret=inet_ntop(AF_INET6, (char *) &sin6->sin6_addr, targetipstring, sizeof(targetipstring)); }else{ - outFatal(QT_3, "NpingTarget::GenerateIPString(): Unsupported address family"); + nping_fatal(QT_3, "NpingTarget::GenerateIPString(): Unsupported address family"); } if( ret==NULL ) - outFatal(QT_3, "NpingTarget::GenerateIPString(): Unsupported address family"); + nping_fatal(QT_3, "NpingTarget::GenerateIPString(): Unsupported address family"); targetipstring_set=true; } /* End of generateIPString() */ @@ -627,7 +627,7 @@ const char *NpingTarget::getSourceIPStr() { }else if(sin->sin_family == AF_INET6){ ret=inet_ntop(AF_INET6, (char *) &sin6->sin6_addr, buffer, sizeof(buffer)); }else{ - outFatal(QT_3, "NpingTarget::getSourceIPString(): Unsupported address family"); + nping_fatal(QT_3, "NpingTarget::getSourceIPString(): Unsupported address family"); } if(ret==NULL) return NULL; @@ -651,7 +651,7 @@ const char *NpingTarget::getSpoofedSourceIPStr() { }else if(sin->sin_family == AF_INET6){ ret=inet_ntop(AF_INET6, (char *) &sin6->sin6_addr, buffer, sizeof(buffer)); }else{ - outFatal(QT_3, "NpingTarget::getSourceIPString(): Unsupported address family"); + nping_fatal(QT_3, "NpingTarget::getSourceIPString(): Unsupported address family"); } if(ret==NULL) return NULL; @@ -670,7 +670,7 @@ const char *NpingTarget::getNextHopIPStr(){ }else if(sin->sin_family == AF_INET6){ ret=inet_ntop(AF_INET6, (char *) &sin6->sin6_addr, buffer, sizeof(buffer)); }else{ - outFatal(QT_3, "NpingTarget::getNextHopIPStr(): Unsupported address family"); + nping_fatal(QT_3, "NpingTarget::getNextHopIPStr(): Unsupported address family"); } if(ret==NULL) return NULL; @@ -773,7 +773,7 @@ bool NpingTarget::determineNextHopMACAddress() { if ( this->getNextHopMACAddress() ) return true; - outPrint(DBG_2,"Determining target %s MAC address or next hop MAC address...", this->getTargetIPstr() ); + nping_print(DBG_2,"Determining target %s MAC address or next hop MAC address...", this->getTargetIPstr() ); /* For connected machines, it is the same as the target addy */ if (this->isDirectlyConnected() && this->getMACAddress() ) { this->setNextHopMACAddress(this->getMACAddress()); @@ -794,45 +794,45 @@ bool NpingTarget::determineNextHopMACAddress() { } /* Maybe the system ARP cache will be more helpful */ - outPrint(DBG_3," > Checking system's ARP cache..."); + nping_print(DBG_3," > Checking system's ARP cache..."); a = arp_open(); addr_ston((sockaddr *)&targetss, &ae.arp_pa); if (arp_get(a, &ae) == 0) { mac_cache_set(&targetss, ae.arp_ha.addr_eth.data); this->setNextHopMACAddress(ae.arp_ha.addr_eth.data); arp_close(a); - outPrint(DBG_3," > Success: Entry found [%s]", this->getNextHopMACStr() ); + nping_print(DBG_3," > Success: Entry found [%s]", this->getNextHopMACStr() ); return true; } arp_close(a); - outPrint(DBG_3," > No relevant entries found in system's ARP cache."); + nping_print(DBG_3," > No relevant entries found in system's ARP cache."); /* OK, the last choice is to send our own damn ARP request (and retransmissions if necessary) to determine the MAC */ /* We first try sending the ARP with our spoofed IP address on it */ if( this->spoofingSourceAddress() ){ - outPrint(DBG_3," > Sending ARP request using spoofed IP %s...", this->getSpoofedSourceIPStr() ); + nping_print(DBG_3," > Sending ARP request using spoofed IP %s...", this->getSpoofedSourceIPStr() ); this->getSpoofedSourceSockAddr(&srcss, NULL); if (doArp(this->getDeviceName(), this->getSrcMACAddress(), &srcss, &targetss, mac, NULL)) { mac_cache_set(&targetss, mac); this->setNextHopMACAddress(mac); - outPrint(DBG_4," > Success: 1 ARP response received [%s]", this->getNextHopMACStr() ); + nping_print(DBG_4," > Success: 1 ARP response received [%s]", this->getNextHopMACStr() ); return true; } } - outPrint(DBG_3," > No ARP responses received." ); + nping_print(DBG_3," > No ARP responses received." ); /* If our spoofed IP address didn't work, try our real IP */ - outPrint(DBG_4," > Sending ARP request using our real IP %s...", this->getSourceIPStr() ); + nping_print(DBG_4," > Sending ARP request using our real IP %s...", this->getSourceIPStr() ); this->getSourceSockAddr(&srcss, NULL); if (doArp(this->getDeviceName(), this->getSrcMACAddress(), &srcss, &targetss, mac, NULL)) { mac_cache_set(&targetss, mac); this->setNextHopMACAddress(mac); - outPrint(DBG_3," > Success: 1 ARP response received [%s]", this->getNextHopMACStr() ); + nping_print(DBG_3," > Success: 1 ARP response received [%s]", this->getNextHopMACStr() ); return true; } - outPrint(DBG_3," > No ARP responses received" ); + nping_print(DBG_3," > No ARP responses received" ); /* I'm afraid that we couldn't find it! Maybe it doesn't exist?*/ return false; @@ -1025,10 +1025,10 @@ int NpingTarget::updateRTTs(unsigned long int diff){ int NpingTarget::printStats(){ - outPrint(VB_0, "Statistics for host %s:", this->getNameAndIP()); - outPrint(VB_0|NO_NEWLINE," | "); + nping_print(VB_0, "Statistics for host %s:", this->getNameAndIP()); + nping_print(VB_0|NO_NEWLINE," | "); this->printCounts(); - outPrint(VB_0|NO_NEWLINE," |_ "); + nping_print(VB_0|NO_NEWLINE," |_ "); this->printRTTs(); return OP_SUCCESS; } /* End of printStats() */ @@ -1039,11 +1039,11 @@ void NpingTarget::printCounts(){ unsigned long int lost = this->sent_total - this->recv_total; /* Sent Packets */ - outPrint(VB_0|NO_NEWLINE, "Probes Sent: %ld ", this->sent_total); + nping_print(VB_0|NO_NEWLINE, "Probes Sent: %ld ", this->sent_total); /* Received Packets */ - outPrint(VB_0|NO_NEWLINE,"| Rcvd: %ld ", this->recv_total ); + nping_print(VB_0|NO_NEWLINE,"| Rcvd: %ld ", this->recv_total ); /* Lost Packets */ - outPrint(VB_0|NO_NEWLINE,"| Lost: %ld ", lost ); + nping_print(VB_0|NO_NEWLINE,"| Lost: %ld ", lost ); /* Only compute percentage if we actually sent packets, don't do divisions * by zero! (this could happen when user presses CTRL-C and we print the @@ -1051,24 +1051,24 @@ void NpingTarget::printCounts(){ float percentlost=0.0; if( lost!=0 && this->sent_total!=0) percentlost=((double)lost)/((double)this->sent_total) * 100; - outPrint(VB_0," (%.2lf%%)", percentlost); + nping_print(VB_0," (%.2lf%%)", percentlost); } /* End of printCounts() */ /* Print round trip times */ void NpingTarget::printRTTs(){ if( max_rtt_set ) - outPrint(QT_1|NO_NEWLINE,"Max rtt: %.3lfms ", this->max_rtt/1000.0 ); + nping_print(QT_1|NO_NEWLINE,"Max rtt: %.3lfms ", this->max_rtt/1000.0 ); else - outPrint(QT_1|NO_NEWLINE,"Max rtt: N/A "); + nping_print(QT_1|NO_NEWLINE,"Max rtt: N/A "); if( min_rtt_set ) - outPrint(QT_1|NO_NEWLINE,"| Min rtt: %.3lfms ", this->min_rtt/1000.0 ); + nping_print(QT_1|NO_NEWLINE,"| Min rtt: %.3lfms ", this->min_rtt/1000.0 ); else - outPrint(QT_1|NO_NEWLINE,"| Min rtt: N/A " ); + nping_print(QT_1|NO_NEWLINE,"| Min rtt: N/A " ); if( avg_rtt_set) - outPrint(QT_1,"| Avg rtt: %.3lfms", this->avg_rtt/1000.0 ); + nping_print(QT_1,"| Avg rtt: %.3lfms", this->avg_rtt/1000.0 ); else - outPrint(QT_1,"| Avg rtt: N/A" ); + nping_print(QT_1,"| Avg rtt: N/A" ); } /* End of printRTTs() */ diff --git a/nping/NpingTargets.cc b/nping/NpingTargets.cc index 7e69cf0fd..fbcd504f0 100644 --- a/nping/NpingTargets.cc +++ b/nping/NpingTargets.cc @@ -139,7 +139,7 @@ int NpingTargets::getNextTargetAddressAndName(struct sockaddr_storage *t, size_t int family= (o.getIPVersion()==IP_VERSION_6) ? AF_INET6 : AF_INET; if( t==NULL || tlen==NULL ) - outFatal(QT_3,"getNextTarget(): NULL values supplied."); + nping_fatal(QT_3,"getNextTarget(): NULL values supplied."); /* Return failure if there are no specs or we noticed that we were finished in * a previous call. */ @@ -185,7 +185,7 @@ int NpingTargets::getNextTargetAddressAndName(struct sockaddr_storage *t, size_t r=current_group.get_next_host(&next, &nextlen); if (r != 0) - outFatal(QT_3,"BUG: TargetGroups are supposed to contain at least one IP! "); + nping_fatal(QT_3,"BUG: TargetGroups are supposed to contain at least one IP! "); } memcpy( t, &next, sizeof( struct sockaddr_storage ) ); /* If current spec is a named host (not a range), store name in supplied buff */ @@ -208,12 +208,12 @@ int NpingTargets::getNextIPv4Address(u32 *addr){ char buff[257]; memset(buff, 0, 257); if( addr == NULL ) - outFatal(QT_3, "getNextIPv4Address(): NULL value supplied. "); + nping_fatal(QT_3, "getNextIPv4Address(): NULL value supplied. "); if ( this->getNextTargetAddressAndName(&t, &tlen, buff, 256) != OP_SUCCESS ) return OP_FAILURE; struct sockaddr_in *p=( struct sockaddr_in *)&t; if(p->sin_family!=AF_INET) - outFatal(QT_3, "getNextIPv4Address(): Trying to obtain an IPv4 address from an IPv6 target."); + nping_fatal(QT_3, "getNextIPv4Address(): Trying to obtain an IPv4 address from an IPv6 target."); *addr = p->sin_addr.s_addr; return OP_SUCCESS; } /* End of getNextIPv4Address() */ @@ -273,7 +273,7 @@ int NpingTargets::processSpecs(){ if(o.getMode()!=TCP_CONNECT && o.getMode()!=UDP_UNPRIV){ result=route_dst( &ss, &rnfo, o.getDevice(), NULL ); if(result==false){ - outError(QT_2, "Failed to determine route to host %s. Skipping it...", mytarget->getTargetIPstr() ); + nping_warning(QT_2, "Failed to determine route to host %s. Skipping it...", mytarget->getTargetIPstr() ); delete mytarget; continue; } @@ -309,7 +309,7 @@ int NpingTargets::processSpecs(){ mytarget->setSrcMACAddress( rnfo.ii.mac ); if( rnfo.ii.device_up == false ) - outError(QT_2, "Device used for target host %s seems to be down.", mytarget->getTargetIPstr()); + nping_warning(QT_2, "Device used for target host %s seems to be down.", mytarget->getTargetIPstr()); /* Determine next hop MAC address and target MAC address */ if( o.sendEth() ){ @@ -348,7 +348,7 @@ NpingTarget *NpingTargets::getNextTarget(){ /* Did we reach the end of the vector in the last call? */ if( this->current_target >= this->Targets.size() ) return NULL; - outPrint(DBG_4, "Next target returned by getNextTarget(): Targets[%lu/%lu] --> %s \n", this->current_target, (unsigned long) this->Targets.size(), this->Targets.at(this->current_target)->getTargetIPstr() ); + nping_print(DBG_4, "Next target returned by getNextTarget(): Targets[%lu/%lu] --> %s \n", this->current_target, (unsigned long) this->Targets.size(), this->Targets.at(this->current_target)->getTargetIPstr() ); return this->Targets.at( this->current_target++ ); } /* End of getNextTarget() */ diff --git a/nping/ProbeMode.cc b/nping/ProbeMode.cc index dd2b55398..96dc56302 100644 --- a/nping/ProbeMode.cc +++ b/nping/ProbeMode.cc @@ -120,7 +120,7 @@ int ProbeMode::init_nsock(){ if( nsock_init==false ){ /* Create a new nsock pool */ if ((nsp = nsp_new(NULL)) == NULL) - outFatal(QT_3, "Failed to create new pool. QUITTING.\n"); + nping_fatal(QT_3, "Failed to create new pool. QUITTING.\n"); nsp_setdevice(nsp, o.getDevice()); /* Allow broadcast addresses */ @@ -152,7 +152,7 @@ int ProbeMode::cleanup(){ * calling this method; otherwise, it will fatal() */ nsock_pool ProbeMode::getNsockPool(){ if( this->nsock_init==false) - outFatal(QT_3, "getNsockPool() called before init_nsock(). Please report a bug."); + nping_fatal(QT_3, "getNsockPool() called before init_nsock(). Please report a bug."); return this->nsp; } /* End of getNsockPool() */ @@ -236,12 +236,12 @@ int ProbeMode::start(){ first_time=false; loopret=nsock_loop(nsp, 2); if (loopret == NSOCK_LOOP_ERROR) - outFatal(QT_3, "Unexpected nsock_loop error.\n"); + nping_fatal(QT_3, "Unexpected nsock_loop error.\n"); }else{ nsock_timer_create(nsp, tcpconnect_event_handler, o.getDelay()+1, &pkts2send[pc]); loopret=nsock_loop(nsp, o.getDelay()+1); if (loopret == NSOCK_LOOP_ERROR) - outFatal(QT_3, "Unexpected nsock_loop error.\n"); + nping_fatal(QT_3, "Unexpected nsock_loop error.\n"); } } } @@ -251,7 +251,7 @@ int ProbeMode::start(){ * otherwise nsock_loop() will return inmediatly */ loopret=nsock_loop(nsp, DEFAULT_WAIT_AFTER_PROBES); if (loopret == NSOCK_LOOP_ERROR) - outFatal(QT_3, "Unexpected nsock_loop error.\n"); + nping_fatal(QT_3, "Unexpected nsock_loop error.\n"); o.stats.stopRxClock(); return OP_SUCCESS; break; /* case TCP_CONNECT */ @@ -290,12 +290,12 @@ int ProbeMode::start(){ first_time=false; loopret=nsock_loop(nsp, 2); if (loopret == NSOCK_LOOP_ERROR) - outFatal(QT_3, "Unexpected nsock_loop error.\n"); + nping_fatal(QT_3, "Unexpected nsock_loop error.\n"); }else{ nsock_timer_create(nsp, udpunpriv_event_handler, o.getDelay(), &pkts2send[pc]); loopret=nsock_loop(nsp, o.getDelay()); if (loopret == NSOCK_LOOP_ERROR) - outFatal(QT_3, "Unexpected nsock_loop error.\n"); + nping_fatal(QT_3, "Unexpected nsock_loop error.\n"); } } } @@ -306,7 +306,7 @@ int ProbeMode::start(){ if(!o.disablePacketCapture()){ loopret=nsock_loop(nsp, DEFAULT_WAIT_AFTER_PROBES); if (loopret == NSOCK_LOOP_ERROR) - outFatal(QT_3, "Unexpected nsock_loop error.\n"); + nping_fatal(QT_3, "Unexpected nsock_loop error.\n"); } o.stats.stopRxClock(); return OP_SUCCESS; @@ -325,22 +325,22 @@ int ProbeMode::start(){ if( o.getMode()!=ARP && o.sendEth()==false ){ /* Get socket descriptor. No need for it in ARP since we send at eth level */ if ((rawipsd = obtainRawSocket()) < 0 ) - outFatal(QT_3,"Couldn't acquire raw socket. Are you root?"); + nping_fatal(QT_3,"Couldn't acquire raw socket. Are you root?"); } /* Check if we have enough information to get the party started */ if((o.getMode()==TCP || o.getMode()==UDP) && targetPorts==NULL) - outFatal(QT_3, "normalProbeMode(): NpingOps does not contain correct target ports\n"); + nping_fatal(QT_3, "normalProbeMode(): NpingOps does not contain correct target ports\n"); /* Set up libpcap */ if(!o.disablePacketCapture()){ /* Create new IOD for pcap */ if ((pcap_nsi = nsi_new(nsp, NULL)) == NULL) - outFatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n"); + nping_fatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n"); /* Open pcap */ filterstring=getBPFFilterString(); - outPrint(DBG_2,"Opening pcap device %s", o.getDevice() ); + nping_print(DBG_2,"Opening pcap device %s", o.getDevice() ); #ifdef WIN32 /* Nping normally uses device names obtained through dnet for interfaces, but Pcap has its own naming system. So the conversion is done here */ @@ -352,8 +352,8 @@ int ProbeMode::start(){ Strncpy(pcapdev, o.getDevice(), sizeof(pcapdev)); #endif if( (auxpnt=nsock_pcap_open(nsp, pcap_nsi, pcapdev, 8192, (o.spoofSource())? 1 : 0, filterstring )) != NULL ) - outFatal(QT_3, "Error opening capture device %s --> %s\n", o.getDevice(), auxpnt); - outPrint(DBG_2,"Pcap device %s open successfully", o.getDevice() ); + nping_fatal(QT_3, "Error opening capture device %s --> %s\n", o.getDevice(), auxpnt); + nping_print(DBG_2,"Pcap device %s open successfully", o.getDevice() ); } /* Ready? Go! */ @@ -377,11 +377,11 @@ int ProbeMode::start(){ currentPort=targetPorts[p]; if ( fillPacket( target, currentPort, pkt, MAX_IP_PACKET_LEN, &pktLen, rawipsd ) != OP_SUCCESS ){ - outFatal(QT_3, "normalProbeMode(): Error in packet creation"); + nping_fatal(QT_3, "normalProbeMode(): Error in packet creation"); } /* Safe checks */ if (pkt == NULL || pktLen <=0) - outFatal(QT_3, "normalProbeMode(): Invalid packet returned by fillPacket() "); + nping_fatal(QT_3, "normalProbeMode(): Invalid packet returned by fillPacket() "); /* Store relevant info so we can pass it to the handler */ pc=(pc+1)%MX_PKT; @@ -406,12 +406,12 @@ int ProbeMode::start(){ first_time=false; loopret=nsock_loop(nsp, 2); if (loopret == NSOCK_LOOP_ERROR) - outFatal(QT_3, "Unexpected nsock_loop error.\n"); + nping_fatal(QT_3, "Unexpected nsock_loop error.\n"); }else{ nsock_timer_create(nsp, nping_event_handler, o.getDelay(), &pkts2send[pc]); loopret=nsock_loop(nsp, o.getDelay()+1); if (loopret == NSOCK_LOOP_ERROR) - outFatal(QT_3, "Unexpected nsock_loop error.\n"); + nping_fatal(QT_3, "Unexpected nsock_loop error.\n"); } } } @@ -430,9 +430,9 @@ int ProbeMode::start(){ while( (target=o.targets.getNextTarget()) != NULL ){ if ( fillPacket( target, 0, pkt, MAX_IP_PACKET_LEN, &pktLen, rawipsd ) != OP_SUCCESS ) - outFatal(QT_3, "normalProbeMode(): Error in packet creation"); + nping_fatal(QT_3, "normalProbeMode(): Error in packet creation"); if (pkt == NULL || pktLen <=0) - outFatal(QT_3, "normalProbeMode(): Error packet returned by createPacket() "); + nping_fatal(QT_3, "normalProbeMode(): Error packet returned by createPacket() "); /* Store relevant info so we can pass it to the handler */ pc=(pc+1)%MX_PKT; @@ -456,12 +456,12 @@ int ProbeMode::start(){ first_time=false; loopret=nsock_loop(nsp, 2); if (loopret == NSOCK_LOOP_ERROR) - outFatal(QT_3, "Unexpected nsock_loop error.\n"); + nping_fatal(QT_3, "Unexpected nsock_loop error.\n"); }else{ nsock_timer_create(nsp, nping_event_handler, o.getDelay(), &pkts2send[pc]); loopret=nsock_loop(nsp, o.getDelay()+1); if (loopret == NSOCK_LOOP_ERROR) - outFatal(QT_3, "Unexpected nsock_loop error.\n"); + nping_fatal(QT_3, "Unexpected nsock_loop error.\n"); } } } @@ -474,7 +474,7 @@ int ProbeMode::start(){ nsock_pcap_read_packet(nsp, pcap_nsi, nping_event_handler, DEFAULT_WAIT_AFTER_PROBES, NULL); loopret=nsock_loop(nsp, DEFAULT_WAIT_AFTER_PROBES); if (loopret == NSOCK_LOOP_ERROR) - outFatal(QT_3, "Unexpected nsock_loop error.\n"); + nping_fatal(QT_3, "Unexpected nsock_loop error.\n"); o.stats.stopRxClock(); } /* Close opened descriptors */ @@ -483,7 +483,7 @@ int ProbeMode::start(){ break; /* case TCP || case UDP || case ICMP || case ARP */ default: - outFatal(QT_3, "normalProbeMode(): Wrong mode. Please report this bug."); + nping_fatal(QT_3, "normalProbeMode(): Wrong mode. Please report this bug."); break; } /* End of main switch */ return OP_SUCCESS; @@ -521,7 +521,7 @@ int ProbeMode::fillPacket(NpingTarget *target, u16 port, u8 *buff, int bufflen, if(target==NULL || buff==NULL || bufflen<=0 || filledlen==NULL) return OP_FAILURE; else - outPrint(DBG_4, "fillPacket(target=%p, port=%d, buff=%p, bufflen=%d, filledlen=%p rawfd=%d)", target, port, buff, bufflen, filledlen, rawfd); + nping_print(DBG_4, "fillPacket(target=%p, port=%d, buff=%p, bufflen=%d, filledlen=%p rawfd=%d)", target, port, buff, bufflen, filledlen, rawfd); /* If o.sendEth() is true that means we need to send packets at raw ethernet * level (we are probably running on windows or user requested that explicitly. @@ -532,7 +532,7 @@ int ProbeMode::fillPacket(NpingTarget *target, u16 port, u8 *buff, int bufflen, if(o.sendEth() && o.getMode()!=ARP){ e.setNextElement( NULL ); if( buff==NULL || filledlen==NULL) - outFatal(QT_3,"fillPacketARP(): NULL pointer supplied."); + nping_fatal(QT_3,"fillPacketARP(): NULL pointer supplied."); /* Source MAC Address */ if( o.issetSourceMAC() ) e.setSrcMAC( o.getSourceMAC() ); @@ -540,7 +540,7 @@ int ProbeMode::fillPacket(NpingTarget *target, u16 port, u8 *buff, int bufflen, if( target->getSrcMACAddress() ) e.setSrcMAC( (u8 *)target->getSrcMACAddress() ); else - outFatal(QT_3, "fillPacket(): Cannot determine Source MAC address."); + nping_fatal(QT_3, "fillPacket(): Cannot determine Source MAC address."); } /* Destination MAC Address */ @@ -550,7 +550,7 @@ int ProbeMode::fillPacket(NpingTarget *target, u16 port, u8 *buff, int bufflen, if( target->getNextHopMACAddress() ) e.setDstMAC( (u8 *)target->getNextHopMACAddress() ); else - outFatal(QT_3, "fillPacket(): Cannot determine Next Hop MAC address."); + nping_fatal(QT_3, "fillPacket(): Cannot determine Next Hop MAC address."); } /* Ethertype value */ @@ -562,7 +562,7 @@ int ProbeMode::fillPacket(NpingTarget *target, u16 port, u8 *buff, int bufflen, else if ( o.getIPVersion() == IP_VERSION_6 ) e.setEtherType(ETHTYPE_IPV6); else - outFatal(QT_3, "Bug in fillPacket() and NpingOps::ipversion"); + nping_fatal(QT_3, "Bug in fillPacket() and NpingOps::ipversion"); } /* Write the ethernet header to the beginning of the original buffer */ @@ -589,7 +589,7 @@ int ProbeMode::fillPacket(NpingTarget *target, u16 port, u8 *buff, int bufflen, fillPacketARP(target, pnt, pntlen, &final_len, rawfd); break; default: - outFatal(QT_3, "Bug in fillPacket() and NpingOps::getMode()"); + nping_fatal(QT_3, "Bug in fillPacket() and NpingOps::getMode()"); break; } @@ -606,7 +606,7 @@ int ProbeMode::fillPacket(NpingTarget *target, u16 port, u8 *buff, int bufflen, * @return OP_SUCCESS on success and fatal()s in case of failure. */ int ProbeMode::createIPv4(IPv4Header *i, PacketElement *next_element, const char *next_proto, NpingTarget *target){ if( i==NULL || next_proto==NULL || target==NULL) - outFatal(QT_3,"createIPv4(): NULL pointer supplied."); + nping_fatal(QT_3,"createIPv4(): NULL pointer supplied."); i->setNextElement( next_element ); /* Set datagram payload */ i->setDestinationAddress( target->getIPv4Address() ); /* Destination IP */ @@ -652,7 +652,7 @@ int ProbeMode::createIPv4(IPv4Header *i, PacketElement *next_element, const char * @return OP_SUCCESS on success and fatal()s in case of failure. */ int ProbeMode::createIPv6(IPv6Header *i, PacketElement *next_element, const char *next_proto, NpingTarget *target){ if( i==NULL || next_proto==NULL || target==NULL) - outFatal(QT_3,"createIPv6(): NULL pointer supplied."); + nping_fatal(QT_3,"createIPv6(): NULL pointer supplied."); /* Set datagram payload */ i->setNextElement( next_element ); @@ -678,7 +678,7 @@ int ProbeMode::createIPv6(IPv6Header *i, PacketElement *next_element, const char if ( target->getIPv6SourceAddress_u8() != NULL ) i->setSourceAddress( target->getIPv6SourceAddress_u8() ); else - outFatal(QT_3, "createIPv6(): Cannot determine Source IPv6 Address"); + nping_fatal(QT_3, "createIPv6(): Cannot determine Source IPv6 Address"); } return OP_SUCCESS; } /* End of createIPv6() */ @@ -701,7 +701,7 @@ int ProbeMode::createIPv6(IPv6Header *i, PacketElement *next_element, const char * So this function basically takes a raw IPv6 socket descriptor and then tries * to set some basic parameters (like Hop Limit) using setsockopt() calls. * It always returns OP_SUCCESS. However, if errors are found, they are printed - * (QT_2 level) using outError(); + * (QT_2 level) using nping_warning(); * */ int ProbeMode::doIPv6ThroughSocket(int rawfd){ @@ -715,9 +715,9 @@ int ProbeMode::doIPv6ThroughSocket(int rawfd){ hoplimit=DEFAULT_IPv6_TTL; } if( setsockopt(rawfd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (char *)&hoplimit, sizeof(hoplimit)) != 0 ) - outError(QT_2, "doIPv6ThroughSocket(): setsockopt() for Unicast Hop Limit on IPv6 socket failed"); + nping_warning(QT_2, "doIPv6ThroughSocket(): setsockopt() for Unicast Hop Limit on IPv6 socket failed"); if( setsockopt(rawfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&hoplimit, sizeof(hoplimit)) != 0 ) - outError(QT_2, "doIPv6ThroughSocket(): setsockopt() for Multicast Hop Limit on IPv6 socket failed"); + nping_warning(QT_2, "doIPv6ThroughSocket(): setsockopt() for Multicast Hop Limit on IPv6 socket failed"); #ifdef IPV6_CHECKSUM /* This is not available in when compiling with MinGW */ /* Transport layer checksum */ @@ -734,7 +734,7 @@ int ProbeMode::doIPv6ThroughSocket(int rawfd){ if( o.getBadsum()==false ){ int offset = 16; if( setsockopt (rawfd, IPPROTO_IPV6, IPV6_CHECKSUM, (char *)&offset, sizeof(offset)) != 0 ) - outError(QT_2, "doIPv6ThroughSocket(): failed to set IPV6_CHECKSUM option on IPv6 socket. "); + nping_warning(QT_2, "doIPv6ThroughSocket(): failed to set IPV6_CHECKSUM option on IPv6 socket. "); } } #endif @@ -744,7 +744,7 @@ int ProbeMode::doIPv6ThroughSocket(int rawfd){ /* It seems that SO_BINDTODEVICE only work on linux */ #ifdef LINUX if (setsockopt(rawfd, SOL_SOCKET, SO_BINDTODEVICE, o.getDevice(), strlen(o.getDevice())+1) == -1) { - outError(QT_2, "Error binding IPv6 socket to device %s", o.getDevice() ); + nping_warning(QT_2, "Error binding IPv6 socket to device %s", o.getDevice() ); } #endif } @@ -772,7 +772,7 @@ int ProbeMode::fillPacketTCP(NpingTarget *target, u16 port, u8 *buff, int buffle struct in_addr tip, sip; if( buff==NULL || filledlen==NULL || target==NULL) - outFatal(QT_3,"fillPacketTCP(): NULL pointer supplied."); + nping_fatal(QT_3,"fillPacketTCP(): NULL pointer supplied."); /* Add Payload if neccessary */ if ( o.issetPayloadType() ){ @@ -875,7 +875,7 @@ int ProbeMode::fillPacketTCP(NpingTarget *target, u16 port, u8 *buff, int buffle break; default: - outFatal(QT_3, "fillPacketTCP(): Wrong IP version in NpingOps\n"); + nping_fatal(QT_3, "fillPacketTCP(): Wrong IP version in NpingOps\n"); break; } @@ -904,7 +904,7 @@ int ProbeMode::fillPacketUDP(NpingTarget *target, u16 port, u8 *buff, int buffle struct in_addr tip, sip; if( buff==NULL || filledlen==NULL || target==NULL) - outFatal(QT_3,"fillPacketUDP(): NULL pointer supplied."); + nping_fatal(QT_3,"fillPacketUDP(): NULL pointer supplied."); /* Add Payload if neccessary */ @@ -984,7 +984,7 @@ int ProbeMode::fillPacketUDP(NpingTarget *target, u16 port, u8 *buff, int buffle break; default: - outFatal(QT_3, "fillPacketUDP(): Wrong IP version in NpingOps\n"); + nping_fatal(QT_3, "fillPacketUDP(): Wrong IP version in NpingOps\n"); break; } @@ -1008,8 +1008,8 @@ int ProbeMode::fillPacketICMP(NpingTarget *target, u8 *buff, int bufflen, int *f RawData p; if( buff==NULL || filledlen==NULL || target==NULL) - outFatal(QT_3,"fillPacketICMP(): NULL pointer supplied."); - outPrint(DBG_4, "fillPacketICMP(target=%p, buff=%p, bufflen=%d, filledlen=%p)", target, buff, bufflen, filledlen); + nping_fatal(QT_3,"fillPacketICMP(): NULL pointer supplied."); + nping_print(DBG_4, "fillPacketICMP(target=%p, buff=%p, bufflen=%d, filledlen=%p)", target, buff, bufflen, filledlen); /* Add Payload if neccessary */ if ( o.issetPayloadType() ){ @@ -1168,9 +1168,9 @@ int ProbeMode::fillPacketARP(NpingTarget *target, u8 *buff, int bufflen, int *fi u8 nullmac[6]={0x00,0x00,0x00,0x00,0x00,0x00}; if(target==NULL || buff==NULL || filledlen==NULL) - outFatal(QT_3,"fillPacketARP(): NULL pointer supplied."); + nping_fatal(QT_3,"fillPacketARP(): NULL pointer supplied."); - outPrint(DBG_4, "fillPacketARP(target=%p, buff=%p, bufflen=%d, filledlen=%p)", target, buff, bufflen, filledlen); + nping_print(DBG_4, "fillPacketARP(target=%p, buff=%p, bufflen=%d, filledlen=%p)", target, buff, bufflen, filledlen); /* Source MAC Address */ if( o.issetSourceMAC() ) @@ -1298,7 +1298,7 @@ char *ProbeMode::getBPFFilterString(){ strncpy(filterstring, buffer, sizeof(filterstring)-1); else strncpy(filterstring, "", 2); - outPrint(DBG_1, "BPF-filter: %s", filterstring); + nping_print(DBG_1, "BPF-filter: %s", filterstring); return filterstring; } @@ -1306,7 +1306,7 @@ char *ProbeMode::getBPFFilterString(){ if( o.getRole()==ROLE_SERVER ){ /* Capture all IP packets but the ones that belong to the side-channel */ sprintf(filterstring, "ip and ( not (tcp and (dst port %d or src port %d) ) )", o.getEchoPort(), o.getEchoPort() ); - outPrint(DBG_1, "BPF-filter: %s", filterstring); + nping_print(DBG_1, "BPF-filter: %s", filterstring); return filterstring; } @@ -1325,7 +1325,7 @@ char *ProbeMode::getBPFFilterString(){ s4->sin_family=AF_INET; inet_pton(AF_INET, "127.0.0.1", &s4->sin_addr); } - outPrint(DBG_2, "Couldn't determine source addrees. Using address %s in BFP filter", IPtoa(&srcss) ); + nping_print(DBG_2, "Couldn't determine source addrees. Using address %s in BFP filter", IPtoa(&srcss) ); } o.targets.rewind(); @@ -1349,7 +1349,7 @@ char *ProbeMode::getBPFFilterString(){ }else if( s4->sin_family == AF_INET ) { inet_ntop(AF_INET, &s4->sin_addr, ipstring, sizeof(ipstring)); }else{ - outError(QT_2, "Warning: Wrong address family (%d) in getBPFFilterString(). Please report a bug", srcss.ss_family); + nping_warning(QT_2, "Warning: Wrong address family (%d) in getBPFFilterString(). Please report a bug", srcss.ss_family); sprintf(ipstring,"127.0.0.1"); } @@ -1478,7 +1478,7 @@ char *ProbeMode::getBPFFilterString(){ Snprintf(buffer, 1024-strlen(filterstring), "or (icmp and (icmp[icmptype] = %d or icmp[icmptype] = %d or icmp[icmptype] = %d or icmp[icmptype] = %d or icmp[icmptype] = %d)) )" , ICMP_UNREACH, ICMP_SOURCEQUENCH, ICMP_REDIRECT, ICMP_TIMXCEED, ICMP_PARAMPROB); } - outPrint(DBG_1, "BPF-filter: %s", filterstring); + nping_print(DBG_1, "BPF-filter: %s", filterstring); return filterstring; } /* End of getBPFFilterString() */ @@ -1528,7 +1528,7 @@ void ProbeMode::probe_nping_event_handler(nsock_pool nsp, nsock_event nse, void bool ip=false; memset(final_output, 0, sizeof(final_output)); - outPrint(DBG_4, "nping_event_handler(): Received callback of type %s with status %s", + nping_print(DBG_4, "nping_event_handler(): Received callback of type %s with status %s", nse_type2str(type), nse_status2str(status)); if (status == NSE_STATUS_SUCCESS ) { @@ -1567,7 +1567,7 @@ void ProbeMode::probe_nping_event_handler(nsock_pool nsp, nsock_event nse, void mypacket->target->setProbeSentICMP(0,0); } if( o.showSentPackets() ){ - outPrint(VB_0,"SENT (%.4fs) %s", o.stats.elapsedRuntime(t), pktinfobuffer ); + nping_print(VB_0,"SENT (%.4fs) %s", o.stats.elapsedRuntime(t), pktinfobuffer ); if( o.getVerbosity() >= VB_3 ) luis_hdump((char*)mypacket->pkt, mypacket->pktLen); } @@ -1596,7 +1596,7 @@ void ProbeMode::probe_nping_event_handler(nsock_pool nsp, nsock_event nse, void ip=false; break; default: - outError(QT_1, "RCVD (%.4fs) Unsupported protocol (Ethernet type %02X)", o.stats.elapsedRuntime(t), *ethtype); + nping_warning(QT_1, "RCVD (%.4fs) Unsupported protocol (Ethernet type %02X)", o.stats.elapsedRuntime(t), *ethtype); print_hexdump(VB_3, packet, packetlen); return; break; @@ -1608,11 +1608,11 @@ void ProbeMode::probe_nping_event_handler(nsock_pool nsp, nsock_event nse, void }else{ IPv4Header iphdr; if( iphdr.storeRecvData(packet, packetlen)!=OP_SUCCESS ) - outError(QT_1, "RCVD (%.4fs) Bogus packet received.", o.stats.elapsedRuntime(t)); + nping_warning(QT_1, "RCVD (%.4fs) Bogus packet received.", o.stats.elapsedRuntime(t)); if( iphdr.getVersion()==4 || iphdr.getVersion()==6){ ip=true; }else{ - outError(QT_1, "RCVD (%.4fs) Unsupported protocol.", o.stats.elapsedRuntime(t)); + nping_warning(QT_1, "RCVD (%.4fs) Unsupported protocol.", o.stats.elapsedRuntime(t)); print_hexdump(VB_3, packet, packetlen); return; } @@ -1672,7 +1672,7 @@ void ProbeMode::probe_nping_event_handler(nsock_pool nsp, nsock_event nse, void /* Packet is ARP */ }else{ getPacketStrInfo("ARP",(const u8*)packet, packetlen, buffer, 512); - outPrint(VB_0, "RCVD (%.4fs) %s", o.stats.elapsedRuntime(t), buffer ); + nping_print(VB_0, "RCVD (%.4fs) %s", o.stats.elapsedRuntime(t), buffer ); o.stats.addRecvPacket(packetlen); print_hexdump(VB_3 | NO_NEWLINE, packet, packetlen); /* TODO: find target and call setProbeRecvARP() */ @@ -1684,7 +1684,7 @@ void ProbeMode::probe_nping_event_handler(nsock_pool nsp, nsock_event nse, void o.setDelayedRcvd(final_output, ev_id); } else - outPrint(VB_0|NO_NEWLINE, "%s", final_output); + nping_print(VB_0|NO_NEWLINE, "%s", final_output); break; /* In theory we should never get these kind of events in this handler @@ -1693,28 +1693,28 @@ void ProbeMode::probe_nping_event_handler(nsock_pool nsp, nsock_event nse, void case NSE_TYPE_CONNECT_SSL: case NSE_TYPE_READ: case NSE_TYPE_WRITE: - outFatal(QT_3, "Bug in nping_event_handler(). Received %s event.", nse_type2str(type)); + nping_fatal(QT_3, "Bug in nping_event_handler(). Received %s event.", nse_type2str(type)); break; default: - outFatal(QT_3, "nping_event_handler(): Bogus event type."); + nping_fatal(QT_3, "nping_event_handler(): Bogus event type."); break; } /* switch(type) */ } else if (status == NSE_STATUS_EOF) { - outPrint(DBG_4, "nping_event_handler(): Unexpected behaviour: Got EOF. Please report this bug.\n"); + nping_print(DBG_4, "nping_event_handler(): Unexpected behaviour: Got EOF. Please report this bug.\n"); } else if (status == NSE_STATUS_ERROR) { - outError(QT_2, "nping_event_handler(): %s failed: %s", nse_type2str(type), strerror(socket_errno())); + nping_warning(QT_2, "nping_event_handler(): %s failed: %s", nse_type2str(type), strerror(socket_errno())); } else if (status == NSE_STATUS_TIMEOUT) { - outPrint(DBG_4,"nping_event_handler(): %s timeout: %s\n", nse_type2str(type), strerror(socket_errno())); + nping_print(DBG_4,"nping_event_handler(): %s timeout: %s\n", nse_type2str(type), strerror(socket_errno())); } else if (status == NSE_STATUS_CANCELLED) { - outError(QT_2, "nping_event_handler(): %s canceled: %s", nse_type2str(type), strerror(socket_errno())); + nping_warning(QT_2, "nping_event_handler(): %s canceled: %s", nse_type2str(type), strerror(socket_errno())); } else if (status == NSE_STATUS_KILL) { - outError(QT_2, "nping_event_handler(): %s killed: %s", nse_type2str(type), strerror(socket_errno())); + nping_warning(QT_2, "nping_event_handler(): %s killed: %s", nse_type2str(type), strerror(socket_errno())); } else{ - outError(QT_2, "nping_event_handler(): Unknown status code %d\n", status); + nping_warning(QT_2, "nping_event_handler(): Unknown status code %d\n", status); } return; @@ -1823,13 +1823,13 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse, /* If we can't allocate for that many descriptors, reduce our requirements */ max_iods=DEFAULT_MAX_DESCRIPTORS-RESERVED_DESCRIPTORS; if( (fds=(nsock_iod *)calloc(max_iods, sizeof(nsock_iod)))==NULL ){ - outFatal(QT_3, "ProbeMode::probe_tcpconnect_event_handler(): Not enough memory"); + nping_fatal(QT_3, "ProbeMode::probe_tcpconnect_event_handler(): Not enough memory"); } } - outPrint(DBG_7, "%d descriptors needed, %d available", o.getTotalProbes(), max_iods); + nping_print(DBG_7, "%d descriptors needed, %d available", o.getTotalProbes(), max_iods); } - outPrint(DBG_4, "tcpconnect_event_handler(): Received callback of type %s with status %s", nse_type2str(type), nse_status2str(status)); + nping_print(DBG_4, "tcpconnect_event_handler(): Received callback of type %s with status %s", nse_type2str(type), nse_status2str(status)); if (status == NSE_STATUS_SUCCESS ) { @@ -1838,7 +1838,7 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse, /* TCP Handshake was completed successfully */ case NSE_TYPE_CONNECT: if( mypacket==NULL ) - outFatal(QT_3, "tcpconnect_event_handler(): NULL value supplied."); + nping_fatal(QT_3, "tcpconnect_event_handler(): NULL value supplied."); /* Determine which target are we dealing with */ nsi_getlastcommunicationinfo(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) ); if(family==AF_INET6){ @@ -1855,13 +1855,13 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse, trg=o.targets.findTarget( &peer ); if(trg!=NULL){ if ( trg->getSuppliedHostName() ) - outPrint(VB_0,"RECV (%.4fs) Handshake with %s:%d (%s:%d) completed", + nping_print(VB_0,"RECV (%.4fs) Handshake with %s:%d (%s:%d) completed", o.stats.elapsedRuntime(t), trg->getSuppliedHostName(), peerport, ipstring, peerport ); else - outPrint(VB_0,"RECV (%.4fs) Handshake with %s:%d completed", o.stats.elapsedRuntime(t), ipstring, peerport ); + nping_print(VB_0,"RECV (%.4fs) Handshake with %s:%d completed", o.stats.elapsedRuntime(t), ipstring, peerport ); trg->setProbeRecvTCP( peerport , 0); }else{ - outPrint(VB_0,"RECV (%.4fs) Handshake with %s:%d completed", o.stats.elapsedRuntime(t), ipstring, peerport ); + nping_print(VB_0,"RECV (%.4fs) Handshake with %s:%d completed", o.stats.elapsedRuntime(t), ipstring, peerport ); } o.stats.addRecvPacket(40); /* Estimation Dst>We 1 TCP SYN|ACK */ break; @@ -1876,7 +1876,7 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse, * and/or multiple target ports. */ case NSE_TYPE_TIMER: if( mypacket==NULL ) - outFatal(QT_3, "tcpconnect_event_handler():2: NULL value supplied."); + nping_fatal(QT_3, "tcpconnect_event_handler():2: NULL value supplied."); /* Fill the appropriate sockaddr for the connect() call */ if( o.getIPVersion() == IP_VERSION_6 ){ @@ -1901,7 +1901,7 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse, } /* Create new IOD for connects */ if ((fds[packetno%max_iods] = nsi_new(nsp, NULL)) == NULL) - outFatal(QT_3, "tcpconnect_event_handler(): Failed to create new nsock_iod.\n"); + nping_fatal(QT_3, "tcpconnect_event_handler(): Failed to create new nsock_iod.\n"); /* Set socket source address. This allows setting things like custom source port */ struct sockaddr_storage ss; @@ -1912,9 +1912,9 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse, nsock_connect_tcp(nsp, fds[packetno%max_iods], tcpconnect_event_handler, 100000, mypacket, (struct sockaddr *)&to, sslen, mypacket->dstport); if( o.showSentPackets() ){ if ( mypacket->target->getSuppliedHostName() ) - outPrint(VB_0,"SENT (%.4fs) Starting TCP Handshake > %s:%d (%s:%d)", o.stats.elapsedRuntime(NULL), mypacket->target->getSuppliedHostName(), mypacket->dstport ,mypacket->target->getTargetIPstr(), mypacket->dstport); + nping_print(VB_0,"SENT (%.4fs) Starting TCP Handshake > %s:%d (%s:%d)", o.stats.elapsedRuntime(NULL), mypacket->target->getSuppliedHostName(), mypacket->dstport ,mypacket->target->getTargetIPstr(), mypacket->dstport); else - outPrint(VB_0,"SENT (%.4fs) Starting TCP Handshake > %s:%d", o.stats.elapsedRuntime(NULL), mypacket->target->getTargetIPstr(), mypacket->dstport); + nping_print(VB_0,"SENT (%.4fs) Starting TCP Handshake > %s:%d", o.stats.elapsedRuntime(NULL), mypacket->target->getTargetIPstr(), mypacket->dstport); } packetno++; o.stats.addSentPacket(80); /* Estimation Src>Dst 1 TCP SYN && TCP ACK */ @@ -1925,18 +1925,18 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse, case NSE_TYPE_READ: case NSE_TYPE_PCAP_READ: case NSE_TYPE_CONNECT_SSL: - outError(QT_2,"tcpconnect_event_handler(): Unexpected behaviour, %s event received . Please report this bug.", nse_type2str(type)); + nping_warning(QT_2,"tcpconnect_event_handler(): Unexpected behaviour, %s event received . Please report this bug.", nse_type2str(type)); break; default: - outFatal(QT_3, "tcpconnect_event_handler(): Bogus event type (%d). Please report this bug.", type); + nping_fatal(QT_3, "tcpconnect_event_handler(): Bogus event type (%d). Please report this bug.", type); break; } /* switch(type) */ } else if (status == NSE_STATUS_EOF) { - outPrint(DBG_4, "tcpconnect_event_handler(): Unexpected behaviour: Got EOF. Please report this bug.\n"); + nping_print(DBG_4, "tcpconnect_event_handler(): Unexpected behaviour: Got EOF. Please report this bug.\n"); } else if (status == NSE_STATUS_ERROR) { /** In my tests with Nping and Wireshark, I've seen that we get NSE_STATUS_ERROR * whenever we start a TCP handshake but our peer sends a TCP RST packet back @@ -1954,18 +1954,18 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse, inet_ntop(AF_INET, &peer4->sin_addr, ipstring, sizeof(ipstring)); peerport=ntohs(peer4->sin_port); } - outPrint(VB_0,"RECV (%.4fs) Possible TCP RST received from %s:%d --> %s", o.stats.elapsedRuntime(t),ipstring, peerport, strerror(nse_errorcode(nse)) ); + nping_print(VB_0,"RECV (%.4fs) Possible TCP RST received from %s:%d --> %s", o.stats.elapsedRuntime(t),ipstring, peerport, strerror(nse_errorcode(nse)) ); } else - outError(QT_2,"ERR: (%.4fs) %s to %s:%d failed: %s", o.stats.elapsedRuntime(t), nse_type2str(type), ipstring, peerport, strerror(socket_errno())); + nping_warning(QT_2,"ERR: (%.4fs) %s to %s:%d failed: %s", o.stats.elapsedRuntime(t), nse_type2str(type), ipstring, peerport, strerror(socket_errno())); } else if (status == NSE_STATUS_TIMEOUT) { - outPrint(DBG_4, "tcpconnect_event_handler(): %s timeout: %s\n", nse_type2str(type), strerror(socket_errno())); + nping_print(DBG_4, "tcpconnect_event_handler(): %s timeout: %s\n", nse_type2str(type), strerror(socket_errno())); } else if (status == NSE_STATUS_CANCELLED) { - outPrint(DBG_4, "tcpconnect_event_handler(): %s canceled: %s", nse_type2str(type), strerror(socket_errno())); + nping_print(DBG_4, "tcpconnect_event_handler(): %s canceled: %s", nse_type2str(type), strerror(socket_errno())); } else if (status == NSE_STATUS_KILL) { - outPrint(DBG_4, "tcpconnect_event_handler(): %s killed: %s", nse_type2str(type), strerror(socket_errno())); + nping_print(DBG_4, "tcpconnect_event_handler(): %s killed: %s", nse_type2str(type), strerror(socket_errno())); } else{ - outError(QT_2, "tcpconnect_event_handler(): Unknown status code %d. Please report this bug.", status); + nping_warning(QT_2, "tcpconnect_event_handler(): Unknown status code %d. Please report this bug.", status); } return; @@ -2059,13 +2059,13 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v /* If we can't allocate for that many descriptors, reduce our requirements */ max_iods=DEFAULT_MAX_DESCRIPTORS-RESERVED_DESCRIPTORS; if( (fds=(nsock_iod *)calloc(max_iods, sizeof(nsock_iod)))==NULL ){ - outFatal(QT_3, "ProbeMode:probe_udpunpriv_event_handler(): Not enough memory"); + nping_fatal(QT_3, "ProbeMode:probe_udpunpriv_event_handler(): Not enough memory"); } } - outPrint(DBG_7, "%d descriptors needed, %d available", o.getTotalProbes(), max_iods); + nping_print(DBG_7, "%d descriptors needed, %d available", o.getTotalProbes(), max_iods); } - outPrint(DBG_4, "udpunpriv_event_handler(): Received callback of type %s with status %s", nse_type2str(type), nse_status2str(status)); + nping_print(DBG_4, "udpunpriv_event_handler(): Received callback of type %s with status %s", nse_type2str(type), nse_status2str(status)); if (status == NSE_STATUS_SUCCESS ) { @@ -2077,7 +2077,7 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v * Basically this just means that nsock successfully obtained a UDP socket * ready to allow sending packets to the appropriate target. */ case NSE_TYPE_CONNECT: - outPrint(DBG_3,"Nsock UDP \"connection\" completed successfully."); + nping_print(DBG_3,"Nsock UDP \"connection\" completed successfully."); break; @@ -2085,7 +2085,7 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v /* We need to start an scheduled UDP packet transmission. */ case NSE_TYPE_TIMER: if( mypacket==NULL ) - outFatal(QT_3, "udpunpriv_event_handler():: NULL value supplied."); + nping_fatal(QT_3, "udpunpriv_event_handler():: NULL value supplied."); /* Fill the appropriate sockaddr for the connect() call */ if( o.getIPVersion() == IP_VERSION_6 ){ @@ -2110,7 +2110,7 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v } /* Create new IOD for connects */ if ((fds[packetno%max_iods] = nsi_new(nsp, NULL)) == NULL) - outFatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n"); + nping_fatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n"); /* Set socket source address. This allows setting things like custom source port */ struct sockaddr_storage ss; @@ -2159,12 +2159,12 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v trg=o.targets.findTarget( &peer ); if(trg!=NULL){ if ( trg->getSuppliedHostName() ) - outPrint(VB_0,"SENT (%.4fs) UDP packet with %lu bytes to %s:%d (%s:%d)", o.stats.elapsedRuntime(NULL), (unsigned long int)sentbytes, trg->getSuppliedHostName(), peerport, ipstring, peerport ); + nping_print(VB_0,"SENT (%.4fs) UDP packet with %lu bytes to %s:%d (%s:%d)", o.stats.elapsedRuntime(NULL), (unsigned long int)sentbytes, trg->getSuppliedHostName(), peerport, ipstring, peerport ); else - outPrint(VB_0,"SENT (%.4fs) UDP packet with %lu bytes to %s:%d", o.stats.elapsedRuntime(NULL), (unsigned long int)sentbytes, ipstring, peerport ); + nping_print(VB_0,"SENT (%.4fs) UDP packet with %lu bytes to %s:%d", o.stats.elapsedRuntime(NULL), (unsigned long int)sentbytes, ipstring, peerport ); trg->setProbeSentUDP( 0, peerport); }else{ - outPrint(VB_0,"SENT (%.4fs) UDP packet with %lu bytes to %s:%d", o.stats.elapsedRuntime(t), (unsigned long int)sentbytes, ipstring, peerport ); + nping_print(VB_0,"SENT (%.4fs) UDP packet with %lu bytes to %s:%d", o.stats.elapsedRuntime(t), (unsigned long int)sentbytes, ipstring, peerport ); } o.stats.addSentPacket(sentbytes); /* Here we don't count the headers, just payload bytes */ @@ -2183,7 +2183,7 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v /* Do an actual read() of the recv data */ readbuff=nse_readbuf(nse, &readbytes); if(readbuff==NULL){ - outFatal(QT_3, "Error: nse_readbuff failed to read in the from the probe"); + nping_fatal(QT_3, "Error: nse_readbuff failed to read in the from the probe"); } /* Determine which target are we dealing with */ nsi_getlastcommunicationinfo(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) ); @@ -2199,12 +2199,12 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v trg=o.targets.findTarget( &peer ); if(trg!=NULL){ if ( trg->getSuppliedHostName() ) - outPrint(VB_0,"RECV (%.4fs) UDP packet with %d bytes from %s:%d (%s:%d)", o.stats.elapsedRuntime(NULL), readbytes, trg->getSuppliedHostName(), peerport, ipstring, peerport ); + nping_print(VB_0,"RECV (%.4fs) UDP packet with %d bytes from %s:%d (%s:%d)", o.stats.elapsedRuntime(NULL), readbytes, trg->getSuppliedHostName(), peerport, ipstring, peerport ); else - outPrint(VB_0,"RECV (%.4fs) UDP packet with %d bytes from %s:%d", o.stats.elapsedRuntime(NULL), readbytes, ipstring, peerport ); + nping_print(VB_0,"RECV (%.4fs) UDP packet with %d bytes from %s:%d", o.stats.elapsedRuntime(NULL), readbytes, ipstring, peerport ); trg->setProbeRecvUDP(peerport, 0); }else{ - outPrint(VB_0,"RECV (%.4fs) UDP packet with %d bytes from %s:%d", o.stats.elapsedRuntime(t), readbytes, ipstring, peerport ); + nping_print(VB_0,"RECV (%.4fs) UDP packet with %d bytes from %s:%d", o.stats.elapsedRuntime(t), readbytes, ipstring, peerport ); } o.stats.addRecvPacket(readbytes); break; @@ -2212,18 +2212,18 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v case NSE_TYPE_PCAP_READ: case NSE_TYPE_CONNECT_SSL: - outError(QT_2,"udpunpriv_event_handler(): Unexpected behaviour, %s event received . Please report this bug.", nse_type2str(type)); + nping_warning(QT_2,"udpunpriv_event_handler(): Unexpected behaviour, %s event received . Please report this bug.", nse_type2str(type)); break; default: - outFatal(QT_3, "udpunpriv_event_handler(): Bogus event type (%d). Please report this bug.", type); + nping_fatal(QT_3, "udpunpriv_event_handler(): Bogus event type (%d). Please report this bug.", type); break; } /* switch(type) */ } else if (status == NSE_STATUS_EOF) { - outPrint(DBG_4, "udpunpriv_event_handler(): Unexpected behaviour: Got EOF. Please report this bug.\n"); + nping_print(DBG_4, "udpunpriv_event_handler(): Unexpected behaviour: Got EOF. Please report this bug.\n"); } else if (status == NSE_STATUS_ERROR) { nsi_getlastcommunicationinfo(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) ); if(family==AF_INET6){ @@ -2233,16 +2233,16 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v inet_ntop(AF_INET, &peer4->sin_addr, ipstring, sizeof(ipstring)); peerport=ntohs(peer4->sin_port); } - outError(QT_2,"ERR: (%.4fs) %s to %s:%d failed: %s", o.stats.elapsedRuntime(t), nse_type2str(type), ipstring, peerport, strerror(socket_errno())); + nping_warning(QT_2,"ERR: (%.4fs) %s to %s:%d failed: %s", o.stats.elapsedRuntime(t), nse_type2str(type), ipstring, peerport, strerror(socket_errno())); } else if (status == NSE_STATUS_TIMEOUT) { - outPrint(DBG_4, "udpunpriv_event_handler(): %s timeout: %s\n", nse_type2str(type), strerror(socket_errno())); + nping_print(DBG_4, "udpunpriv_event_handler(): %s timeout: %s\n", nse_type2str(type), strerror(socket_errno())); } else if (status == NSE_STATUS_CANCELLED) { - outPrint(DBG_4, "udpunpriv_event_handler(): %s canceled: %s", nse_type2str(type), strerror(socket_errno())); + nping_print(DBG_4, "udpunpriv_event_handler(): %s canceled: %s", nse_type2str(type), strerror(socket_errno())); } else if (status == NSE_STATUS_KILL) { - outPrint(DBG_4, "udpunpriv_event_handler(): %s killed: %s", nse_type2str(type), strerror(socket_errno())); + nping_print(DBG_4, "udpunpriv_event_handler(): %s killed: %s", nse_type2str(type), strerror(socket_errno())); } else{ - outError(QT_2, "udpunpriv_event_handler(): Unknown status code %d. Please report this bug.", status); + nping_warning(QT_2, "udpunpriv_event_handler(): Unknown status code %d. Please report this bug.", status); } return; @@ -2254,7 +2254,7 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v * method. We need this because C++ does not allow to use class methods as * callback functions for things like signal() or the Nsock lib. */ void nping_event_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); ProbeMode::probe_nping_event_handler(nsp, nse, arg); return; } /* End of nping_event_handler() */ @@ -2264,7 +2264,7 @@ void nping_event_handler(nsock_pool nsp, nsock_event nse, void *arg){ * method. We need this because C++ does not allow to use class methods as * callback functions for things like signal() or the Nsock lib. */ void tcpconnect_event_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); ProbeMode::probe_tcpconnect_event_handler(nsp, nse, arg); return; } /* End of tcpconnect_event_handler() */ @@ -2274,7 +2274,7 @@ void tcpconnect_event_handler(nsock_pool nsp, nsock_event nse, void *arg){ * method. We need this because C++ does not allow to use class methods as * callback functions for things like signal() or the Nsock lib. */ void udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); ProbeMode::probe_udpunpriv_event_handler(nsp, nse, arg); return; } /* End of udpunpriv_event_handler() */ @@ -2285,7 +2285,7 @@ void udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, void *arg){ * method. We need this because C++ does not allow to use class methods as * callback functions for things like signal() or the Nsock lib. */ void delayed_output_handler(nsock_pool nsp, nsock_event nse, void *arg){ - outPrint(DBG_4, "%s()", __func__); + nping_print(DBG_4, "%s()", __func__); ProbeMode::probe_delayed_output_handler(nsp, nse, arg); return; } /* End of udpunpriv_event_handler() */ diff --git a/nping/common_modified.cc b/nping/common_modified.cc index a5389f16c..36587e1e4 100644 --- a/nping/common_modified.cc +++ b/nping/common_modified.cc @@ -259,7 +259,7 @@ int TargetGroup::get_next_host(struct sockaddr_storage *ss, size_t *sslen) { //if (o.debugging > 2) { /* CHANGE: Do not use NmapOps and do not use log_Write*/ // log_write(LOG_STDOUT, "doing %d.%d.%d.%d = %d.%d.%d.%d\n", current[0], current[1], current[2], current[3], addresses[0][current[0]],addresses[1][current[1]],addresses[2][current[2]],addresses[3][current[3]]); //} - //outPrint(DBG_2, "doing %d.%d.%d.%d = %d.%d.%d.%d", current[0], current[1], current[2], current[3], addresses[0][current[0]],addresses[1][current[1]],addresses[2][current[2]],addresses[3][current[3]]); + //nping_print(DBG_2, "doing %d.%d.%d.%d = %d.%d.%d.%d", current[0], current[1], current[2], current[3], addresses[0][current[0]],addresses[1][current[1]],addresses[2][current[2]],addresses[3][current[3]]); /* Set the IP to the current value of everything */ @@ -443,7 +443,7 @@ int TargetGroup::parse_expr(const char * const target_expr, int af) { while (target->h_addr_list[count]) count++; if (count > 1) - outPrint(DBG_2,"Warning: Hostname %s resolves to %d IPs. Using %s.", target_net, count, inet_ntoa(*((struct in_addr *)target->h_addr_list[0]))); + nping_print(DBG_2,"Warning: Hostname %s resolves to %d IPs. Using %s.", target_net, count, inet_ntoa(*((struct in_addr *)target->h_addr_list[0]))); } else { error("Failed to resolve given hostname/IP: %s. Note that you can't use '/mask' AND '1-4,7,100-' style IP ranges", target_net); free(hostexp); diff --git a/nping/nping.cc b/nping/nping.cc index 8dfb71490..4519bb1d3 100644 --- a/nping/nping.cc +++ b/nping/nping.cc @@ -159,25 +159,25 @@ int main(int argc, char *argv[] ){ /* ISO 8601 date/time -- http://www.cl.cam.ac.uk/~mgk25/iso-time.html */ if ( strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M %Z", tm) <= 0) - outFatal(QT_3,"Unable to properly format time"); - outPrint(QT_1, "\nStarting %s %s ( %s ) at %s", NPING_NAME, NPING_VERSION, NPING_URL, tbuf); + nping_fatal(QT_3,"Unable to properly format time"); + nping_print(QT_1, "\nStarting %s %s ( %s ) at %s", NPING_NAME, NPING_VERSION, NPING_URL, tbuf); /*If nping is called on something that doesn't take port scanning * we should alert the user that their port command is going to be ignored * I choose to print out a Fatal error since the scan doesn't make sense. */ if(o.issetTargetPorts() && !o.scan_mode_uses_target_ports(o.getMode())) - outFatal(QT_3, "You cannot use -p (explicit port selection) in your current scan mode.\n(Perhaps you meant to use --tcp or --udp)"); + nping_fatal(QT_3, "You cannot use -p (explicit port selection) in your current scan mode.\n(Perhaps you meant to use --tcp or --udp)"); /* Resolve and cache target specs */ - outPrint(DBG_2,"Resolving specified targets..."); + nping_print(DBG_2,"Resolving specified targets..."); o.targets.processSpecs(); if( ((i=o.targets.getTargetsFetched())<=0) && o.getRole()!=ROLE_SERVER ) - outFatal(QT_3, "Execution aborted. Nping needs at least one valid target to operate."); + nping_fatal(QT_3, "Execution aborted. Nping needs at least one valid target to operate."); else - outPrint(DBG_2,"%lu target IP address%s determined.", i, (i==1)? "":"es" ); + nping_print(DBG_2,"%lu target IP address%s determined.", i, (i==1)? "":"es" ); switch( o.getRole() ){ @@ -201,7 +201,7 @@ int main(int argc, char *argv[] ){ break; default: - outFatal(QT_3, "Invalid role %d\n", o.getRole() ); + nping_fatal(QT_3, "Invalid role %d\n", o.getRole() ); break; } @@ -221,9 +221,9 @@ int main(int argc, char *argv[] ){ int do_safe_checks(){ IPv6Header i; if( (sizeof(u32) != 4) || (sizeof(u16) != 2) || (sizeof(u8) != 1) ) - outFatal(QT_3,"Types u32, u16 and u8 do not have the correct sizes on your system."); + nping_fatal(QT_3,"Types u32, u16 and u8 do not have the correct sizes on your system."); //if (i.test_correctness() == false) - // outError(QT_2,"IPv6 may not work on your system. Please report a bug."); + // nping_warning(QT_2,"IPv6 may not work on your system. Please report a bug."); test_stuff(); /* Little function that is called quite early to test some misc stuff. */ return OP_SUCCESS; } /* End of do_safe_checks() */ @@ -253,7 +253,7 @@ void test_stuff(){ * and http://seclists.org/nmap-dev/2009/q3/0596.html */ void signal_handler(int signo){ fflush(stdout); - outPrint(DBG_1,"signal_handler(): Received signal %d", signo); + nping_print(DBG_1,"signal_handler(): Received signal %d", signo); switch(signo) { case SIGINT: o.stats.stopTxClock(); @@ -267,7 +267,7 @@ void signal_handler(int signo){ break; default: - outError(QT_2, "signal_handler(): Unexpected signal received (%d). Please report a bug.", signo); + nping_warning(QT_2, "signal_handler(): Unexpected signal received (%d). Please report a bug.", signo); break; } fflush(stderr); diff --git a/nping/nping.h b/nping/nping.h index ff3b42792..2c28c3a87 100644 --- a/nping/nping.h +++ b/nping/nping.h @@ -219,13 +219,13 @@ * So the thing here is that there are two things that should be taken * into account: * 1. The current verbosity level that user has supplied from the command line - * 2. The verbosity level that we supply in our print calls ( outPrint(), - * outError(), etc...) + * 2. The verbosity level that we supply in our print calls ( nping_print(), + * nping_warning(), etc...) * * Fortunately Nping output functions already take care of checking the * current verbosity level, so programmers only have to decide which level * should they specify in their output calls. If you are a programmer and - * you are using outPrint(), outError() or outFatal() calls in Nping's code, + * you are using nping_print(), nping_warning() or nping_fatal() calls in Nping's code, * you have to ask yourself: Do I want to print extra information that * shouldn't be printed by default? Or am I printing important stuff like * errors, etc, that should almost always be printed out? @@ -250,9 +250,9 @@ * Check the comments after each level definition to see how they should be * used. Here are some examples: * - * outFatal(QT_3,"createIPv4(): NULL pointer supplied."); - * outPrint(DBG_2,"Resolving specified targets..."); - * outPrint(VB_0, "Raw packets sent: %llu ", this->stats.getSentPackets() ); + * nping_fatal(QT_3,"createIPv4(): NULL pointer supplied."); + * nping_print(DBG_2,"Resolving specified targets..."); + * nping_print(VB_0, "Raw packets sent: %llu ", this->stats.getSentPackets() ); * * */ @@ -292,7 +292,7 @@ #define MAX_DEV_LEN 128 /**< Max network interface name length */ -#define NO_NEWLINE 0x8000 /**< Used in outFatal(), outError() and outPrint() */ +#define NO_NEWLINE 0x8000 /**< Used in nping_fatal(), nping_warning() and nping_print() */ /** Bit count for number parsing functions */ #define RANGE_8_BITS 8 diff --git a/nping/output.cc b/nping/output.cc index 88454418e..228f115c2 100644 --- a/nping/output.cc +++ b/nping/output.cc @@ -108,7 +108,7 @@ extern NpingOps o; /** Print fatal error messages to stderr and then exits. * @warning This function does not return because it calls exit() */ -int outFatal(int level, const char *str, ...) { +int nping_fatal(int level, const char *str, ...) { va_list list; char errstr[MAX_ERR_STR_LEN]; memset(errstr,0, MAX_ERR_STR_LEN); @@ -135,7 +135,7 @@ int outFatal(int level, const char *str, ...) { va_end(list); exit(EXIT_FAILURE); return OP_SUCCESS; -} /* End of outFatal() */ +} /* End of nping_fatal() */ /** Prints recoverable error message to stderr and returns. This function @@ -143,9 +143,9 @@ int outFatal(int level, const char *str, ...) { * behaviour it is possible to OR the supplied level with the constant * NO_NEWLINE like this: * - * outError(QT_2|NO_NEWLINE, "I don't want newlines in this string"); + * nping_warning(QT_2|NO_NEWLINE, "I don't want newlines in this string"); * */ -int outError(int level, const char *str, ...) { +int nping_warning(int level, const char *str, ...) { va_list list; char errstr[MAX_ERR_STR_LEN]; bool skipnewline=false; @@ -178,16 +178,16 @@ int outError(int level, const char *str, ...) { } va_end(list); return OP_SUCCESS; -} /* End of outError() */ +} /* End of nping_warning() */ /** Print regular messages to stdout. This function inserts one \n newline * automatically in every call. To avoid that behaviour it is possible to * OR the supplied level with constant NO_NEWLINE like this: * - * outPrint(VB_2|NO_NEWLINE, "I don't want newlines in this string"); + * nping_print(VB_2|NO_NEWLINE, "I don't want newlines in this string"); * */ -int outPrint(int level, const char *str, ...){ +int nping_print(int level, const char *str, ...){ va_list list; char errstr[MAX_ERR_STR_LEN]; bool skipnewline=false; @@ -219,7 +219,7 @@ int outPrint(int level, const char *str, ...){ } va_end(list); return OP_SUCCESS; -} /* End of outPrint() */ +} /* End of nping_print() */ /*****************************************************************************/ diff --git a/nping/output.h b/nping/output.h index c13f474f0..83cd42f9e 100644 --- a/nping/output.h +++ b/nping/output.h @@ -129,13 +129,13 @@ int error(const char *str, ...) int pfatal(const char *str, ...) __attribute__ ((format (printf, 1, 2))); -int outFatal(int level, const char *str, ...) +int nping_fatal(int level, const char *str, ...) __attribute__((format(printf, 2, 3))); -int outError(int level, const char *str, ...) +int nping_warning(int level, const char *str, ...) __attribute__((format(printf, 2, 3))); -int outPrint(int level, const char *str, ...) +int nping_print(int level, const char *str, ...) __attribute__((format(printf, 2, 3))); #ifdef __cplusplus diff --git a/nping/utils.cc b/nping/utils.cc index d0756c425..e21b1306b 100644 --- a/nping/utils.cc +++ b/nping/utils.cc @@ -108,7 +108,7 @@ extern NpingOps o; /** Returns true if "source" contains at least one instance of "substring" */ bool contains(const char *source, const char *substring){ if(source==NULL || substring==NULL ) - outFatal(QT_3,"contains(): NULL value received."); + nping_fatal(QT_3,"contains(): NULL value received."); if( strcasestr(source, substring) ) return true; else @@ -120,7 +120,7 @@ bool contains(const char *source, const char *substring){ * sensitive)*/ bool meansRandom(const char *source){ if(source==NULL) - outFatal(QT_3,"meansRandom(): NULL value received."); + nping_fatal(QT_3,"meansRandom(): NULL value received."); if( !strcasecmp(source, "rand") || !strcasecmp(source, "random") ) return true; else @@ -472,7 +472,7 @@ int print_hexdump(int level, const u8 *cp, u32 length){ char *str = hexdump(cp, length); if(str==NULL) return OP_FAILURE; - outPrint(level, "%s", str); + nping_print(level, "%s", str); free(str); return OP_SUCCESS; -} /* End of print_hexdump() */ \ No newline at end of file +} /* End of print_hexdump() */ diff --git a/nping/utils_net.cc b/nping/utils_net.cc index f4b7708e4..c7ce794ba 100644 --- a/nping/utils_net.cc +++ b/nping/utils_net.cc @@ -391,7 +391,7 @@ int getPacketStrInfo(const char *proto, const u8 *packet, u32 len, u8 *dstbuff, int detail; if ( dstbuff == NULL || dstlen < 512 ) - outFatal(QT_3,"safe_ippackethdrinfo() Invalid values supplied."); + nping_fatal(QT_3,"safe_ippackethdrinfo() Invalid values supplied."); if(o.getVerbosity()>=VB_2) detail=HIGH_DETAIL; @@ -412,9 +412,9 @@ int getPacketStrInfo(const char *proto, const u8 *packet, u32 len, u8 *dstbuff, else if ( o.getMode()==UDP ) return udppackethdrinfo(packet, len, dstbuff, dstlen, detail, ss_src, ss_dst); else - outFatal(QT_3, "getPacketStrInfo(): Unable to determinate transport layer protocol"); + nping_fatal(QT_3, "getPacketStrInfo(): Unable to determinate transport layer protocol"); }else{ - outFatal(QT_3, "getPacketStrInfo(): Unkwnown protocol"); + nping_fatal(QT_3, "getPacketStrInfo(): Unkwnown protocol"); } return OP_SUCCESS; } /* getPacketStrInfo() */ @@ -480,7 +480,7 @@ int getNetworkInterfaceName(u32 destination, char *dev){ struct sockaddr_in dst, src; bool result=false; if(dev==NULL) - outFatal(QT_3, "getNetworkInterfaceName(): NULL value supplied."); + nping_fatal(QT_3, "getNetworkInterfaceName(): NULL value supplied."); memset(&rnfo, 0, sizeof(struct route_nfo) ); memset(&dst, 0, sizeof(struct sockaddr_in) ); memset(&src, 0, sizeof(struct sockaddr_in) ); @@ -504,7 +504,7 @@ int getNetworkInterfaceName(struct sockaddr_storage *dst, char *dev){ struct sockaddr_storage src; bool result=false; if(dev==NULL) - outFatal(QT_3, "getNetworkInterfaceName(): NULL value supplied."); + nping_fatal(QT_3, "getNetworkInterfaceName(): NULL value supplied."); memset(&rnfo, 0, sizeof(struct route_nfo) ); memset(&src, 0, sizeof(struct sockaddr_in) ); result=route_dst(dst, &rnfo, NULL, NULL); @@ -532,13 +532,13 @@ int resolveCached(char *host, struct sockaddr_storage *ss, size_t *sslen, int pf /* Used for debug. When called with NULL,0x1337, print stats */ if(host==NULL && pf == 1337){ - outPrint(DBG_4, "resolveCached(): MISSES: %d, HITS: %d\n", misses, hits); + nping_print(DBG_4, "resolveCached(): MISSES: %d, HITS: %d\n", misses, hits); return OP_SUCCESS; } if( ss==NULL || sslen==NULL || host==NULL) - outFatal(QT_3, "resolveCached(): NULL values supplied"); + nping_fatal(QT_3, "resolveCached(): NULL values supplied"); /* First we check if we have the host already cached */ for(int i=0; i=VB_2) @@ -1131,14 +1131,14 @@ int send_packet(NpingTarget *target, int rawfd, u8 *pkt, size_t pktLen){ if(dport!=NULL) s6.sin6_port = *dport; else - outFatal(QT_3, "send_packet(): Could not determine TCP destination port."); + nping_fatal(QT_3, "send_packet(): Could not determine TCP destination port."); } else if( o.getMode()==UDP){ dport=getDstPortFromUDPHeader(pkt, pktLen); if(dport!=NULL) s6.sin6_port = *dport; else - outFatal(QT_3, "send_packet(): Could not determine UDP destination port."); + nping_fatal(QT_3, "send_packet(): Could not determine UDP destination port."); } */ @@ -1445,21 +1445,21 @@ int obtainRawSocket(){ break; case ARP: - outError(QT_2,"Warning: createRawSocket() should not be called in ARP mode."); + nping_warning(QT_2,"Warning: createRawSocket() should not be called in ARP mode."); return 0; break; default: - outFatal(QT_3, "createRawSocket(): NpingOps::getMode() does not return a valid mode. Please report this bug."); + nping_fatal(QT_3, "createRawSocket(): NpingOps::getMode() does not return a valid mode. Please report this bug."); break; } if ((rawipsd = socket(AF_INET6, SOCK_RAW, protocol)) < 0 ) - outFatal(QT_3,"Couldn't acquire IPv6 raw socket. Are you root?"); + nping_fatal(QT_3,"Couldn't acquire IPv6 raw socket. Are you root?"); }else{ if ((rawipsd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0 ) - outFatal(QT_3,"Couldn't acquire IPv4 raw socket. Are you root?"); + nping_fatal(QT_3,"Couldn't acquire IPv4 raw socket. Are you root?"); /* Tell the kernel we are including our own IP Header (call to * setsockopt passing option IP_HDRINCL) */ sethdrinclude(rawipsd); @@ -1467,7 +1467,7 @@ int obtainRawSocket(){ /* Allow broadcast addresses */ if (setsockopt(rawipsd, SOL_SOCKET, SO_BROADCAST, (const char *)&one, sizeof(int)) == -1) - outError(QT_2,"Failed to set SO_BROADCAST on raw socket."); + nping_warning(QT_2,"Failed to set SO_BROADCAST on raw socket."); return rawipsd; } /* End of obtainRawSocket() */ @@ -1513,20 +1513,20 @@ int getinterfaces_inet6_linux(if6_t *ifbuf, int max_ifaces){ memset(buffer, 0, sizeof(buffer)); if(ifbuf==NULL || max_ifaces<=0) - outFatal(QT_3,"getinterfaces_inet6_linux() NULL values supplied"); + nping_fatal(QT_3,"getinterfaces_inet6_linux() NULL values supplied"); /* TODO: Do we fatal() or should we just error and return OP_FAILURE? */ if ( !file_is_readable(PATH_PROC_IFINET6) ) - outFatal(QT_3, "Couldn't get IPv6 interface information. File %s does not exist or you don't have read permissions.", PATH_PROC_IFINET6); + nping_fatal(QT_3, "Couldn't get IPv6 interface information. File %s does not exist or you don't have read permissions.", PATH_PROC_IFINET6); if( (if6file=fopen(PATH_PROC_IFINET6, "r"))==NULL ) - outFatal(QT_3, "Failed to open %s.", PATH_PROC_IFINET6); + nping_fatal(QT_3, "Failed to open %s.", PATH_PROC_IFINET6); while( fgets(buffer,sizeof(buffer), if6file) ){ if(parsed_ifs>=max_ifaces) break; - outPrint(DBG_4, "Read %s:%d: %s\n", PATH_PROC_IFINET6, ++readlines, buffer); + nping_print(DBG_4, "Read %s:%d: %s\n", PATH_PROC_IFINET6, ++readlines, buffer); /* Check the line has the expected format ********************************/ /* Some versions of the kernel include colons in the IPv6 address, some @@ -1707,20 +1707,20 @@ int getroutes_inet6_linux(route6_t *rtbuf, int max_routes){ memset(buffer, 0, sizeof(buffer)); if(rtbuf==NULL || max_routes<=0) - outFatal(QT_3,"getroutes_inet6_linux() NULL values supplied"); + nping_fatal(QT_3,"getroutes_inet6_linux() NULL values supplied"); /* TODO: Do we fatal() or should we just error and return OP_FAILURE? */ if ( !file_is_readable(PATH_PROC_IPV6ROUTE) ) - outFatal(QT_3, "Couldn't get IPv6 route information. File %s does not exist or you don't have read permissions.", PATH_PROC_IPV6ROUTE); + nping_fatal(QT_3, "Couldn't get IPv6 route information. File %s does not exist or you don't have read permissions.", PATH_PROC_IPV6ROUTE); if( (route6file=fopen(PATH_PROC_IPV6ROUTE, "r"))==NULL ) - outFatal(QT_3, "Failed to open %s.", PATH_PROC_IPV6ROUTE); + nping_fatal(QT_3, "Failed to open %s.", PATH_PROC_IPV6ROUTE); while( fgets(buffer,sizeof(buffer), route6file) ){ if(parsed_routes>=max_routes) break; - outPrint(DBG_4, "Read %s:%d: %s\n",PATH_PROC_IPV6ROUTE, ++readlines, buffer); + nping_print(DBG_4, "Read %s:%d: %s\n",PATH_PROC_IPV6ROUTE, ++readlines, buffer); /* Check the line has the expected format ********************************/ /* Some versions of the kernel include colons in the IPv6 address, some