Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-26-2012, 01:22 AM
|
#1
|
LQ Newbie
Registered: Apr 2012
Posts: 8
Rep: 
|
error: dereferencing pointer to incomplete type in C
I am getting following compilation errors in gcc. Anyone please help me in finding what is wrong?
$ gcc -c recv_v4.c
recv_v4.c: In function `recv_v4':
recv_v4.c:42: error: dereferencing pointer to incomplete type
recv_v4.c:42: error: `ICMP_TIMXCEED' undeclared (first use in this function)
recv_v4.c:42: error: (Each undeclared identifier is reported only once
recv_v4.c:42: error: for each function it appears in.)
recv_v4.c:42: error: dereferencing pointer to incomplete type
recv_v4.c:42: error: `ICMP_TIMXCEED_INTRANS' undeclared (first use in this function)
recv_v4.c:59: error: dereferencing pointer to incomplete type
recv_v4.c:59: error: `ICMP_UNREACH' undeclared (first use in this function)
recv_v4.c:72: error: dereferencing pointer to incomplete type
recv_v4.c:72: error: `ICMP_UNREACH_PORT' undeclared (first use in this function)
recv_v4.c:75: error: dereferencing pointer to incomplete type
recv_v4.c:82: error: dereferencing pointer to incomplete type
recv_v4.c:82: error: dereferencing pointer to incomplete type
Following is the code:
Code:
#include "trace.h"
recv_v4.c
extern int gotalarm;
/*
* Return: -3 on timeout
* -2 on ICMP time exceeded in transit (caller keeps going)
* -1 on ICMP port unreachable (caller is done)
* >= 0 return value is some other ICMP unreachable code
*/
int recv_v4(int seq, struct timeval *tv)
{
int hlen1, hlen2, icmplen, ret;
socklen_t len;
ssize_t n;
struct ip *ip, *hip;
struct icmp *icmp;
struct udphdr *udp;
gotalarm = 0;
alarm(3);
for ( ; ; ) {
if (gotalarm)
return(-3); /* alarm expired */
len = pr->salen;
n = recvfrom(recvfd, recvbuf, sizeof(recvbuf), 0, pr->sarecv, &len);
if (n < 0) {
if (errno == EINTR)
continue;
else
err_sys("recvfrom error");
}
ip = (struct ip *) recvbuf; /* start of IP header */
hlen1 = ip->ip_hl << 2; /* length of IP header */
icmp = (struct icmp *) (recvbuf + hlen1); /* start of ICMP header */
if ( (icmplen = n - hlen1) < 8)
continue; /* not enough to look at ICMP header */
if (icmp->icmp_type == ICMP_TIMXCEED && icmp->icmp_code == ICMP_TIMXCEED_INTRANS) {
if (icmplen < 8 + sizeof(struct ip))
continue; /* not enough data to look at inner IP */
hip = (struct ip *) (recvbuf + hlen1 + 8);
hlen2 = hip->ip_hl << 2;
if (icmplen < 8 + hlen2 + 4)
continue; /* not enough data to look at UDP ports */
udp = (struct udphdr *) (recvbuf + hlen1 + 8 + hlen2);
if (hip->ip_p == IPPROTO_UDP &&
udp->uh_sport == htons(sport) &&
udp->uh_dport == htons(dport + seq)) {
ret = -2; /* we hit an intermediate router */
break;
}
} else if (icmp->icmp_type == ICMP_UNREACH) {
if (icmplen < 8 + sizeof(struct ip))
continue; /* not enough data to look at inner IP */
hip = (struct ip *) (recvbuf + hlen1 + 8);
hlen2 = hip->ip_hl << 2;
if (icmplen < 8 + hlen2 + 4)
continue; /* not enough data to look at UDP ports */
udp = (struct udphdr *) (recvbuf + hlen1 + 8 + hlen2);
if (hip->ip_p == IPPROTO_UDP &&
udp->uh_sport == htons(sport) &&
udp->uh_dport == htons(dport + seq)) {
if (icmp->icmp_code == ICMP_UNREACH_PORT)
ret = -1; /* have reached destination */
else
ret = icmp->icmp_code; /* 0, 1, 2, ... */
break;
}
}
if (verbose) {
printf(" (from %s: type = %d, code = %d)\n",
Sock_ntop_host(pr->sarecv, pr->salen),
icmp->icmp_type, icmp->icmp_code);
}
/* Some other ICMP error, recvfrom() again */
}
alarm(0); /* don't leave alarm running */
gettimeofday(tv, NULL); /* get time of packet arrival */
return(ret);
}
trace.h
Code:
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/udp.h>
#include <unistd.h>
#include <stdio.h>
#ifdef HAVE_SOCKADDR_DL_STRUCT
#include <net/if_dl.h>
#endif
#define BUFSIZE 1500
struct rec { /* format of outgoing UDP data */
u_short rec_seq; /* sequence number */
u_short rec_ttl; /* TTL packet left with */
struct timeval rec_tv; /* time packet left */
};
/* globals */
char recvbuf[BUFSIZE];
char sendbuf[BUFSIZE];
int datalen; /* # bytes of data following ICMP header */
char *host;
u_short sport, dport;
int nsent; /* add 1 for each sendto() */
pid_t pid; /* our PID */
int probe, nprobes;
int sendfd, recvfd; /* send on UDP sock, read on raw ICMP sock */
int ttl, max_ttl;
int verbose;
/* function prototypes */
const char *icmpcode_v4(int);
const char *icmpcode_v6(int);
int recv_v4(int, struct timeval *);
int recv_v6(int, struct timeval *);
void sig_alrm(int);
void traceloop(void);
void tv_sub(struct timeval *, struct timeval *);
struct proto {
const char *(*icmpcode)(int);
int (*recv)(int, struct timeval *);
struct sockaddr *sasend; /* sockaddr{} for send, from getaddrinfo */
struct sockaddr *sarecv; /* sockaddr{} for receiving */
struct sockaddr *salast; /* last sockaddr{} for receiving */
struct sockaddr *sabind; /* sockaddr{} for binding source port */
socklen_t salen; /* length of sockaddr{}s */
int icmpproto; /* IPPROTO_xxx value for ICMP */
int ttllevel; /* setsockopt() level to set TTL */
int ttloptname; /* setsockopt() name to set TTL */
} *pr;
#ifdef IPV6
#include <netinet/ip6.h>
#include <netinet/icmp6.h>
#endif
|
|
|
04-26-2012, 02:41 AM
|
#2
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,655
|
I have tried and worked for me. So I suggest you to type gcc -E rec_v4.c > rec_v4.i and look at that rec_v4.i file, maybe it will give you a tip where is it lost. I do not know what os you have, maybe a define solves it.
|
|
|
04-26-2012, 05:40 AM
|
#3
|
LQ Newbie
Registered: Apr 2012
Posts: 8
Original Poster
Rep: 
|
I am using CYGWIN and Windows XP Professional OS.
|
|
|
04-26-2012, 11:07 PM
|
#4
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078
Rep: 
|
In my <netinet/ip_icmp.h> you need to have __USE_BSD defined to get struct icmp and the macros you're using.
Kevin Barry
|
|
|
04-27-2012, 02:17 AM
|
#5
|
LQ Newbie
Registered: Apr 2012
Posts: 8
Original Poster
Rep: 
|
I defined __USE_BSD in ip_icmp.h. But still having same errors.
|
|
|
04-27-2012, 02:22 AM
|
#6
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,655
|
Oh, no! Do not touch that file. gcc -D__USE_BSD -c recv_v4.c would be the way, but actually I cannot check if it solves your problem.
|
|
|
04-27-2012, 06:53 AM
|
#7
|
LQ Newbie
Registered: Apr 2012
Posts: 8
Original Poster
Rep: 
|
thanks pan64.
|
|
|
04-27-2012, 12:14 PM
|
#8
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078
Rep: 
|
Quote:
Originally Posted by pan64
Oh, no! Do not touch that file. gcc -D__USE_BSD -c recv_v4.c would be the way, but actually I cannot check if it solves your problem.
|
Yes, I should have been more explicit.
Kevin Barry
|
|
1 members found this post helpful.
|
07-07-2012, 05:27 AM
|
#9
|
LQ Newbie
Registered: Jul 2012
Posts: 22
Rep: 
|
error: dereferencing pointer to incomplete type
i am working on my client/server chat program and i get "error: dereferencing pointer to incomplete type" when i compile my client.c.
Here is my code:
#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <netdb.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
int main(int argc,char *argv[])
{
struct sockaddr_in clientaddr;
pid_t pid;
int clientfd,sendbytes;
struct hostent *host;
char *buf,*buf_r;
if(argc < 4)
{
printf("usage:\n");
printf("%s host port name\n",argv[0]);
exit(1);
}
host = gethostbyname(argv[1]);
if((clientfd = socket (AF_INET,SOCK_STREAM,0)) == -1)
{
perror("socket\n");
exit(1);
}
clientaddr.sin_family = AF_INET;
clientaddr.sin_port = htons((uint16_t)atoi(argv[2]));
clientaddr.sin_addr = *((struct in_addrr *) host->h_addr);
bzero(&(clientaddr.sin_zero),0);
if(connect(clientfd,(struct sockaddr *)&clientaddr,sizeof(struct sockaddr)) == -1)
{
perror("connect\n");
exit(1);
}
buf=(char *)malloc(120);
memset(buf,0,120);
buf_r=(char *)malloc(100);
if( recv(clientfd,buf,100,0) == -1)
{
perror("recv: ");
exit(1);
}
printf("\n%s\n",buf);
pid = fork();
while(1)
{
if(pid > 0)
{
//get_cur_time(time_str);
strcpy(buf,argv[3]);
strcat(buf,":");
memset(buf_r,0,100);
//gets(buf_r);
fgets(buf_r,100,stdin);
strncat(buf,buf_r,strlen(buf_r)-1);
//strcat(buf,time_str);
//printf("---%s\n",buf);
if((sendbytes = send(clientfd,buf,strlen(buf),0)) == -1)
{
perror("send\n");
exit(1);
}
}
else if(pid == 0)
{
memset(buf,0,1000);
if(recv(clientfd,buf,100,0) <=0)
{
perror("recv:");
close(clientfd);
raise(SIGSTOP);
exit(1);
}
printf("%s\n",buf);
}
else
perror("fork");
}
close(clientfd);
return 0;
}
Please help me find solution for this. Thank you.
|
|
|
07-07-2012, 09:35 AM
|
#10
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,655
|
please open a new thread for your problem and also please use [code]here comes your code[/code] to keep formatting, and post the full error message.
Actually the real error message was:
Quote:
gcc -o prog -Wall prog.c
prog.c: In function 'main':
prog.c:36: error: dereferencing pointer to incomplete type
|
you made a typo in line 36:
clientaddr.sin_addr = *((struct in_addrr *) host->h_addr);
so, just remove that r
Last edited by pan64; 07-07-2012 at 10:53 AM.
|
|
|
All times are GMT -5. The time now is 08:35 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|