Jump to content


Installing Cygwin


  • You cannot reply to this topic
No replies to this topic

#1 WindScar

    New Member

  • Members
  • PipPip
  • 21 posts

Posted 19 January 2009 - 10:03 PM

I am following the Beej's Guide to Network Programming wich said that I can compile any of it's examples on Windows if I download Cygwin.
So I downloaded Cygwin, installed it in C:\cycwin and then I got lost, but I found out that the .h files were located in C:\cycwin\usr\include so I moved all the content to C:\codeblocks\mingw\include\. Then I tryed to compile the following example:

/*

** 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;

}


But I got the following errors:


-------------- Build: Release in sock_beej ---------------


Compiling: main.cpp

In file included from C:/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/asm/socket.h:14,

                 from C:/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/cygwin/socket.h:48,

                 from C:/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sys/socket.h:15,

                 from C:\MeusTestes\sock_beej\main.cpp:8:

C:/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/cygwin/if.h:79: error: `caddr_t' does not name a type

In file included from C:/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sys/socket.h:15,

                 from C:\MeusTestes\sock_beej\main.cpp:8:

C:/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/cygwin/socket.h:55: error: `__uid32_t' does not name a type

C:/CodeBlocks/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/cygwin/socket.h:56: error: `__gid32_t' does not name a type

C:\MeusTestes\sock_beej\main.cpp: In function `int main(int, char**)':

C:\MeusTestes\sock_beej\main.cpp:14: error: aggregate `addrinfo hints' has incomplete type and cannot be defined

C:\MeusTestes\sock_beej\main.cpp:16: error: `INET6_ADDRSTRLEN' was not declared in this scope

C:\MeusTestes\sock_beej\main.cpp:27: error: `getaddrinfo' was not declared in this scope

C:\MeusTestes\sock_beej\main.cpp:28: error: `gai_strerror' was not declared in this scope

C:\MeusTestes\sock_beej\main.cpp:28: warning: unused variable 'gai_strerror'

C:\MeusTestes\sock_beej\main.cpp:27: warning: unused variable 'getaddrinfo'

C:\MeusTestes\sock_beej\main.cpp:34: error: invalid use of undefined type `struct addrinfo'

C:\MeusTestes\sock_beej\main.cpp:14: error: forward declaration of `struct addrinfo'

C:\MeusTestes\sock_beej\main.cpp:40: error: invalid use of undefined type `struct addrinfo'

C:\MeusTestes\sock_beej\main.cpp:14: error: forward declaration of `struct addrinfo'

C:\MeusTestes\sock_beej\main.cpp:41: error: invalid use of undefined type `struct addrinfo'

C:\MeusTestes\sock_beej\main.cpp:14: error: forward declaration of `struct addrinfo'

C:\MeusTestes\sock_beej\main.cpp:45: error: invalid use of undefined type `struct addrinfo'

C:\MeusTestes\sock_beej\main.cpp:14: error: forward declaration of `struct addrinfo'

C:\MeusTestes\sock_beej\main.cpp:46: error: invalid use of undefined type `struct sockaddr_in6'

C:\MeusTestes\sock_beej\main.cpp:45: error: forward declaration of `struct sockaddr_in6'

C:\MeusTestes\sock_beej\main.cpp:51: error: invalid use of undefined type `struct addrinfo'

C:\MeusTestes\sock_beej\main.cpp:14: error: forward declaration of `struct addrinfo'

C:\MeusTestes\sock_beej\main.cpp:51: error: `ipstr' was not declared in this scope

C:\MeusTestes\sock_beej\main.cpp:55: error: `freeaddrinfo' was not declared in this scope

C:\MeusTestes\sock_beej\main.cpp:16: warning: unused variable 'INET6_ADDRSTRLEN'

C:\MeusTestes\sock_beej\main.cpp:55: warning: unused variable 'freeaddrinfo'

Process terminated with status 1 (0 minutes, 1 seconds)

21 errors, 4 warnings

 

Ignoring the fprintf errors, what's wrong there?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users