The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Creating a pointer to std::istrstream is giving error khan_069 AIX 0 09-10-2008 03:24 AM
error: field `fatx_i' has incomplete type lateralus01 High Level Programming 2 07-22-2008 02:02 AM
error: field has incomplete type boyanov High Level Programming 4 08-10-2007 04:15 AM
array type has incomplete element type jaganadh High Level Programming 1 07-24-2007 03:54 AM
Accesing structure member:Error:dereferencing pointer to incomplete type amit4g High Level Programming 3 05-07-2007 08:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-16-2009
katwala katwala is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 7
Angry Build Error: error: dereferencing pointer to incomplete type

I'm getting the following Error:

prepare_pcap.c: In function `prepare_pkts':
prepare_pcap.c:127: error: dereferencing pointer to incomplete type
prepare_pcap.c:138: error: dereferencing pointer to incomplete type

====================================

This is the part of the relevant Code:

-----PREPARE_PCAP.H-----------

#if defined(__HPUX) || defined(__DARWIN) || defined(__CYGWIN) || defined(__FreeBSD__)
struct iphdr
{
#ifdef _HPUX_LI
unsigned int ihl:4;
unsigned int version:4;
#else
unsigned int version:4;
unsigned int ihl:4;
#endif
u_int8_t tos;
u_int16_t tot_len;
u_int16_t id;
u_int16_t frag_off;
u_int8_t ttl;
u_int8_t protocol;
u_int16_t check;
u_int32_t saddr;
u_int32_t daddr;
/*The options start here. */
};

------PREPARE_PCAP.C---------

int prepare_pkts(char *file, pcap_pkts *pkts) {
pcap_t *pcap;
struct pcap_pkthdr *pkthdr = NULL;
.....
struct iphdr *iphdr;

.....
iphdr = (struct iphdr *)((char *)ethhdr + sizeof(*ethhdr)); <<<LINE 127
if (iphdr && iphdr->version == 6) {
//ipv6
pktlen = (u_long) pkthdr->len - sizeof(*ethhdr) - sizeof(*ip6hdr);


----------------------------
This is where the error occurs. Can anyone please give me suggestion?

Thank you in Advance.
  #2 (permalink)  
Old 04-16-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
Code:
int prepare_pkts(char *file, pcap_pkts *pkts) {
pcap_t *pcap;
struct pcap_pkthdr *pkthdr = NULL;
.....
struct iphdr *iphdr;

.....
iphdr = (struct iphdr *)((char *)ethhdr + sizeof(*ethhdr)); <<<LINE 127
if (iphdr && iphdr->version == 6) {
//ipv6
pktlen = (u_long) pkthdr->len - sizeof(*ethhdr) - sizeof(*ip6hdr);
let's see here....

This: *ethdr is totally illegal. You cannot use a pointer syntax on a plain old struct.
I think you'd want this:

sizeof( struct ethdr )

in order to get any useful information.

substitute "struct whatever" wherever you have these sizeof(*thing) things.

----

BTW -- what in the world are you trying to do here?
Whatever it is .... it's the wrong way.

If you describe what it really is you're trying to accomplish,
I can show you a better way.

Best regards,
We're all learning,
quirk
  #3 (permalink)  
Old 04-16-2009
katwala katwala is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 7
Build Error: error: dereferencing pointer to incomplete type

Thank you for your reply. First a background on what I'm trying to do - I'm trying to compile SIPp (VoIP load generator) on Solaris Platform. This is an open Source code - however, a majority of the usage is on Linux platform - where it compiles fine.

I tried your suggestion of replacing sizeof((ethhdr) with sizeof( struct ethhdr ) - however, it fails with the following error:

prepare_pcap.c:126: error: invalid application of `sizeof' to an incomplete type

Source Line 126:
iphdr = (struct iphdr *)((char *)ethhdr + sizeof(struct ethhdr));

Please let me know if you have other suggestions.

thank you,
--------------------------------------------------
  #4 (permalink)  
Old 04-16-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
omg -- this is actual open source code? that's amazing.

Well -- one error at a time. Fix one -- on to the next.
That first suggestion did what it was supposed to do.

This statement:
Code:
iphdr = (struct iphdr *)((char *)ethhdr + sizeof(struct ethhdr));
Is complete insane. It's relying on typecasting a pointer of a structure,
jumping over the size of itself and assuming that the next spot in memory
is a pointer to iphdr. This simply is dreaming. Although it ~could~ happen,
given that the compiler writer places his variables on after the other in
memory but if it did... that means that the memory must've been explicitly
declared somewhere and if so... why not explicitly cast that memory here?

But whatever. The same problem exists, more or less. But to get it to compile,
try this:


Code:
iphdr = (struct iphdr *)((long)&ethhdr + (long)sizeof(struct ethhdr));
or:

Code:
iphdr = (void *)((long)&ethhdr + (long)sizeof(struct ethhdr));
good luck with this!
  #5 (permalink)  
Old 04-16-2009
katwala katwala is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 7
Red face

Modified your suggestion to:

iphdr = (void *)((long)&ethhdr + (long)sizeof(&ethhdr));

And I don't see the error :

prepare_pcap.c:127: error: invalid application of `sizeof' to an incomplete type


--------

Any suggestion on the original error : dereferencing pointer to incomplete type.

thx.
  #6 (permalink)  
Old 04-16-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
why modify my suggestion and then complain when it doesn't work?

Here is how this stuff is supposed to work:

Code:
#include <stdio.h>
#include <string.h>

struct hdr {
  int x;
  long y;
  char z[16];
  };

struct hdr *iphdr;
struct hdr ethhdr;



int main()
{

ethhdr.x = 7;
ethhdr.y = 81;
strcpy( ethhdr.z, "frogs" );

iphdr = (void *)((long)&ethhdr + (long)sizeof(&ethhdr));

(void)printf( "address becomes: |%x|\n", &ethhdr );
(void)printf( "address becomes: |%x|\n", iphdr );

return 0;
}
OUTPUT:

Code:
address becomes: |20e54|
address becomes: |20e58|
But this line:

Code:
iphdr = (void *)((long)&ethhdr + (long)sizeof(&ethhdr));
can serve no useful purpose.
it is a bug. it's wrong. etc...
  #7 (permalink)  
Old 04-16-2009
katwala katwala is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 7
I forgot one thing: I had tried w/ ur suggestion:
iphdr = (struct iphdr *)((long)&ethhdr + (long)sizeof(struct ethhdr));
and also with
iphdr = (void *)((long)&ethhdr + (long)sizeof(struct ethhdr));

However, I got this error again:

prepare_pcap.c:127: error: invalid application of `sizeof' to an incomplete type
Closed Thread

Bookmarks

Tags
build error

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0