This is going to sound like a idiot question, how do I get the right IP for a host?

This is a discussion on This is going to sound like a idiot question, how do I get the right IP for a host? within the C++ Programming forums, part of the General Programming Boards category; Im using Visual C++ 6.0 and I used the CAsyncSocket class to start up a host server for a chatroom ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    33

    Question This is going to sound like a idiot question, how do I get the right IP for a host?

    Im using Visual C++ 6.0 and I used the CAsyncSocket class to start up a host server for a chatroom that updates each time a message is sent. Sounds like I know what I'm doing huh? Program is even finished. 0 Errors so far in the compiler, but no telling if theres any logic errors yet. You'd think I would have this thing figured out... but nooooooooooooooo

    I seriously can't figure out what my IP is for my client to connect to.

    I searched the wonderful gallery of Windows help files and it returned winipcfg. Unfortuantely this program gives me like 7 diffrent IPS! So which one is it. Im out on a limb here guys, can ya throw me a bone?

    - Zedd
    "Who ya gonna call?"

    AWAX

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    4
    I believe it depends on what method you use to connect to the internet. If you are on standard 56k dialup service, you will most likely get a new IP address each time you log in (dynamic). If you are on cable service, however, you most likely have a static IP address.

    In any case, I know that if you have 56k dialup service, the correct IP address is the one listed under PPP adapter. With my DSL service, it lists my IP address under the name of my DSL "modem."

  3. #3
    Registered User WayTooHigh's Avatar
    Join Date
    Aug 2001
    Posts
    101
    i wrote this little bit of code. it works on my computer. it will show your ip and your host name. just create a Win32 Console app and add wsock32.lib to the project.
    Code:
    #include<windows.h>
    #include<iostream.h>
    
    int main()
    {
    	LPHOSTENT szHost_IP;
    	
    	struct in_addr in_IP;
    	char szHost_Name[255],
    		szYour_IP[255];
    
    	WSADATA WSAData;
    
    	if(WSAStartup(MAKEWORD(2,0), &WSAData))
    	{
    		cout<<"ERROR";
    		return 0;
        }
    
    	gethostname(szHost_Name, sizeof(szHost_Name));
    	szHost_IP = gethostbyname(szHost_Name);
    	in_IP = *(struct in_addr FAR *)(szHost_IP->h_addr);
    
    	wsprintf(szYour_IP, "Your Host Name - %s\n\n", szHost_Name);
    	cout<<szYour_IP;
    	
    	wsprintf(szYour_IP, "Your IP - %s\n\n", inet_ntoa(in_IP));
    	cout<<szYour_IP;
    
    	return 0;
    }
    hope it works. if not re-post.
    Sometimes, the farthest point from the center is the center itself.

    Your life is your canvas, it's only as beautiful as you paint it.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    33

    Another great idiot's question.

    That code probably does exactly what I'm trying to code. However, how do I add thw Winsock lib to a Win32 Console in VC? Any idea?
    "Who ya gonna call?"

    AWAX

  5. #5
    Registered User WayTooHigh's Avatar
    Join Date
    Aug 2001
    Posts
    101
    when your project is open, press 'Alt+F7'. this opens your project settings. click on the 'Link' tab. click on the edit box below 'Object/library modules:'. press the 'End' key on your keyboard. then press the spacebar. and enter 'wsock32.lib'. click 'OK'. and there ya go. it's added.
    Sometimes, the farthest point from the center is the center itself.

    Your life is your canvas, it's only as beautiful as you paint it.

  6. #6
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    it's a lot nicer to do it in-line in your code

    #pragma comment(lib, "wsock32.lib") //no ;

  7. #7
    Registered User WayTooHigh's Avatar
    Join Date
    Aug 2001
    Posts
    101
    Originally posted by -KEN-
    it's a lot nicer to do it in-line in your code

    #pragma comment(lib, "wsock32.lib") //no ;
    you're right that is alot nicer. i didn't know you could include a lib with code. its good to know. thanks.
    Sometimes, the farthest point from the center is the center itself.

    Your life is your canvas, it's only as beautiful as you paint it.

  8. #8
    Unregistered
    Guest
    And if you just want to test your chat proggy on your computer by running the server and client, then just connect to 127.0.0.1 or localhost (both of those mean connecting to your computer, ie not even using the 'net)

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    33

    I tried that...

    With my prog I tried using 127.0.0.1 and "loopback". Neither did the job, the buffer was full of 1024 of giibberish and it just read in the gibberish. Does anyone have any sample code of VERY basic TCPIP? Apparently I guess Im not getting it... :-(

    I posted my functions for that proggy in another post. But noone responded. :-(

    It's just no my week I guess. Ill try this IP snatcher. Thanks everyone. - Zedd
    "Who ya gonna call?"

    AWAX

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    33
    HELLLLLLLLPPPPPPPPPP ! :-)

    void CSock2Dlg::Onclient()
    {
    m_socket.Create() ;
    m_socket.Connect("loopback",4000) ;
    }

    void CSock2Dlg::Onexit()
    {
    OnOK();
    }

    void CSock2Dlg::Onserver()
    {
    m_socket.Create(4000) ;
    m_socket.Listen() ;



    }

    void CSock2Dlg::Onaccept()
    {
    m_socket.Accept(m_socket2) ;

    }

    void CSock2Dlg::Onsend()
    {
    CString strMyMessage;
    strMyMessage = m_sbox ;
    int iLen;
    iLen = strMyMessage.GetLength();
    m_socket.Send(LPCTSTR(strMyMessage), iLen);
    }

    void CSock2Dlg::Onrecieve()
    {
    char *pBuf = new char[1025];
    int iBufSize = 1024;
    int iRcvd;
    CString strRecvd;
    iRcvd = m_socket.Receive(pBuf, iBufSize);
    if (iRcvd == SOCKET_ERROR)
    {
    // Do some error handling here
    }
    else
    {
    pBuf[iRcvd] = NULL;
    strRecvd = pBuf;
    // Continue processing the message
    }

    m_mbox = strRecvd ;
    UpdateData(FALSE) ;

    }
    "Who ya gonna call?"

    AWAX

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about My WAN IP
    By failure_to in forum Networking/Device Communication
    Replies: 5
    Last Post: 08-22-2004, 01:45 PM
  2. Sound question
    By Rev. Jack Ed in forum Game Programming
    Replies: 4
    Last Post: 11-28-2003, 11:35 PM
  3. Sound Driver Programming Question
    By phos2k in forum Linux Programming
    Replies: 1
    Last Post: 11-10-2003, 10:07 PM
  4. Question on sound in a game of mine.
    By Vanished in forum C++ Programming
    Replies: 4
    Last Post: 12-09-2002, 04:46 PM
  5. Question on sound in a game of mine
    By Vanished in forum Game Programming
    Replies: 2
    Last Post: 12-09-2002, 12:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21