• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSNetService, IP address and port number
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNetService, IP address and port number


  • Subject: Re: NSNetService, IP address and port number
  • From: j o a r <email@hidden>
  • Date: Thu, 16 Jan 2003 23:12:36 +0100

You can do something like this to get the address from the NSData:

#import <netinet/in.h>
#import <arpa/inet.h>

+ (NSString *) addressFromData:(NSData *) addressData
{
NSString *adr = nil;

if (addressData != nil)
{
struct sockaddr_in addrIn = *(struct sockaddr_in *)[addressData bytes];
adr = [NSString stringWithFormat: @"%s", inet_ntoa(addrIn.sin_addr)];
}

return adr;
}

+ (NSString *) portFromData:(NSData *) addressData
{
NSString *port = nil;

if (addressData != nil)
{
struct sockaddr_in addrIn = *(struct sockaddr_in *)[addressData bytes];
port = [NSString stringWithFormat: @"%s", inet_ntoa(addrIn.sin_port)];
}

return port;
}

("Programmed" in Mail, so watch out for typos...)

j o a r


On Thursday, Jan 16, 2003, at 22:16 Europe/Stockholm, kubernan wrote:

I think i have to use something like [aNetService adresses] and read the returned array,
but i don't know how to use the NSData item of the array with the sockaddr structure
for reading the ip address and port number.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSNetService, IP address and port number
      • From: j o a r <email@hidden>
References: 
 >NSNetService, IP address and port number (From: kubernan <email@hidden>)

  • Prev by Date: Safari bookmark bar
  • Next by Date: NSTask/NSPipe STDIN hangs on large data, sometimes...
  • Previous by thread: NSNetService, IP address and port number
  • Next by thread: Re: NSNetService, IP address and port number
  • Index(es):
    • Date
    • Thread