Re: API to convert IP ADDress
Re: API to convert IP ADDress
- Subject: Re: API to convert IP ADDress
- From: Sherm Pendley <email@hidden>
- Date: Tue, 2 Mar 2004 15:48:36 -0500
On Mar 2, 2004, at 3:11 PM, Matt Jaffa wrote:
convert IP Address 192.34.12.0 (for example) to the int
representation of it 3495828 (something like that)
// Assuming NSString *address
NSArray *nums=[addr componentsSeparatedByString:@"."];
int rep = [[NSArray objectAtIndex:0]intValue] * 2^24 +
[[NSArray objectAtIndex:1]intValue] * 2^16 +
[[NSArray objectAtIndex: 2]intValue] * 2^8 +
[[NSArray objectAtIndex: 3]intValue];
And also to convert the int representation of the server address back
to 192.34.12.0
NSString *address = [NSString stringWithFormat:@"%u.%u.%u.%u",
(rep & 0xff000000) >> 24, (rep & 0x00ff0000) >> 16,
(rep & 0x0000ff00) >> 8, (rep & 0x000000ff)];
Untested, typed into email, etc... YMMV.
sherm--
_______________________________________________
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.