in my source codes, there is the following snippet:
while ((cmd=getchar()) != EOF)
{
switch(cmd)
{
case '1':
printf("pls input the data to be sent:
");
char data[100];
gets(data);
send_data(sd_cli, data, strlen(data), &svr_addr);
pcap_packet = pcap_next(pcap_handler, &pcap_header);
if(pcap_packet !=NULL)
printf("capture one packet with length of %d
", pcap_header.len);
analyze_pcap_pkt(pcap_packet, &ipid, &temp_port1, &temp_port2, &seq, &ack_seq);
temp_seq = seq;
seq = ack_seq;
ack_seq = temp_seq;
ipid++;
break;
case '2':
printf("old ack is %x
", ack_seq);
printf("pls input the seq plus amount:
");
char amount[6];
gets(amount);
ack_seq= ack_seq+atoi(amount);
printf("new akc is %x
", ack_seq);
send_ack(sd_raw, &svr_addr, lo_ipaddr, svr_ipaddr, htons(src_port), htons(dst_port), htons(ipid), htonl(seq), htonl(ack_seq));
ipid++;
break;
case '4':
send_rst(sd_raw, &svr_addr, lo_ipaddr, svr_ipaddr, htons(ipid), htons(src_port), htons(dst_port), htonl(seq), htonl(ack_seq));
break;
}
}
when I run the program, the output is:
old ack_seq is ab2429c6
pls input the seq plus amount:
new ack_seq is ab2429c6
sendto ack packet
: Invalid argument
BTW: the send_ack
, send_rst
functions use raw socket to send packets.
it seems that the gets()
function doesn't get excuted, what is wrong with this?
thanks!