Solved

Question on gethostbyname() function

Posted on 2008-10-13
4
299 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
  • 2
  • 2
4 Comments
 
LVL 17

Expert Comment

by:sweetfa2
Comment Utility
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
Comment Utility


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
Comment Utility
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
Comment Utility


Yes, that should be it.

Thanks!

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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 purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now