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 7777599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:11:00+00:00 2026-06-01T18:11:00+00:00

I know how to get the name behind an ip address using the terminal

  • 0

I know how to get the name behind an ip address using the terminal and dig. I.e:

dig @224.0.0.251 -p5353 -x 192.168.0.195 +short

However, I don’t want to use NSTask in my application.
How can I use NSHost to get the name behind an ip address within a LAN? I tried this, but it always returns nil:

NSHost *myHost = [NSHost hostWithAddress:@"192.168.0.195"]; 
NSLog(@"name: %@", [myHost name]);

Thanks a lot!

Edit:
These methods/functions…
+[NSHost hostWithAddress:]
gethostbyaddr(3) – A BSD function
…seem to be the same as:

dig -x 192.168.0.195

If I use that dig command in the terminal it says that no servers could be reached. (Yes I don’t have a DNS server in my LAN), so no wonder I get back nil.

It would be great if I could implement dig @224.0.0.251 -p5353 -x 192.168.0.195 +short (bonjour multicast lookup) in my app without having to use NSTask. 🙂

  • 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-01T18:11:02+00:00Added an answer on June 1, 2026 at 6:11 pm

    It does not use NSHost, but uses the Bonjour-API and it seems to work as you want:

    #import <Cocoa/Cocoa.h>
    #import <dns_sd.h>
    #import <resolv.h>
    
    static void callback(DNSServiceRef serviceRef, DNSServiceFlags flags, uint32_t interfaceIndex,
                         DNSServiceErrorType errorCode, const char *fullname,
                         uint16_t rrtype, uint16_t rrclass,
                         uint16_t rdlen, const void *rdata,
                         uint32_t ttl, void *context) {
    
        char result[1024] = {0};
        dn_expand(rdata, rdata + rdlen, rdata, result, 1024);
        NSLog(@"Found: %s", result);
    }
    
    int main(int argc, char const *argv[]) {
        DNSServiceRef reverseLookupService = NULL;
    
        DNSServiceErrorType error = kDNSServiceErr_NoError;
        error = DNSServiceQueryRecord(&reverseLookupService, kDNSServiceFlagsForceMulticast,
            kDNSServiceInterfaceIndexAny, "5.1.168.192.in-addr.arpa.",
            kDNSServiceType_PTR, kDNSServiceClass_IN,
            callback, NULL);
    
        if (error != kDNSServiceErr_NoError) {
            NSLog(@"Error: %d", error);
            exit(1);
        }
    
        error = DNSServiceProcessResult(reverseLookupService);
    
        DNSServiceRefDeallocate(reverseLookupService);
    
        return 0;
    }
    

    The important part is using DNSServiceQueryRecord with kDNSServiceFlagsForceMulticast. Look at https://developer.apple.com/library/mac/#documentation/Networking/Reference/DNSServiceDiscovery_CRef/dns_sd_h/index.html#//apple_ref/c/func/DNSServiceQueryRecord for more info about this function.

    You’ll have to convert the IP address to in-addr.arpa.-format yourself, but that is not hard (the octets are backwards with “in-addr.arpa.” at the end. IPv6 is probably similar, but I have not tested it).

    It imports resolv.h (and you need to link it to libresolv), but only for dn_expand. The data passed to the callback is compressed, and dn_expand creates a human-readable representation.

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

Sidebar

Related Questions

Does anybody know, is it possible and how can I get name of user
Can we get variable name('PHPSESSID') defined php.ini through some function in PHP? I know
I know of three ways to get a full language name of a CultureInfo
How can i get a process by know process name on mac os?
Does anyone know if it's possible to get the full processor name (as shown
I know I can get touch events in my iPhone app. But these touch
I know how to get the user that last modified a file, but does
I know you can get the SQL, but it's paramterized without the parameters being
Anybody know how to get all of these in a C# app that leads
I have set up my EC2 infrastructure behind an ELB instance and by using

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.