Date: Tue, 4 Jan 2005 21:33:01 -0800 (PST) From: neha agrawal <nehavrce@yahoo.co.in> To: freebsd-net@freebsd.org Subject: Replaying a TCP connection Message-ID: <20050105053301.85548.qmail@web8404.mail.in.yahoo.com>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
hello!
i want to implement smtp protocol on the same
machine.i have a libpcap trace file..in which i have
captured mail traffic..(single session).and i want to
develop a program which can read this trace file..and
communicate with the smtp server...
first packet is Sync packet in trace file..so i
want to send it to smtp server...and then i want my
progrem to handle the reply sent by server..(say it
sent Syn-Ack) anf then my prgm should reply
accordingly..
for doing this i am using PF_PACKET , SOCK_RAW
and using sendto function...i am sending the
packet..im able to see it through tcpdump...but
theserver is not replying...why??i am wrking with
linux Redhat 9 kernel 2.4.20-8
(...if u r familiar with flowreplay tool..i
want to do something similar ...but mine is single
session..so less complicated...)
attching source code...
do let me know..if i am on correct track...
thnks
Neha
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
[-- Attachment #2 --]
/*th a FIN flag and pass it through a raw socket.
*
* Thamer Al-Herbish shadows@whitefang.com
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in_systm.h>
#if defined(LINUX)
#include <linux/ip.h>
#include <linux/tcp.h>
#else
#include <netinet/ip.h>
#include <netinet/tcp.h>
#endif
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <rawsock_utils.h>
int main(int argc,char *argv[])
{
unsigned char packet[
#if !defined(LINUX)
sizeof(struct ip) +
#else /* LINUX */
sizeof(struct iphdr) +
#endif /* LINUX */
sizeof(struct tcphdr)];
struct sockaddr_in mysocket;
unsigned short sport, dport;
struct in_addr saddr, daddr;
struct tcphdr *tcp;
unsigned long seq, ack;
int sockd, on = 1;
if(argc < 5) {
fprintf(stderr,"usage: %s source_port source_address dest_port dest_address\n",
argv[0]);
exit(1);
}
sport = (unsigned short)atoi(argv[1]);
saddr.s_addr = inet_addr(argv[2]);
dport = (unsigned short)atoi(argv[3]);
daddr.s_addr = inet_addr(argv[4]);
if((sockd = socket(AF_INET,SOCK_RAW,IPPROTO_RAW)) < 0) {
perror("socket");
exit(1);
}
if(setsockopt(sockd,IPPROTO_IP,IP_HDRINCL,(char *)&on,sizeof(on)) < 0) {
perror("setsockopt");
exit(1);
}
/* Very bad random sequence number generator */
srand(getpid());
seq = rand()%time(NULL);
ack = rand()%time(NULL);
ip_gen(packet,IPPROTO_TCP,saddr,daddr,sizeof(packet));
#if !defined(LINUX)
tcp = (struct tcphdr *)(packet + sizeof(struct ip));
tcp_gen((char *)tcp,sport,dport,seq,ack);
#if !defined(SOLARIS_CKSUM_BUG)
tcp->th_sum = trans_check(IPPROTO_TCP,(char *)tcp,
sizeof(struct tcphdr),
saddr,
daddr);
#else /* SOLARIS_CKSUM_BUG */
tcp->th_sum = sizeof(struct tcphdr);
#endif /* SOLARIS_CKSUM_BUG */
#else /* LINUX */
tcp = (struct tcphdr *)(packet + sizeof(struct iphdr));
tcp_gen((char *)tcp,sport,dport,seq,ack);
#if !defined(SOLARIS_CKSUM_BUG)
tcp->check = trans_check(IPPROTO_TCP,(char *)tcp,
sizeof(struct tcphdr),
saddr,
daddr);
#else /* SOLARIS_CKSUM_BUG */
tcp->check = sizeof(struct tcphdr);
#endif /* SOLARIS_CKSUM_BUG */
#endif /* LINUX */
memset(&mysocket,'\0',sizeof(mysocket));
mysocket.sin_family = AF_INET;
mysocket.sin_port = htons(dport);
mysocket.sin_addr = daddr;
if(sendto(sockd,&packet,sizeof(packet),0x0,(struct sockaddr *)&mysocket,
sizeof(mysocket)) != sizeof(packet)) {
perror("sendto");
exit(1);
}
exit(0);
}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050105053301.85548.qmail>
