Hey,
i test the ping script at LCC-Win32 and VS2005(Win32 Console App), but can't work.
ping.h
Code:
#ifndef __ping_h__
#define __ping_h__
#define MAXIPNAME 30
// For optional values, zero means use the default.
typedef struct __Ping {
char *HostName; // IN: Host name/Ip address of destination. Required
int TotalPackets; // OPTIONAL: Number of packets to send before exiting.
// Default is 5
int DataSize; // OPTIONAL: Data size in the sent packets. Default is 32
int SleepTime; // OPTIONAL: Time (in ms) to wait after each packet.
// Default is 1000 ms.
int MaxTimeouts; // OPTIONAL: Maximum number of timeouts allowed.
// Default is 5.
int (*Callback)(struct __Ping *); // OPTIONAL: Callback function at each
// packet received and at each timeout.
int ttl; // OPTIONAL: Time to live. Default 128
int verbose; // Optional: Whether to print messages to stdout or not.
int TotalReceived; // OUT: Total packets received
int TotalSent; // OUT: Total packets sent
int MaxTime; // OUT: Maximum time (ms)
int MinTime; // OUT: Minimum time (ms)
int TotalTime; // OUT: Total time used
int Timeouts; // OUT: Number of timeouts
int Errorcode; // WSAGetLastError() report when an error occurs, or
// a negative number, specific to the ping function.
int ShortPackets; // OUT: Packets that weren't sent completely due to errors
char ip[MAXIPNAME];// OUT: IP of destination (Can be the same as HostName)
// Per packet specific data
int Bytes; // OUT: Bytes received
int Seq; // OUT: Sequence number
int Time; // OUT: Time for this packet
} PingInterface;
#define PINGERROR_BADADDR -1
#define PINGERROR_SETSOCKOPT -2
#define PINGERROR_NONETWORK -3
#define PINGERROR_NOSOCKET -4
#define PINGERROR_INTERNAL -5
int ping(PingInterface *);
#endif
ping.c
Code:
#include <ping.h>
#include <stdio.h>
int main(int argc,char *argv[])
{
PingInterface p;
memset(&p,0,sizeof(p));
p.HostName = (argv[1]);
if (ping(&p)) {
printf("Host %s is up\n",argv[1]);
}
else
printf("Host %s is down\n",argv[1]);
}
The code from LCC-Win32 CTutorial PDF book.
LCC-Win32 compile failed:
Wedit output window build: Mon Jun 01 07:30:06 2009
Error c:\lcc\ping\ping.c 11 undefined reference to _ping
C:\lcc\bin\make.exe
Compilation + link time:0.1 sec, Return code: 1
Comment: I conly created the ping.c file for the project, ping.h already inclueded at the directory of "c:\lcc\include\ping.h".
VS2005 compile failed too:
------ Rebuild All started: Project: ping, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'ping', configuration 'Debug|Win32'
Compiling...
ping.c
d:\vs\tmp\pingfun\pingfun\ping.c(2) : fatal error C1083: Cannot open include file: 'ping.h': No such file or directory
Build log was saved at "file://d:\vs\TMP\PingFun\PingFun\Debug\BuildLog.htm"
ping - 1 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Comment: Actually, i already add a new ping.h file at the vs IDE. and i right click the <ping.h> from ping.c head incldue area, the ping.h fill frame will jumped out normally. Why the comipler sitll alert "NO such file or drectory"?
thanks!