LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Error: dereferencing pointer to incomplete type (https://www.linuxquestions.org/questions/programming-9/error-dereferencing-pointer-to-incomplete-type-440477/)

cynthia_thomas 05-01-2006 04:34 AM

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

graemef 05-01-2006 08:10 AM

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.


All times are GMT -5. The time now is 01:11 PM.