Thread: systray app to get IP Address

  1. #16
    Registered User
    Join Date
    Aug 2002
    Originally posted by anonytmouse
    char port='7';
    rc = getaddrinfo(hostname,&port,NULL,&res);

    [in] Pointer to a null-terminated string containing either a service name or port number.

    You are not passing a proper port string to getaddrinfo.
    I made this change, but I still get the same result.

    I didn't use gethostbyname becase the manual pages say that it is depricated by getaddrinfo.

    I know I'm closer than I have been before. I will try and get this working today. Thanks for your help.
    Best Regards,


  2. #17
    Registered User
    Join Date
    Aug 2002

    Thumbs up

    It works!

    What I ended up having to do was cast between a winsock 1 and winsock 2 structure to get access to the in_addr structure that the inet_ntoa function needed.

    Here is my working code:

    	WORD wVersionRequested;
    	WSADATA wsaData;
    	int err;
    	wVersionRequested = MAKEWORD( 2, 2 );
    	err = WSAStartup( wVersionRequested, &wsaData );
    	if ( err != 0 ) {
        /* Tell the user that we could not find a usable */
        /* WinSock DLL.                                  */
    	char host[255];
    	char *hostname=&host[0];
    	struct addrinfo *res = NULL;
        int             rc;
    	char *port=new char[25];
    	rc = getaddrinfo(hostname,port,NULL,&res);
        if (rc != 0)
           fprintf(stderr, "Invalid address %s, getaddrinfo failed: %d\n", hostname, rc);
    	struct sockaddr_in *myip;
    	myip=(sockaddr_in *)res->ai_addr;
    	char *ipaddr=new char[16];
    	sprintf(ipaddr,"%s",inet_ntoa( myip->sin_addr ));
    	delete [] ipaddr;
    	delete [] port;
    Best Regards,


  3. #18
    Registered User
    Join Date
    Aug 2002
    Originally posted by _Elixia_
    Maybe then that you have an old version of ssh. When I ssh into my shell account here, this is what I get:

    bash-2.05$ who -m!jamesp pts/13 Sep 18 18:30 (
    It does work on Linux. But It doesn't work on SUN, IBM, or HP UNIX.
    Best Regards,


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I thought pointers were pointers...
    By keira in forum C Programming
    Replies: 19
    Last Post: 08-15-2007, 11:48 PM
  2. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  3. how get ip address on 2 network cards
    By akesayyo in forum C Programming
    Replies: 8
    Last Post: 07-04-2005, 10:15 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. MSN Vital Information
    By iain in forum A Brief History of
    Replies: 9
    Last Post: 09-22-2001, 08:55 PM