CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2010
    Posts
    30

    passing IP Address as a parameter

    Hi,
    I am trying to pass the IP Address as a parameter instead of hard coding it, but I am ending with no connection.

    The code is as follows:

    char server_ip_address[16]; //globally declared

    void put_address(char *ip_addr)
    {
    struct sockaddr_in ServAddr;
    ServAddr.sin_addr.s_addr = inet_addr(ip_addr);
    }

    /*calling the put_address function */
    udp_connect()
    {
    ServAddr.sin_family = AF_INET;
    ServAddr.sin_len = sizeof(ServAddr);
    put_address(&server_ip_address);
    ServAddr.sin_port = 5060;
    }

    /*initializing the server_ip_address with IP Address in the main function*/
    main()
    {
    scanf("%s", server_ip_address);
    }

    Any idea where I am making a mistake in my routine.

    Thanks

  2. #2
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    Re: passing IP Address as a parameter

    So when you run it through your debugger, what value gets passed?

  3. #3
    Join Date
    Dec 2010
    Posts
    30

    Re: passing IP Address as a parameter

    I can see that the variable is taking the value which is been given in the main function. But the problem is in my main function I am running other threads as well. Is that is the problem.

  4. #4
    Join Date
    Dec 2010
    Posts
    30

    Re: passing IP Address as a parameter

    got it working, was a small mistake in my code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured