• 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: API to convert IP ADDress
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: API to convert IP ADDress
      • From: Alastair Houghton <email@hidden>
References: 
 >API to convert IP ADDress (From: Matt Jaffa <email@hidden>)

  • Prev by Date: Re: Getting accurate bounds for glyph range
  • Next by Date: Re: API to convert IP ADDress
  • Previous by thread: API to convert IP ADDress
  • Next by thread: Re: API to convert IP ADDress
  • Index(es):
    • Date
    • Thread