| | |
Cygwin socket problem
Thread Solved |
Hi, I installed cygwin recently and wanted to do some network programming with it. Since I have never used unix sockets before, I'm reading Beej's Guide To Network Programming. I took this from section 5.1 and tried to compile it. I get a few errors that I can't figure out
.
Here are my errors:
stuff.c: In function `main':
stuff.c:14: error: storage size of 'hints' isn't known
stuff.c:16: error: `INET6_ADDRSTRLEN' undeclared (first use in this function)
stuff.c:16: error: (Each undeclared identifier is reported only once
stuff.c:16: error: for each function it appears in.)
stuff.c:34: error: dereferencing pointer to incomplete type
stuff.c:40: error: dereferencing pointer to incomplete type
stuff.c:41: error: dereferencing pointer to incomplete type
stuff.c:45: error: dereferencing pointer to incomplete type
stuff.c:46: error: dereferencing pointer to incomplete type
stuff.c:51: error: dereferencing pointer to incomplete type
I added this to my code and got rid of the `INET6_ADDRSTRLEN' undeclared error:
. C Syntax (Toggle Plain Text)
/* ** showip.c -- show IP addresses for a host given 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[INET6_ADDRSTRLEN]; if (argc != 2) { fprintf(stderr,"usage: showip hostname\n"); return 1; } memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version 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; // get the pointer to the address itself, // different fields in IPv4 and IPv6: if (p->ai_family == AF_INET) { // IPv4 struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr; addr = &(ipv4->sin_addr); ipver = "IPv4"; } else { // IPv6 struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr; addr = &(ipv6->sin6_addr); ipver = "IPv6"; } // convert the IP to a string and print it: inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr); printf(" %s: %s\n", ipver, ipstr); } freeaddrinfo(res); // free the linked list return 0; }
Here are my errors:
stuff.c: In function `main':
stuff.c:14: error: storage size of 'hints' isn't known
stuff.c:16: error: `INET6_ADDRSTRLEN' undeclared (first use in this function)
stuff.c:16: error: (Each undeclared identifier is reported only once
stuff.c:16: error: for each function it appears in.)
stuff.c:34: error: dereferencing pointer to incomplete type
stuff.c:40: error: dereferencing pointer to incomplete type
stuff.c:41: error: dereferencing pointer to incomplete type
stuff.c:45: error: dereferencing pointer to incomplete type
stuff.c:46: error: dereferencing pointer to incomplete type
stuff.c:51: error: dereferencing pointer to incomplete type
I added this to my code and got rid of the `INET6_ADDRSTRLEN' undeclared error:
C Syntax (Toggle Plain Text)
#ifndef INET6_ADDRSTRLEN #define INET6_ADDRSTRLEN 46 #endif
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live."
--Martin Golding
--Martin Golding
I figured it out after about a bit of searching. For anyone having this same problem: apparently, Cygwin can't use IPv6 by default. I went to http://win6.jp/Cygwin/ and downloaded the files I needed there. I unzipped it into my cygwin directory, and had to replace cygwin1.dll in the bin directory with new-cygwin1.dll.
Last edited by TheBeast32; Jul 19th, 2009 at 11:49 pm.
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live."
--Martin Golding
--Martin Golding
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
I tried to put together the same program in C on our development server but ran into the same issue. I don't believe it's platform-related as much as it is leaving out a header include.
In reference to these two lines of Beej's showip.c example:
If you're getting this error:
Chances are you left out:
Cheers!
Matt Borja
Borja Webs, LLC
<<snipped>>
In reference to these two lines of Beej's showip.c example:
C Syntax (Toggle Plain Text)
addr = &(ipv4->sin_addr); addr = &(ipv6->sin6_addr);
C Syntax (Toggle Plain Text)
error: dereferencing pointer to incomplete type
C Syntax (Toggle Plain Text)
#include <netinet/in.h>
Matt Borja
Borja Webs, LLC
<<snipped>>
Last edited by niek_e; 4 Days Ago at 11:39 am. Reason: Fake sig removed
![]() |
Similar Threads
- Sending files in socket problem/// (Java)
- Porting Unix,Linux sockets to windows without winsock (C++)
- Socket problem (Python)
- Java Socket Problem (Java)
- socket problem,,,,, plz help (Java)
- Toshiba Tecra 8100 no boot-up after memory upgrade (Troubleshooting Dead Machines)
- Connecting to a computer via sockets (C++)
- CPU fan vibration (Cases, Fans and Power Supplies)
Other Threads in the C Forum
- Previous Thread: Help with two programmes
- Next Thread: heap sort -- segmentation fault
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop function getlogicaldrivestrin givemetehcodez grade gtkwinlinux histogram homework i/o ide inches include infiniteloop input interest intmain() iso keyboard km license linked linkedlist linux list looping lowest matrix meter microsoft mysql number oddnumber open opendocumentformat openwebfoundation pdf pointer posix power probleminc process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing scheduling segmentationfault send sequential single socket socketprogramming stack standard strchr string suggestions systemcall test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi





