How to programmatically get a hostname's IP address on a local network in C?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0















I'm working on a project where I'd like to transfer data over TCP/IP sockets in a C program between two computers connected over WiFi to a home router, both are running Debian-based Linix distributions. I'd like to be able to connect from the client machine with only knowledge of a hostname of the device. I don't have control over the router and so I can't set a static IP for the device.



Is there an API available for retrieving an IP address given a hostname and where could I go for more information on using that API in C?










share|improve this question

















  • 2





    manpages.debian.org/manpages-dev/getaddrinfo.3

    – A.B
    Feb 3 at 1:04











  • +1 for getaddrinfo() but actually this may just not be possible on a home network depending on DNS and DHCP configuration - if you're using ISP DNS servers directly then the router (which knows hostname to IP mapping) won't provide an answer.

    – Dave C
    Feb 3 at 1:06











  • it's not the best interface anyway (not asynchronous etc), but it's not either doing only dns resolution. it could do mDNS (avahi/zeroconf/bonjour ...) resolution if nsswitch.conf tells to

    – A.B
    Feb 3 at 1:12















0















I'm working on a project where I'd like to transfer data over TCP/IP sockets in a C program between two computers connected over WiFi to a home router, both are running Debian-based Linix distributions. I'd like to be able to connect from the client machine with only knowledge of a hostname of the device. I don't have control over the router and so I can't set a static IP for the device.



Is there an API available for retrieving an IP address given a hostname and where could I go for more information on using that API in C?










share|improve this question

















  • 2





    manpages.debian.org/manpages-dev/getaddrinfo.3

    – A.B
    Feb 3 at 1:04











  • +1 for getaddrinfo() but actually this may just not be possible on a home network depending on DNS and DHCP configuration - if you're using ISP DNS servers directly then the router (which knows hostname to IP mapping) won't provide an answer.

    – Dave C
    Feb 3 at 1:06











  • it's not the best interface anyway (not asynchronous etc), but it's not either doing only dns resolution. it could do mDNS (avahi/zeroconf/bonjour ...) resolution if nsswitch.conf tells to

    – A.B
    Feb 3 at 1:12













0












0








0


1






I'm working on a project where I'd like to transfer data over TCP/IP sockets in a C program between two computers connected over WiFi to a home router, both are running Debian-based Linix distributions. I'd like to be able to connect from the client machine with only knowledge of a hostname of the device. I don't have control over the router and so I can't set a static IP for the device.



Is there an API available for retrieving an IP address given a hostname and where could I go for more information on using that API in C?










share|improve this question














I'm working on a project where I'd like to transfer data over TCP/IP sockets in a C program between two computers connected over WiFi to a home router, both are running Debian-based Linix distributions. I'd like to be able to connect from the client machine with only knowledge of a hostname of the device. I don't have control over the router and so I can't set a static IP for the device.



Is there an API available for retrieving an IP address given a hostname and where could I go for more information on using that API in C?







networking c






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 3 at 0:55









Shane SnoverShane Snover

41




41







  • 2





    manpages.debian.org/manpages-dev/getaddrinfo.3

    – A.B
    Feb 3 at 1:04











  • +1 for getaddrinfo() but actually this may just not be possible on a home network depending on DNS and DHCP configuration - if you're using ISP DNS servers directly then the router (which knows hostname to IP mapping) won't provide an answer.

    – Dave C
    Feb 3 at 1:06











  • it's not the best interface anyway (not asynchronous etc), but it's not either doing only dns resolution. it could do mDNS (avahi/zeroconf/bonjour ...) resolution if nsswitch.conf tells to

    – A.B
    Feb 3 at 1:12












  • 2





    manpages.debian.org/manpages-dev/getaddrinfo.3

    – A.B
    Feb 3 at 1:04











  • +1 for getaddrinfo() but actually this may just not be possible on a home network depending on DNS and DHCP configuration - if you're using ISP DNS servers directly then the router (which knows hostname to IP mapping) won't provide an answer.

    – Dave C
    Feb 3 at 1:06











  • it's not the best interface anyway (not asynchronous etc), but it's not either doing only dns resolution. it could do mDNS (avahi/zeroconf/bonjour ...) resolution if nsswitch.conf tells to

    – A.B
    Feb 3 at 1:12







2




2





manpages.debian.org/manpages-dev/getaddrinfo.3

– A.B
Feb 3 at 1:04





manpages.debian.org/manpages-dev/getaddrinfo.3

– A.B
Feb 3 at 1:04













+1 for getaddrinfo() but actually this may just not be possible on a home network depending on DNS and DHCP configuration - if you're using ISP DNS servers directly then the router (which knows hostname to IP mapping) won't provide an answer.

– Dave C
Feb 3 at 1:06





+1 for getaddrinfo() but actually this may just not be possible on a home network depending on DNS and DHCP configuration - if you're using ISP DNS servers directly then the router (which knows hostname to IP mapping) won't provide an answer.

– Dave C
Feb 3 at 1:06













it's not the best interface anyway (not asynchronous etc), but it's not either doing only dns resolution. it could do mDNS (avahi/zeroconf/bonjour ...) resolution if nsswitch.conf tells to

– A.B
Feb 3 at 1:12





it's not the best interface anyway (not asynchronous etc), but it's not either doing only dns resolution. it could do mDNS (avahi/zeroconf/bonjour ...) resolution if nsswitch.conf tells to

– A.B
Feb 3 at 1:12










0






active

oldest

votes











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f498368%2fhow-to-programmatically-get-a-hostnames-ip-address-on-a-local-network-in-c%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f498368%2fhow-to-programmatically-get-a-hostnames-ip-address-on-a-local-network-in-c%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)