Link to home
Start Free TrialLog in
Avatar of Subrat (C++ windows/Linux)
Subrat (C++ windows/Linux)Flag for India

asked on

How to get all pings generated by an application while it's downloading or installing from internet?

Hi all,
I need to know 'How to get all pings generated by an application while it's downloading or installing from internet?' using C++ win32 APIs. Looks for a quick response. It's _URGENT_
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What do you mean by "get" ?
What do you mean by "pings" ?
Avatar of Subrat (C++ windows/Linux)

ASKER

// What do you mean by "get" ?
It's not related to GET/POST request. You can assume as print
So, you want a log of all "pings". What do you mean by "pings" ? What information do you want to log ?
name of the site(ex:www.myname.com), ip adress , RLZ params etc...
What do you mean by "pings" ?
Ex:
Go to adobe reader site ()http://get.adobe.com/reader/) and download it. At the same time start HttpAnalyzer. It can show us URL, time, which type of request it's and so on.
I need the same functionality, how exactly to write code to achieve this using C++ win32.
 
Thanks
Subrat
>> I need the same functionality, how exactly to write code to achieve this using C++ win32.
Apologies for repeating myself but did you look at Wireshark? The source code is available, which could be modified for your specific needs.
>> Go to adobe reader site ()http://get.adobe.com/reader/) and download it. At the same time start HttpAnalyzer. It can show us URL, time, which type of request it's and so on.

So, you mean any traffic, not just ping's (http://linux.die.net/man/8/ping).


>> I need the same functionality, how exactly to write code to achieve this using C++ win32.

Writing this yourself is not straightforward, so consider evilrix' suggestion.

If you really want to write this yourself, you whould start reading up on network protocols (specifically TCP/IP, by reading the book "TCP/IP Illustrated" by W. Richard Stevens eg.), socket programming (http://beej.us/guide/bgnet/), pcap (http://www.tcpdump.org/pcap.htm), etc.
But, be prepared to put in a lot of time to get this to work.
Hi Evilrix,
I have started working on WinPCap lib. Wireshark is also using it. I may need more clarification on WinPCap, so now I'm not closing this thread.

Thanks
Subrat
I'm getting compilation error due to winsock.h. I also replaced it with winshock2.h but still getting same.Plz have alook on my Log file by which u can identify the problem
BuildLog.htm
The issue is to do with header order dependencies.

IIRC you have to include the winsock header before windows.h

I'll see if I can find the MSDN article that explains this.
Here we go, I think this is the solution you need: http://msdn.microsoft.com/en-us/library/ms737629(VS.85).aspx
My order is as follows

#include "stdafx.h"
#include "pcap.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#ifndef WIN32
#include "sys/socket.h"
#include "netinet/in.h"
#else
#include <winsock.h>
#endif
Did you read the link I posted? It also suggests to define WIN32_LEAN_AND_MEAN to prevent historical winsock symbols from being defined.
WIN32_LEAN_AND_MEAN is already defined.
 
The stdafx.h probably includes windows.h
One  Q.
 In the log file it is clear tht  my application is using vc6 sdk (c:\program files\microsoft sdks\windows\v6.0a\include\). Is it a problem?
I want to know why it's searching in this include folder by default? Where is the setting?
I've seen that this is not added by me explicitly.  
>>The stdafx.h probably includes windows.h
No. Already seen.
After all these modifications, I'm sure you don't get the same error message, right ?

Could you post the complete latest code, as well as the errors you are currently getting ?
Problem solved......
It was in pcap-stdinc.h. (_WINSOCKAPI_   macro).
Hi infinity,
One more Q.
In the log file I attached, it is clear tht  my application is using vc6 sdk (c:\program files\microsoft sdks\windows\v6.0a\include\).

I want to know why it's searching in this include folder by default? Where is the settings?

I've seen that this path is not added by me explicitly.
Subrat2009,

Since that's unrelated to the original question it should really be asked as a new question.
https://www.experts-exchange.com/help.jsp?hi=23

The default search paths are set in the compiler settings.

Tools | Options >> Projects and Solutions >> VC++ Directories

Thanks.
Hi all,
 Now problem is
While control reaches at pacp_loop() I'm getting assert,


pcap_compile(adhandle, &fcode, NULL, 1, netmask)
pcap_setfilter(adhandle, &fcode)
pcap_freealldevs(alldevs)
pcap_loop(adhandle, 0, packet_handler2, NULL);


I hope this much info are enough. If u want the complete code then I'll post.

Unable to upload ASSERT IMAGE So find the
Asser MSG:

file: f:\dd\vctools\crt_bld\self_x86\src\isctype.c
Line: 56
Expression: (unsigned)(c+1) <= 256


But I don't think problem in this file!

Plz help me!

Thanks,
Subrat.
If I was to guess (and the truth is I am guessing) it looks like there is an assert that is checking that the value of an unsigned  integer is between 1 and 256. I'd suggest one or more of your parameters being passed into one of the pcap functions is incorrect.
Hi evilrix/Infinity,

Can you plz go through the following link and let me know what exactly the problem why getting ASSERTS instead  getting URL names.

http://www.codeproject.com/KB/IP/URLLogger.aspx?msg=2288055#xx2288055xx


FYI:
I changed like below
UrlSniffer::UrlSniffer()
{
      this->SetFilterString("host www.yahoo.com"); //tcp port 8080 or tcp port 1080

}


Thanks,
Subrat.
Hi evilrix/Infinity,

Please have a look on it.

Thanks & Regards,
Subrat
>> pcap_loop(adhandle, 0, packet_handler2, NULL);

Don't use 0 as the second argument. Either provide a positive value to sniff a given amount of packets, or provide a negative value (-1) if you want to sniff packets until an error occurs.


As evilrix already told you before - this is no longer directly related to your original question, so if you have further problems, you should probably create new questions for them.
Hi Evilrix & Infinity,
   Really helped me! Thanks a lot. I'll open a new Q which is related  to this thread and wish u should help me. and also later I'll copy paste the entire code here or write a blog on pcap lib usages in simplest way.

Thanks,
Subrat.
Hi
Plz hav a look on Q. ID:26164071

Thanks,
Subrat.