?
Solved

Question on gethostbyname() function

Posted on 2008-10-13
4
Medium Priority
?
319 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

762 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