Hi all,
I'm trying to compile compile a little ping program with
gcc -o myping myping.c
I have no problems, but if I compile it with
gcc -o myping -std=c99 myping.c
the result is:
"
myping.c: In function 'main':
myping.c:62: warning: implicit declaration of function 'inet_aton'
myping.c:67: error: dereferencing pointer to incomplete type
myping.c:68: error: dereferencing pointer to incomplete type
myping.c:69: error: dereferencing pointer to incomplete type
myping.c:70: error: dereferencing pointer to incomplete type
myping.c:71: error: dereferencing pointer to incomplete type
myping.c:72: error: dereferencing pointer to incomplete type
myping.c:73: error: dereferencing pointer to incomplete type
myping.c:78: error: dereferencing pointer to incomplete type
myping.c:85: error: dereferencing pointer to incomplete type
myping.c:87: error: dereferencing pointer to incomplete type
myping.c:89: error: dereferencing pointer to incomplete type
"
How can I solve this problem?
Thank you in advance for your help,
Gg.
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <netdb.h>
#define MAX_PACKET 1000
#define ICMP_SIZE 16
unsigned short check_sum(unsigned short *addr, int len)
{
int nleft = len;
int sum = 0;
unsigned short *w = addr;
unsigned short answer = 0;
while (nleft 1)
{
sum += *w++;
nleft -= 2;
}
if (nleft == 1)
{
*(unsigned char *)(&answer) = * (unsigned char *) w;
sum += answer;
}
sum = (sum >16) + (sum & 0xffff);
sum = sum + (sum >16);
answer = ~sum;
return answer;
}
void timeval_sub(struct timeval *out, struct timeval *in)
{
out->tv_sec = out->tv_sec - in->tv_sec;
out->tv_usec = out->tv_usec - in->tv_usec;
if (out->tv_sec < 0)
{
out->tv_usec += 1000000;
out->tv_sec--;
}
}
int main(int argc, char *argv[])
{
int icmp_socket_fd;
struct sockaddr_in icmp_socket_info;
struct in_addr addr;
struct icmp *icmp_buf;
char pkt_buf[MAX_PACKET];
struct ip *ip = (struct ip *)pkt_buf;
struct timeval tv, appo_tv;
icmp_socket_fd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
inet_aton(argv[1], &addr);
icmp_socket_info.sin_family = AF_INET;
icmp_socket_info.sin_addr.s_addr = addr.s_addr;
icmp_buf = (struct icmp *)pkt_buf;
icmp_buf->icmp_type = ICMP_ECHO;
icmp_buf->icmp_code = 0;
icmp_buf->icmp_id = getpid();
icmp_buf->icmp_seq = 0;
gettimeofday((struct timeval *)icmp_buf->icmp_data, NULL);
icmp_buf->icmp_cksum = 0;
icmp_buf->icmp_cksum = check_sum((unsigned short *)icmp_buf,
ICMP_SIZE);
sendto(icmp_socket_fd, icmp_buf, ICMP_SIZE, 0, (struct sockaddr *)
&icmp_socket_info, sizeof(icmp_socket_info));
do
{
gettimeofday(&appo_tv, NULL);
timeval_sub(&appo_tv, (struct timeval *)icmp_buf->
icmp_data);
recvfrom(icmp_socket_fd, pkt_buf, sizeof(pkt_buf), 0, NULL,
NULL);
icmp_buf = (struct icmp *) (pkt_buf+ip->ip_hl*4);;
}
while(icmp_buf->icmp_type != ICMP_ECHOREPLY );
gettimeofday(&tv, NULL);
timeval_sub(&tv, (struct timeval *)icmp_buf->icmp_data);
printf("Ping received in %ld micro sec\n", tv.tv_sec* 1000000
+tv.tv_usec);
}
PS
gcc --version
gcc (GCC) 4.1.0 20060304 (Red Hat 4.1.0-3) 2 4637
On Mon, 6 Nov 2006 ge******@gmail.com wrote:
>
Hi all,
I'm trying to compile compile a little ping program with
gcc -o myping myping.c
I have no problems, but if I compile it with
gcc -o myping -std=c99 myping.c
the result is:
"
myping.c: In function 'main':
myping.c:62: warning: implicit declaration of function 'inet_aton'
myping.c:67: error: dereferencing pointer to incomplete type
myping.c:68: error: dereferencing pointer to incomplete type
myping.c:69: error: dereferencing pointer to incomplete type
myping.c:70: error: dereferencing pointer to incomplete type
myping.c:71: error: dereferencing pointer to incomplete type
myping.c:72: error: dereferencing pointer to incomplete type
myping.c:73: error: dereferencing pointer to incomplete type
myping.c:78: error: dereferencing pointer to incomplete type
myping.c:85: error: dereferencing pointer to incomplete type
myping.c:87: error: dereferencing pointer to incomplete type
myping.c:89: error: dereferencing pointer to incomplete type
"
How can I solve this problem?
I don't blame you for being confused, but you should really learn
to read your system's header files for yourself. Take a look at
/usr/include/arpa/inet.h, and notice that it includes features.h,
and then read the documentation at the top of that file. (The answer
to your question is to #define _GNU_SOURCE.)
And FYI, your question had nothing to do with standard C, and
everything to do with GCC options and POSIXy extensions. A newsgroup
devoted to GCC, or to Linux, would have been the correct place for
it.
HTH,
-Arthur
Arthur J. O'Dwyer ha scritto:
On Mon, 6 Nov 2006 ge******@gmail.com wrote:
Hi all,
I'm trying to compile compile a little ping program with
gcc -o myping myping.c
I have no problems, but if I compile it with
gcc -o myping -std=c99 myping.c
the result is:
"
myping.c: In function 'main':
myping.c:62: warning: implicit declaration of function 'inet_aton'
How can I solve this problem?
I don't blame you for being confused, but you should really learn
to read your system's header files for yourself. Take a look at
/usr/include/arpa/inet.h, and notice that it includes features.h,
and then read the documentation at the top of that file. (The answer
to your question is to #define _GNU_SOURCE.)
Thank you very much for your help,
Sorry for the Off Topic.
Gg This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: dayzman |
last post by:
Hi,
I'm running Windows and Python 2.4 (binary). I've been trying to
compile this module with extensions that incorporate some C99
extensions (e.g. designated initialisers). I haven't had much...
|
by: MikeyD |
last post by:
Just switched to using gcc on my windows 98 pc. Programs were compiling fine
on a propriety compiler. Now, though, it gives me an error message for a for
loop, "line xx: use of header-defined for...
|
by: Michael B. |
last post by:
I was just thinking about this, specifically wondering if there's any
features that the C specification currently lacks, and which may be
included in some future standardization.
Of course, I...
|
by: Jason Curl |
last post by:
I've seen the document N869.txt and the copy I could find talks about
C99. Is there anything that comprehensively describes the difference
between C89 and C99? I'd like to write code to be as...
|
by: E. Robert Tisdale |
last post by:
Please find attached a copy of the "Shape class" example from
Bjarne Stroustrup, "The C++ Programming Language: Third Edition",
Chapter 2: A Tour of C++, Section 6: Object-Oriented Programming,...
| |
by: pocmatos |
last post by:
Hi all,
Using -std=c99 to enforce the c99 standard in gcc I get:
$ gcc -Wall -std=c99 timespec.c
timespec.c: In function 'main':
timespec.c:5: error: storage size of 'a' isn't known...
|
by: sunny |
last post by:
Hi All
What is C99 Standard is all about. is it portable, i mean i saw
-std=C99 option in GCC
but there is no such thing in VC++.?
which one is better ANSI C / C99?
can i know the major...
|
by: Stefano Sabatini |
last post by:
Hi all,
I would like to know what you guys consider more portable (as far
as I can understand it -std=c99 is a gcc specific option).
Also can you say what's the difference between...
|
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= |
last post by:
When I'm writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:
gcc *.c -ansi -pedantic -Wall -o executable
If I'm using 3rd-party libraries, I'll...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |