Nmap Development mailing list archives
Scanning Localhost
From: Wasim <wasim.khan () gmail com>
Date: Wed, 29 Nov 2006 16:29:08 +1200
I have encountered a problem while writing code for scanning Localhost. The
problem is i did'nt get the destination port and source port of reply
correct. For e.g. if i set source port =62144 and destination port=22 then
i must get reply source port = 22 and reply destination port = 62144, but
that is not the case. What can be the problem??? can any body help??? I
googled it but couldn't find any thing.
Here i'm putting the code where i'm sniffing:
struct pcap_pkthdr header;
const u_char *packet;
struct libnet_ipv4_hdr *ipHdr;
struct libnet_tcp_hdr *tcpHdr;
int reply_dstport = 0;
int reply_sport =0 ;
int timeout = 3;
time_t start;
start = time(NULL);
/* capture packets until a timeout occurs or the required packet is
received */
while ((time(NULL)-start) < timeout)
{
packet = pcap_next(pcapHandle, &header);
if (packet == NULL)
{
continue;
}
else
{
ipHdr = (struct libnet_ipv4_hdr *)(packet + 14);
tcpHdr = (struct libnet_tcp_hdr *)(packet + 14 + (ipHdr->ip_hl << 2));
/* if ip packet is not from the expected host then skip this packet */
if ((ipHdr->ip_src.s_addr != destination_ip))
continue;
cout << "IP of request and reply is Identical" << endl;
int tprotocol; //transport protocol like tcp ,udp tcp 0x06
tprotocol = ipHdr->ip_p;
if(tprotocol == 0x06)
{
/*here the problem occurs */
reply_sport = ntohs(tcpHdr->th_sport);
reply_dstport = ntohs(tcpHdr->th_dport);
cout << "source port (reply) = " << reply_sport << endl;
cout << "dest port (reply) = " << reply_dstport << endl;
}
}
}
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org
Current thread:
- Scanning Localhost Wasim (Nov 28)
