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

Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
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
add a comment |
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
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
networking c
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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