ping script doesn't work?

This is a discussion on ping script doesn't work? within the C Programming forums, part of the General Programming Boards category; 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 ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    48

    ping script doesn't work?

    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!
    Last edited by userpingz; 05-31-2009 at 05:40 PM. Reason: wrong ENTER key input when i creating the post
    --------------------------------------------------------
    Newbie
    C/C#/C++
    swimming/cycling/running
    There is nothing more powerful than an idea.
    Except for an idea put into action.
    --------------------------------------------------------

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by guy with stupid name
    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 include area, the ping.h fill frame will jumped out normally.
    I doubt you added the library where "ping()" resides.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    Quote Originally Posted by zacs7 View Post
    I doubt you added the library where "ping()" resides.
    thank you.
    i am newbie.

    I backed up ping.h and reinstalled the LCC-WIN32.exe just now.
    the ping.h located at C:\lcc\includ\... No different after i reinstall the tool.
    attached the ping.h

    Is there something wrong with my ping.h OR ping.c


    em :-(
    Attached Files Attached Files
    --------------------------------------------------------
    Newbie
    C/C#/C++
    swimming/cycling/running
    There is nothing more powerful than an idea.
    Except for an idea put into action.
    --------------------------------------------------------

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So as zacs7 said, your ping.h header file claims that your ping.c file will define a function called ping; yet it does not, causing much sadness and despondency.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using expect script in C program
    By nitinmhetre in forum Linux Programming
    Replies: 1
    Last Post: 12-21-2006, 07:25 AM
  2. Script in games
    By Shakti in forum Game Programming
    Replies: 7
    Last Post: 09-27-2006, 12:27 AM
  3. In a game Engine...
    By Shamino in forum Game Programming
    Replies: 28
    Last Post: 02-19-2006, 10:30 AM
  4. how to implementate a registration script
    By TJa in forum C++ Programming
    Replies: 0
    Last Post: 10-28-2005, 02:33 AM
  5. Problem with cgi script - can't rename files
    By bjdea1 in forum C Programming
    Replies: 2
    Last Post: 12-12-2001, 03:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21