1
0
mirror of https://github.com/nmap/nmap.git synced 2026-02-01 19:19:09 +00:00

Merge r27122 from nmap-npingchanges: Changed names for output funtions. outPrint() -> nping_print(); outFatal() -> nping_fatal() ; outError() -> nping_warning(). This change is completely irrelevant but I personally hate the names I chose the first time and I thought I'd change them to something better.

This commit is contained in:
luis
2013-03-29 12:44:51 +00:00
parent 5c9a2b54ce
commit f64b3fafe8
16 changed files with 714 additions and 714 deletions

View File

@@ -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<N<2^16.");
nping_fatal(QT_3, "Invalid echo port. Value must be 0<N<2^16.");
}
} else if (optcmp(long_options[option_index].name, "once")==0 ){
o.setOnce(true);
@@ -914,30 +914,30 @@ char errstr[256];
/* Inter-packet delay */
} else if (optcmp(long_options[option_index].name, "delay") == 0 ){
if ( (l= tval2msecs(optarg)) == -1)
outFatal(QT_3,"Invalid delay supplied. Delay must be a valid, positive integer or floating point number.");
nping_fatal(QT_3,"Invalid delay supplied. Delay must be a valid, positive integer or floating point number.");
else if(l<0)
outFatal(QT_3,"Invalid delay supplied. Delays can never be negative.");
nping_fatal(QT_3,"Invalid delay supplied. Delays can never be negative.");
if (l >= 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;
}

View File

@@ -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_len<AES_KEY_SIZE)
@@ -152,13 +152,13 @@ int Crypto::aes128_cbc_encrypt(u8 *inbuff, size_t inlen, u8 *dst_buff, u8 *key,
EVP_CIPHER_CTX_set_padding(&ctx, 0);
int result=OP_SUCCESS;
if( EVP_EncryptInit(&ctx, EVP_aes_128_cbc(), key, iv)==0 ){
outPrint(DBG_4, "EVP_EncryptInit() failed");
nping_print(DBG_4, "EVP_EncryptInit() failed");
result=OP_FAILURE;
}else if( EVP_EncryptUpdate(&ctx, dst_buff, &flen, inbuff, (int)inlen)==0 ){
outPrint(DBG_4, "EVP_EncryptUpdate() failed");
nping_print(DBG_4, "EVP_EncryptUpdate() failed");
result=OP_FAILURE;
}else if( EVP_EncryptFinal(&ctx, dst_buff+flen, &flen2)==0 ){
outPrint(DBG_4, "EVP_EncryptFinal() failed");
nping_print(DBG_4, "EVP_EncryptFinal() failed");
result=OP_FAILURE;
}
EVP_CIPHER_CTX_cleanup(&ctx);
@@ -173,7 +173,7 @@ int Crypto::aes128_cbc_encrypt(u8 *inbuff, size_t inlen, u8 *dst_buff, u8 *key,
int Crypto::aes128_cbc_decrypt(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_len<AES_KEY_SIZE)
@@ -187,13 +187,13 @@ int Crypto::aes128_cbc_decrypt(u8 *inbuff, size_t inlen, u8 *dst_buff, u8 *key,
EVP_CIPHER_CTX_set_padding(&ctx, 0);
int result=OP_SUCCESS;
if( EVP_DecryptInit(&ctx, EVP_aes_128_cbc(), key, iv)==0 ){
outPrint(DBG_4, "EVP_DecryptInit() failed");
nping_print(DBG_4, "EVP_DecryptInit() failed");
result=OP_FAILURE;
}else if( EVP_DecryptUpdate(&ctx, dst_buff, &flen1, inbuff, (int)inlen)==0 ){
outPrint(DBG_4, "EVP_DecryptUpdate() failed");
nping_print(DBG_4, "EVP_DecryptUpdate() failed");
result=OP_FAILURE;
}else if( EVP_DecryptFinal(&ctx, dst_buff+flen1, &flen2)==0 ){
outPrint(DBG_4, "OpenSSL bug: it says EVP_DecryptFinal() failed when it didn't (%s).",
nping_print(DBG_4, "OpenSSL bug: it says EVP_DecryptFinal() failed when it didn't (%s).",
ERR_error_string(ERR_peek_last_error(), NULL));
/* We do not return OP_FAILURE in this case because the
* EVP_DecryptFinal() function seems to be buggy and fails when it shouldn't.
@@ -233,7 +233,7 @@ int Crypto::aes128_cbc_decrypt(u8 *inbuff, size_t inlen, u8 *dst_buff, u8 *key,
int Crypto::generateNonce(u8 *dst_buff, size_t bufflen){
outPrint(DBG_4, "%s()", __func__);
nping_print(DBG_4, "%s()", __func__);
if(dst_buff==NULL || bufflen<=0)
return OP_FAILURE;
#ifdef HAVE_OPENSSL
@@ -249,7 +249,7 @@ int Crypto::generateNonce(u8 *dst_buff, size_t bufflen){
#define TIMES_KEY_DERIVATION 1000
u8 *Crypto::deriveKey(const u8 *from, size_t fromlen, size_t *final_len){
outPrint(DBG_4, "%s()", __func__);
nping_print(DBG_4, "%s()", __func__);
if(from==NULL || fromlen==0)
return NULL;
@@ -262,7 +262,7 @@ u8 *Crypto::deriveKey(const u8 *from, size_t fromlen, size_t *final_len){
EVP_MD_CTX_init(&ctx);
if( EVP_MD_size(EVP_sha256()) != SHA256_HASH_LEN )
outFatal(QT_2, "OpenSSL is broken. SHA256 len is %d\n", EVP_MD_size(EVP_sha256()) );
nping_fatal(QT_2, "OpenSSL is broken. SHA256 len is %d\n", EVP_MD_size(EVP_sha256()) );
/* Compute the SHA256 hash of the supplied buffer */
EVP_DigestInit(&ctx, EVP_sha256());

View File

@@ -134,11 +134,11 @@ int EchoClient::cleanup(){
* sends the appropriate packet specs and handles raw packet transmission and
* NEP_ECHO reception and display. */
int EchoClient::start(NpingTarget *target, u16 port){
outPrint(DBG_4, "%s(%p, %u)", __func__, target, port);
nping_print(DBG_4, "%s(%p, %u)", __func__, target, port);
/* Init Nsock in the probe engine */
if( this->probe.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(pktlen<NEP_ECHO_MIN_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_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(recvbytes<plen){
memcpy(this->lasthdr, 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(recvbytes<plen){
memcpy(this->lasthdr, 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);
}

View File

@@ -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() */
} /* End of decrypt() */

File diff suppressed because it is too large Load Diff

View File

@@ -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; i<tportcount; i++){
if( this->target_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;

View File

@@ -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() */

View File

@@ -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() */

View File

@@ -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() */

View File

@@ -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);

View File

@@ -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);

View File

@@ -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

View File

@@ -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() */
/*****************************************************************************/

View File

@@ -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

View File

@@ -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() */
} /* End of print_hexdump() */

View File

@@ -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<MAX_CACHED_HOSTS && i<cached_count; i++){
@@ -546,14 +546,14 @@ int resolveCached(char *host, struct sockaddr_storage *ss, size_t *sslen, int pf
*sslen=archive[i].sslen;
memcpy(ss, &(archive[i].ss) , *sslen);
hits++;
outPrint(DBG_4, "resolveCached(): Cache hit %d for %s\n", hits, host);
nping_print(DBG_4, "resolveCached(): Cache hit %d for %s\n", hits, host);
return OP_SUCCESS;
}
}
/* Cache miss */
misses++;
outPrint(DBG_4, "resolveCached(): Cache miss %d for %s\n", misses, host);
nping_print(DBG_4, "resolveCached(): Cache miss %d for %s\n", misses, host);
if( (result=resolve(host, 0, ss, sslen, pf)) == 0 ){
@@ -605,7 +605,7 @@ int resolveCached(char *host, struct sockaddr_storage *ss, size_t *sslen, int pf
//return OP_SUCCESS;
}else{
outError(QT_2, "Error resolving %s\n",host);
nping_warning(QT_2, "Error resolving %s\n",host);
return OP_FAILURE;
}
} /* End of resolveCached() */
@@ -626,20 +626,20 @@ struct hostent *gethostbynameCached(char *host){
int i=0;
if( host==NULL)
outFatal(QT_3, "gethostbynameCached(): NULL values supplied");
nping_fatal(QT_3, "gethostbynameCached(): NULL values supplied");
/* First we check if we have the host already cached */
for(i=0; i<MAX_CACHED_HOSTS && i<cached_count; i++){
if( !strcasecmp( archive[i].hostname , host ) ){ /* Cache hit */
hits++;
outPrint(DBG_4, "gethostbynameCached(): Cache hit %d for %s", hits, host);
nping_print(DBG_4, "gethostbynameCached(): Cache hit %d for %s", hits, host);
return archive[i].h;
}
}
/* Cache miss */
misses++;
outPrint(DBG_4, "gethostbynameCached(): Cache miss %d for %s", misses, host);
nping_print(DBG_4, "gethostbynameCached(): Cache miss %d for %s", misses, host);
if( (result=gethostbyname(host) ) != NULL ){
@@ -828,7 +828,7 @@ char *MACtoa(u8 *mac){
const char *arppackethdrinfo(const u8 *packet, u32 len, int detail){
static char protoinfo[512];
if (packet==NULL)
outFatal(QT_3, "arppackethdrinfo(): NULL value supplied");
nping_fatal(QT_3, "arppackethdrinfo(): NULL value supplied");
if( len < 28 )
return "BOGUS! Packet too short.";
u16 *htype = (u16 *)packet;
@@ -870,7 +870,7 @@ int arppackethdrinfo(const u8 *packet, u32 len, u8 *dstbuff, u32 dstlen){
int detail=0;
if ( dstbuff == NULL || dstlen < 512 )
outFatal(QT_3,"safe_arppackethdrinfo() Invalid values supplied.");
nping_fatal(QT_3,"safe_arppackethdrinfo() Invalid values supplied.");
/* Determine level of detail in packet output from current verbosity level */
if(o.getVerbosity()>=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