Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
my requirement is Ethernet with self test module using pining programs if any one have idea just let me know or help me out

What I have tried:

/*.cpp*/
#include "pch.h"
#include "MGTS.h"
#include "CUtilitiesTab.h"
#include "afxdialogex.h"
#define STRICT
#include <tchar.h>
#include <windows.h>
#include <winsock2.h>
#include <iphlpapi.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WIN32_LEAN_AND_MEAN

void CUtilitiesTab::OnBnClickedCheck2()
{
	<pre>int rc;
	IPAddr ia;
	MessageBeep(1000);
	UpdateData(TRUE);
	ia = inet_addr(m_ip_address);
	rc = NewPing(ia, (ULONG*)&m_hops_count, (ULONG*)&m_rtt);
	if (rc == 0)
		m_selftestresult.SetWindowTextW(_T("pass"));
	else			
		m_selftestresult.SetWindowTextW(_T("Host not responding or no route, rc = %d", rc));
	UpdateData(FALSE);
	MessageBeep(1000);
	return;

}



/*.h*/ hearder file



class CUtilitiesTab : public CDialogEx
{
	DECLARE_DYNAMIC(CUtilitiesTab)

public:
	CUtilitiesTab(CWnd* pParent = nullptr);   // standard constructor
	virtual ~CUtilitiesTab();

	

// Dialog Data
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_UTILITIES };
#endif

protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()
public:
	

	

	/*Ethernet*/

	IPHLPAPI_DLL_LINKAGE BOOL GetRTTAndHopCount(
		IPAddr DestIpAddress,
		PULONG HopCount,
		ULONG  MaxHops,
		PULONG RTT
	);
    CString   m_ip_address[4];
	long   m_hops_count;
	long	m_rtt;
	afx_msg void OnBnClickedCheck2();

};


I am geting below error ,but when i put
#pragma warning(disable:4996)
it will remove the below error .
Error C4996 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings MGTS


as if now i am geting this error ..

S
Error	LNK2019	unresolved external symbol __imp__GetRTTAndHopCount@16 referenced in function "int __cdecl NewPing(unsigned long,unsigned long *,unsigned long *)" (?NewPing@@YAHKPAK0@Z	1	



please someone help me'
Posted
Updated 18-Aug-20 19:17pm
v2
Comments
Richard MacCutchan 19-Aug-20 3:09am    
You are missing a library in your linker parameters. Check the documentation for the GetRTTAndHopCount function.
Member 14837073 20-Aug-20 2:38am    
I tried but same issue i am facing

1 solution

This help?
Ping for Windows[^]
 
Share this answer
 
Comments
Rick York 17-Aug-20 11:57am    
Good heavens - what a horrible article.
OriginalGriff 17-Aug-20 12:00pm    
It's nineteen years old, and we've moved on a lot since then!
Rick York 17-Aug-20 13:12pm    
For the most part I would agree. I still see exceptions on occasion. The most common I see lately are articles that are little more than a user manual for the program. The code is only mentioned in passing. It's a been a little while since the last of those so I think the trend for fewer of them is a positive one.
Member 14837073 18-Aug-20 3:16am    
/*.cpp/*
void CUtilitiesTab::OnBnClickedCheck2()
{
int rc;
IPAddr ia;
MessageBeep(1000);
UpdateData(TRUE);
ia = inet_addr(m_ip_address);
rc = NewPing(ia, (ULONG*)&m_hops_count, (ULONG*)&m_rtt);
if (rc == 0)
m_selftestresult.SetWindowTextW(_T("pass"));
else
m_selftestresult.SetWindowTextW(_T("Host not responding or no route, rc = %d", rc));
UpdateData(FALSE);
MessageBeep(1000);
return;

}
int NewPing(IPAddr ia, ULONG* hops_count, ULONG* rtt)
{
boolean IsOk;

IsOk = GetRTTAndHopCount(ia, hops_count, 128, rtt); //the iphlpapi call
if (IsOk == TRUE) return 0;
return GetLastError();
}

/*.h*/


#pragma once


// CUtilitiesTab dialog

//#ifndef __SERIAL_H__

class CUtilitiesTab : public CDialogEx
{
DECLARE_DYNAMIC(CUtilitiesTab)

public:
CUtilitiesTab(CWnd* pParent = nullptr); // standard constructor
virtual ~CUtilitiesTab();



// Dialog Data
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_UTILITIES };
#endif

protected:
HICON m_hIcon;

// Generated message map functions
virtual BOOL OnInitDialog();
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

DECLARE_MESSAGE_MAP()
public:
bool IsCheck1Checked;
CButton m_mil1553;
CButton m_ethernet;
CButton m_discrete;
CString m_resultTxt;
afx_msg void OnBnClickedMfcbutton1();






/*Ethernet*/

char m_ip_address[4];
long m_hops_count;
long m_rtt;
afx_msg void OnBnClickedCheck2();
};

what i tried here.
here i am just declare the IP adress as hardcode , when i click checkbox its should saw the output in edittext like "pass" or "fail"..

but here i am geeting the error

Error C4996 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings MGTS

if anyone can help me out this that would be great full

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900