Re: NSNetService, IP address and port number
Re: NSNetService, IP address and port number
- Subject: Re: NSNetService, IP address and port number
- From: Axel Andersson <email@hidden>
- Date: Thu, 16 Jan 2003 23:37:29 +0100
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.
#import <sys/types.h>
#import <sys/socket.h>
#import <netinet/in.h>
#import <arpa/inet.h>
NSString *ip;
struct sockaddr_in *addr;
int port;
addr = (struct sockaddr_in *) [[[aNetService adresses] objectAtIndex:0]
bytes];
ip = [NSString stringWithCString:(char *) inet_ntoa(addr->sin_addr)];
port = ntohs(addr->sin_port);
Cheers,
Axel Andersson
_______________________________________________
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.