Solved

Question on gethostbyname() function

Posted on 2008-10-13
4
309 Views
Last Modified: 2012-05-05
Hello group,

I'm new to socket programming in C (Linux) and currently trying to retrieve a page which works fine as long as there argument is only something like www.example.com but  for instance if I pass:

myprog   www.example.com

the code returns the html page contents and all tags ...


but if I use it as

myprog  www.example.com/corporate/aboutus.php

It won't work if I add a / or page at the end of it. Any idea why?


Your help is appreciated.

Regards.


It seems in new IPv6 I should use getaddrinfo() but since I'm using somebody's else code so don't want to change it too much.



0
Comment
Question by:akohan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:sweetfa2
ID: 22707893
gethostbyname is trying to resolve an ip address for the host itself.  in your second instance you are passing a full url which cannot be resolved through a dns.
0
 

Author Comment

by:akohan
ID: 22707937


Thanks! now what approach should I take to return an sub page or a page from a server?

Regards.
0
 
LVL 17

Accepted Solution

by:
sweetfa2 earned 500 total points
ID: 22707950
Depends on what you have at the moment to retrieve this.

What does your myprog do after it resolves the hostname.  I am presuming it does asocket  open on port 80 of the resolved address, sends a "GET /" to the opened socket and reads the input.

If this is the case, your myprog will have to split out the host component (before the /) and pass that to gethostbyname, and the remainder of the string should be appended to the GET string.
0
 

Author Comment

by:akohan
ID: 22707976


Yes, that should be it.

Thanks!

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question