--- tcp.c.orig Wed Nov 14 11:56:01 2001 +++ tcp.c.new Wed Nov 14 12:03:52 2001 @@ -43,7 +43,6 @@ struct arglist ret; if(arg_get_type(args, "ip")>=0) { - struct pseudohdr pseudoheader; u_char * pkt; struct ip * ip = arg_get_value(args, "ip"); char * data = arg_get_value(args, "data"); @@ -81,14 +80,15 @@ tcp->th_dport = htons((unsigned short)atoi(prompt(globals, "th_dport : "))); if((arg_get_type(args, "th_seq"))>=0) - tcp->th_seq = htonl((u_long)atol(arg_get_value(args, "th_seq"))); + tcp->th_seq = htonl(strtoul(arg_get_value(args, "th_seq"), NULL, 0)); else - tcp->th_seq = htonl((u_long)atol(prompt(globals, "th_seq : "))); + tcp->th_seq = htonl(strtoul(prompt(globals, "th_seq : "), NULL, 0)); if((arg_get_type(args, "th_ack"))>=0) - tcp->th_ack = htonl((u_long)atol(arg_get_value(args, "th_ack"))); - else - tcp->th_ack = htonl((u_long)atol(prompt(globals, "th_ack : "))); + tcp->th_ack = htonl(strtoul(arg_get_value(args, "th_ack"), NULL, 0)); + else { + tcp->th_ack = htonl(strtoul(prompt(globals, "th_ack : "), NULL, 0)); + } if((arg_get_type(args, "th_x2"))>=0) tcp->th_x2 = (u_char)atoi(arg_get_value(args, "th_x2")); @@ -126,7 +126,18 @@ if(!tcp->th_sum) { + struct pseudohdr pseudoheader; + char * tcpsumdata = (char *)malloc( sizeof( struct pseudohdr ) + + ( len % 2 ? len + 1 : 0 ) ); struct in_addr source, dest; + + if( tcpsumdata == NULL ) { + printf("forge_tcp_packet : Error : tcpsumdata malloc failed \n"); + ret.value = NULL; + ret.type = 0; + return(ret); + } + source.s_addr = ip->ip_src.s_addr; dest.s_addr = ip->ip_dst.s_addr; @@ -135,10 +146,13 @@ pseudoheader.daddr.s_addr=dest.s_addr; pseudoheader.protocol=IPPROTO_TCP; - pseudoheader.length=htons(sizeof(struct tcphdr))+len; + pseudoheader.length=htons(sizeof(struct tcphdr)+len); bcopy((char *) tcp,(char *) &pseudoheader.tcpheader,sizeof(struct tcphdr)); - tcp->th_sum = np_in_cksum((unsigned short *)&pseudoheader,12+sizeof(struct - tcphdr)+len); + /* fill tcpsumdata with data to checksum */ + bcopy((char *) &pseudoheader, tcpsumdata ,sizeof(struct pseudohdr)); + bcopy((char *) data, tcpsumdata + sizeof(struct pseudohdr), len ); + tcp->th_sum = np_in_cksum((unsigned short *)tcpsumdata,12+sizeof(struct tcphdr) + len ); + free( tcpsumdata ); } ret.type = VAR_PKT|PKT_IP|PKT_TCP; ret.value = pkt;