Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8742675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:32:29+00:00 2026-06-13T11:32:29+00:00

I need to resolve some hostnames from my application. Is there any alternative to

  • 0

I need to resolve some hostnames from my application. Is there any alternative to gethostbyname where I can give as a parameter my own DNS server to use as a resolver?

I have already coded my own function, but I thought there may be one I don’t know about.

I am using Linux/C language. My libc is uclibc. But I am also curious about GNU LibC.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:32:30+00:00Added an answer on June 13, 2026 at 11:32 am

    You’ll need to do your own query, but it isn’t difficult.

    To do this, you would want to use the res_query() family of functions, which allow you to specify the resolver through an environmental variable:

    The res_init() function reads the configuration files (see resolv.conf(5)) to get the default domain name, search order and name server address(es). If no server is given, the local host is tried. If no domain is given, that associated with the local host is used. It can be overridden with the environment variable LOCALDOMAIN

    IBM’s docs go a little more in depth with how to set the variable:

    The configured search list (struct state.defdname and struct state.dnsrch) can be overridden by setting the environment variable LOCALDOMAIN to a space-separated list of up to 6 search domains with a total of 256 characters (including spaces). If a search list is specified, the default local domain is not used on queries.

    Notes –

    • You should call setenv() prior to calling res_init(), or the setting will not be picked up. Remember to unset it once done, if applicable

    • If you use hostnames for the search domains, /etc/hosts still takes precedence.

    • res_init() was made properly reentrant in uclibc in 2007, so I’m pretty sure you could just use it for whatever purpose.

    These functions have the additional benefit of being able to retrieve more detailed data (MX, etc) as well. Still, if you have something smaller that works equally well, there’s no sense in not using it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to setup a DNS server only to resolve the name of our
I need to resolve a hostname using a specific DNS server like you would
Here in the below code i need some info on cloning there is a
Some specific requests in my application need to go over MMS APN . This
I need to call easy_install as a function to install some Python eggs from
Hi Need help to resolve some complicated query. I'll send the input username (say
I need to configure different implementations of some interface, and make it resolve based
Is there a clean way to resolve a DNS query (get IP by hostname)
Colleagues, Using JPA I need resolve following issue: at database level exits 3 entities
I need to resolve an assembly and type at runtime and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.