How can I translate IP to hostname in C - FreeBSD

This is a discussion on How can I translate IP to hostname in C - FreeBSD ; 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/lis...reebsd-hackers To unsubscribe, send any mail ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: How can I translate IP to hostname in C

  1. How can I translate IP to hostname in C

    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/lis...reebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  2. Re: How can I translate IP to hostname in C

    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/lis...reebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  3. Re: How can I translate IP to hostname in C

    On Thu, May 22, 2008 at 04:14:46PM +0000, 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 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/lis...reebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  4. Re: How can I translate IP to hostname in C

    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/lis...reebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  5. Re: How can I translate IP to hostname in C

    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/lis...reebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


+ Reply to Thread