LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 04-26-2012, 01:22 AM   #1
Himalay
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Rep: Reputation: Disabled
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
 
Old 04-26-2012, 02:41 AM   #2
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,035

Rep: Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337
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.
 
Old 04-26-2012, 05:40 AM   #3
Himalay
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
I am using CYGWIN and Windows XP Professional OS.
 
Old 04-26-2012, 11:07 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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
 
Old 04-27-2012, 02:17 AM   #5
Himalay
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
I defined __USE_BSD in ip_icmp.h. But still having same errors.
 
Old 04-27-2012, 02:22 AM   #6
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,035

Rep: Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337
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.
 
Old 04-27-2012, 06:53 AM   #7
Himalay
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
thanks pan64.
 
Old 04-27-2012, 12:14 PM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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.
Old 07-07-2012, 05:27 AM   #9
joyce092130
LQ Newbie
 
Registered: Jul 2012
Posts: 22

Rep: Reputation: Disabled
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.
 
Old 07-07-2012, 09:35 AM   #10
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,035

Rep: Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337Reputation: 1337
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dereferencing pointer to incomplete type sweetymobil Programming 7 06-22-2009 08:46 AM
tai64nlocal.c:55: error: dereferencing pointer to incomplete type ExCIA Linux - General 1 03-31-2009 10:49 AM
dereferencing pointer to incomplete type (just built a new kernel) 144419855310001 Linux - Kernel 0 10-03-2007 04:58 PM
error: dereferencing pointer to incomplete type ChullDouvre Programming 2 05-02-2007 01:16 AM
Error: dereferencing pointer to incomplete type cynthia_thomas Programming 1 05-01-2006 09:10 AM


All times are GMT -5. The time now is 11:25 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration