|
Hi,
I'm not using this code but I'm using something similar. I need to get the IP address of where I'm listening from. However, the inet_ntoa command always returns IP address as 0.0.0.0.
here are parts of the code... please let me know if I'm doing something wrong. I'm using Visual Studio C++. Is it possible that I might be missing a header file or something? I think it would give an error if that was the case. I have this in my code: #pragma comment(lib, "Ws2_32.lib")
Thanks!
SOCKADDR_IN recv_addr;
SOCKET sock;
WSADATA data;
if (WSAStartup(MAKEWORD(2,2), &data) != 0) return(0);
int ret;
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (!sock)
{
WSACleanup();
return(0);
}
recv_addr.sin_family = AF_INET;
recv_addr.sin_addr.s_addr = INADDR_ANY;
recv_addr.sin_port = htons(APP_PORT);
ret = bind(sock, (SOCKADDR *)&recv_addr, sizeof(SOCKADDR));
if (ret)
{
WSACleanup();
return(false);
}
case WM_SOCKETREAD:
{
SOCKADDR from;
char buffer[256];
int len = sizeof(SOCKADDR);
memset(buffer, '\0', 256);
recvfrom(sock, buffer, 256, 0, &from, &len);
SetDlgItemText(hDlg, IDC_MESSAGE, buffer);
char* Recv_IP= ReadIP();
}break;
char* ReadIP()
{
int length = sizeof(recv_addr);
getsockname(sock, (SOCKADDR*)&recv_addr, &length);
MessageBox(hDlg, inet_ntoa((in_addr)recv_addr.sin_addr), "IP Address", MB_OK);
return(inet_ntoa((in_addr)recv_addr.sin_addr));
}
|
|
|
|
|
Hi;
I catch only traffic sent to me, but not sent from me. This problem appeared only on XP SP2. Do you have any idea how to fix this, or we just drop it
Thanks;
|
|
|
|
|
i download the code but i couldn't run the code what should i do....
plz help..
ujjwal
|
|
|
|
|
Did you manage to compile the code?
What was the error message?
Eran Aharonovich (eran.aharonovich@gmail.com )
Noviway
|
|
|
|
|
i did with borland c++ compiler do i need visual c++...
do u have idea to converts packets's data in readable form...i am trying it with java...and got the result in hexadecimal form and so on..
ujjwal
|
|
|
|
|
i am new to mfc c++ and i really need help
Instead of displaying the mac and ip address, i want to display the number of packets. And when the packets reach 50 i want it auto delete.
hope to hear from the experts soon. thanks
|
|
|
|
|
I can see all the traffic I want except if the message is split in multiple fragments. E.g. I ping an IP with 2500 bytes of data. It seems that the WSARecv() function does not return. It keeps on blocking, waiting for data (the next frame that doesn't have the more fragments bit on). Did I miss something here?
-----------------------
"Hey, Eddie, can I pour you a beer?"
"A little early, isn't it, Richy?"
"For a beer?"
"No, for stupid questions."
|
|
|
|
|
I've a problem of getting inbound packets only under SP2, I knew from MSKB that only sending raw sockets is denied from SP2, but all we have here is recieving, so what's wrong (p.s. All sniffers do that, not just yours)
|
|
|
|
|
I can capture only the responses not the messages in contrary to your screenshot, what is wrong, I hope you respond fast, as time is critical with me. I use your tool in protocol analysis
Thanx in advance.
|
|
|
|
|
Hi,
Does this code shows all the IPs of all computers in a local network?
///////////////////////////////////////////////////////////////////////
// For Win32. link with wsock32.lib :
WSAData wsa1;
if (WSAStartup(MAKEWORD(1, 1), &wsa1) != 0)
return -1;
char shostname[255];
int e;
e=gethostname(shostname, sizeof(shostname));
if (e != 0) {
e= WSAGetLastError ();
return -1;
}
struct hostent *phost = gethostbyname(shostname);
if (phost == 0)
return -1;
for (int i = 0; phost->h_addr_list[i] != 0; ++i) {
struct in_addr addr;
memcpy(&addr, phost->h_addr_list[i], sizeof(struct in_addr));
//ip address is inet_ntoa(addr)
char oip[50];
strcpy(oip,inet_ntoa(addr));
//m_server.AppendText(oip);
}
////////////////////////////////////////////////////////////////
If the answer is no, So what can I do?
When I test some codes they only gave me the Ips of computers that were
configured with Network Setup Wizard.
Please Help me!
Thanks.
|
|
|
|
|
MSDN says:
BOOL GetIpAddress(char *hostname)
{
WCHAR msg[128];
HOSTENT *lpHost=NULL;
struct sockaddr_in dest;
lpHost = gethostbyname(hostname);
if (lpHost == NULL)
{
wsprintf(msg, L"gethostbyname failed: %d", WSAGetLastError());
MessageBox(NULL, msg, NULL, MB_OK);
}
else
{
for(int i=0; lpHost->h_addr_list[i] != NULL ;i++)
{
memcpy(&(dest.sin_addr), lpHost->h_addr_list[i],
lpHost->h_length);
wsprintf(msg, L"IP address is: '%S'",
inet_ntoa(dest.sin_addr));
MessageBox(NULL, msg, L"IP Address", MB_OK);
}
}
return 0;
}
|
|
|
|
|
|
|
I am very much intersted in writing a packet sniffer myself. As I am novice in this area can anybody advice me as to how should I begin and proceed.
s
|
|
|
|
|
Any idea to make it work in Win98
Thanks
|
|
|
|
|
You can't do this in 98 using Winsock.
You must use other libraries like WinPCap
|
|
|
|
|
Hi,
I have downloaded your article and given 5/5. I have understood most of them, but it would be quite good if you can elaborate on the following functions.
bool CSnifferDlg::ParseTCPPacket(const CString& source, const CString& destination, TCP_HDR* pTCPHeader, char* pData, unsigned long len )
and structure
struct Session
{
unsigned int sourcePort, destPort;
CString sourceIP, destIP;
Session* pOtherSide;
tcp_seq ISN;
DWORD len;
};
I will be grateful if you can give some links on the content. I am currently working on such a project. I am finding it hard to get information about the IP data grams and other headers. Also if any book on the subject that you can suggest will be helpful.
Thanking you,
Sanjit.
|
|
|
|
|
A conversation between 2 computers must have 2 sessions:
One holds the data that computerA sent and the other one holds the
data which computerB sent. Together they make a conversation.
The ip header contains the source ip address and the destination.
The TCP header contains the port information ( source and destination )
and a unique id for each packet.
I connect one session to the other by using the Session pointer ( pOtherSide variable ).
And of course, each session has its length.
|
|
|
|
|
You placed your article under C++/MFC folder, however it seems that your project is developed under .NET. Since I don't have .NET studio installed. is it possible to get the C++/MFC version of the project? Also , if I'm right, and your project is .NET, I would suggest reconsidering the project location on server.
|
|
|
|
|
Do not copy the project as a whole but copy the files needed instead.
|
|
|
|
|
I know this site is a MS focused website, but.. Isn't it better to use UNIX alike calls?, such as socket(), recv(), ... These seem to be faster and a LOT less overhead. - Run the tool through a debugger and you'll see..
Plus, the program seems to freeze - as a while() loop will use 99% of your CPU.. Does working with threads can get rid of this?
Thanks,
Michael
"live life one cpu cycle at a time".
|
|
|
|
|
No, threads won't help you. You must do a recv all the time, there are no other notifications you can get. you must do that yourself.
|
|
|
|
|
Oops, though you were using no threads at all.. but you are
My bad
"live life one cpu cycle at a time".
|
|
|
|
|
I think it better to use Thread,when i find some time ,i like to rewrite your Software and article with you ,if you don't mind
Really your are Very Genius
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
|