Hi, I'm learning a bit of network programming over the holidays from this guide http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html
The first full program won't compile
I have bolded the line cc doesn't like.
I get this error:
What gives? Who cares if the types incomplete, why can't I access a member of the struct?
Cheers for any help, (yes I've tried gcc).
The first full program won't compile
I have bolded the line cc doesn't like.
Code:
/*
** showip.c -- show IP addresses for a host gien on the command line
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
int
main(int argc, char *argv[]) {
struct addrinfo hints, *res, *p;
int status;
char ipstr[INET_ADDRSTRLEN];
if(argc != 2) {
fprintf(stderr, "usage: showip <hostname>\n");
return 1;
}
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
if( (status = getaddrinfo(argv[1], NULL, &hints, &res) ) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status) );
return 2;
}
printf("IP addresses for %s:\n\n", argv[1]);
for(p = res; p != NULL; p = p->ai_next) {
void *addr;
char *ipver;
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
[B]addr = &(ipv4->sin_addr);[/B]
ipver = "IPv4";
inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
printf(" %s: %s\n", ipver, ipstr);
}
freeaddrinfo(res);
return 0;
}
I get this error:
Code:
> cc -o showip showip.c
showip.c: In function 'main':
showip.c:40: error: dereferencing pointer to incomplete type
showip.c:50:2: warning: no newline at end of file
>
What gives? Who cares if the types incomplete, why can't I access a member of the struct?
Cheers for any help, (yes I've tried gcc).