LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 05-01-2006, 04:34 AM   #1
cynthia_thomas
LQ Newbie
 
Registered: Oct 2005
Posts: 28

Rep: Reputation: 15
Error: dereferencing pointer to incomplete type


hi ,

this is the error which i got when compiling a C pgm:

con1.c:471: dereferencing pointer to incomplete type
con1.c:473: dereferencing pointer to incomplete type


this is the code lines which produced the error



int main(int argc, char **argv)
{

char *dev = NULL;
char errbuf[PCAP_ERRBUF_SIZE];
char *fname;
int n;
struct sockaddr_in serv_addr;
struct hostent *server;
pcap_t *handle;
bpf_u_int32 mask;
bpf_u_int32 net;
struct pcap_pkthdr *h;
const u_char *sp;
struct pcap_pkthdr hdr;
pcap_dumper_t *dumpfile;
int num_packets = 5;
front1=NULL;
rear1=NULL;
fname="dump";


// Establishing a connection to the server

if (argc < 3) {
fprintf(stderr,"usage %s hostname port\n", argv[0]);
exit(0);
}
portno = atoi(argv[2]);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
server = gethostbyname(argv[1]);
if (server == NULL) {
fprintf(stderr,"ERROR, no such host\n");
exit(0);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
// here is the error
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length); //
serv_addr.sin_port = htons(portno);
if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0)
error("ERROR connecting");
......

Any idea.
thanks and regards
cynthia thomas
 
Old 05-01-2006, 08:10 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by cynthia_thomas
// here is the error
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length); //
h_addr is a character array whilst s_addr is of type unsigned long.

The copy that you are attempting will not give you the result that you are hoping for, being a conversion from a character representation of the IP address to a numerical representation.

Check out the function inet_aton()

graeme.
 
  


Reply



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
gcc 4.0.0 warning: dereferencing type-punned pointer will break strict-aliasing rules stephenwalter Programming 4 06-10-2009 04:06 AM
tai64nlocal.c:55: error: dereferencing pointer to incomplete type ExCIA Linux - General 1 03-31-2009 09:49 AM
redeferenced pointer to incomplete type Aldair1808 Programming 1 11-28-2005 03:23 PM
ereferencing pointer to incomplete type? ams Programming 5 03-03-2005 10:32 AM
C error "dereferencing pointer to incomplete type" lucs Slackware 6 02-21-2005 09:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:45 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration