Re: How can I translate IP to hostname in C

2008-05-23 Thread Oliver Fromme
Bjoern A. Zeeb wrote:
  John Timony wrote:
   I am writing a c program in FreeBSD,and I can not
   translate a ip to hostname
   ,i wonder if there is a function to take this job...
  
  You mean like gethostbyaddr()?

gethostbyaddr() is considered obsolete, I think.
You should use getaddrinfo() instead, which is more
flexible and easier to use, and it enables you to
easily write code that is independent and agnostic
of the address family (IPv4 vs. IPv6 vs. others).
The manual page contains detailed example code.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH  Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

The most important decision in [programming] language design
concerns what is to be left out.  --  Niklaus Wirth
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


How can I translate IP to hostname in C

2008-05-22 Thread John Timony
Hi,guys

I am writing a c program in FreeBSD,and I can not
translate a ip to hostname
,i wonder if there is a function to take this job...

s.o.s

-Fabonacc



  

___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: How can I translate IP to hostname in C

2008-05-22 Thread Bjoern A. Zeeb

On Thu, 22 May 2008, John Timony wrote:

Hi,


I am writing a c program in FreeBSD,and I can not
translate a ip to hostname
,i wonder if there is a function to take this job...


You mean like gethostbyaddr()?

See also http://www.unixguide.net/network/socketfaq/2.24.shtml for
further inspiration on this but slightly different topic.

--
Bjoern A. Zeeb  Stop bit received. Insert coin for new game.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: How can I translate IP to hostname in C

2008-05-22 Thread Bruce Cran

John Timony wrote:

Hi,guys

I am writing a c program in FreeBSD,and I can not
translate a ip to hostname
,i wonder if there is a function to take this job...



You could use gethostbyaddr(3), but those traditional functions have 
been replaced with more flexible versions such as getnameinfo(3) on 
newer systems.  There's a good introduction to modern sockets 
programming at http://people.redhat.com/drepper/userapi-ipv6.html


--
Bruce Cran
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: How can I translate IP to hostname in C

2008-05-22 Thread Bernd Walter
On Thu, May 22, 2008 at 04:14:46PM +, Bjoern A. Zeeb wrote:
 On Thu, 22 May 2008, John Timony wrote:
 
 Hi,
 
 I am writing a c program in FreeBSD,and I can not
 translate a ip to hostname
 ,i wonder if there is a function to take this job...
 
 You mean like gethostbyaddr()?
 
 See also http://www.unixguide.net/network/socketfaq/2.24.shtml for
 further inspiration on this but slightly different topic.

You can also use the newer getaddrinfo(3)/freeaddrinfo(3).
I think it is bit easier to use and can it transparently handle inet6
addresses as well.
The only downside is that some rare old systems don't support it.
On FreeBSD it is suppoorted since FreeBSD-4, but some commerical
OS implemented it later.

-- 
B.Walter [EMAIL PROTECTED] http://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: How can I translate IP to hostname in C

2008-05-22 Thread Bernd Walter
On Thu, May 22, 2008 at 07:30:45PM +0100, Bruce Cran wrote:
 John Timony wrote:
 Hi,guys
 
 I am writing a c program in FreeBSD,and I can not
 translate a ip to hostname
 ,i wonder if there is a function to take this job...
 
 
 You could use gethostbyaddr(3), but those traditional functions have 
 been replaced with more flexible versions such as getnameinfo(3) on 
 newer systems.  There's a good introduction to modern sockets 
 programming at http://people.redhat.com/drepper/userapi-ipv6.html

Ups - yes that's what I ment in my mail.
I wrote getaddrinfo, which is the other direction...

-- 
B.Walter [EMAIL PROTECTED] http://www.bwct.de
Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm.
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]