Determining own IP address

I've got a socket app that wants to figure out the IP addr of the iPhone it's running on. gethostname followed by gethostbyname works if there's a DNS server but I may be running with static IP addresses in an AdHoc network and in that case gethostbyname fails. What are my other options? I read about NSHost, will that work without DNS server? I also heard about System.Configuration framework but could not find anything related to the IP address of the device.
Thanks,
Andrew

This is actually a fairly tricky thing to determine as you can have multiple IP addresses. Try the following:
// Get my address.
- (NSString *) address
NSMutableString * result = [NSMutableString new];
struct ifaddrs * myaddrs;
if(!getifaddrs(& myaddrs))
for(ifaddrs * ifa = myaddrs; ifa; ifa = ifa->ifa_next)
if(!ifa->ifa_addr)
continue;
if((ifa->ifa_flags & IFF_UP) == 0)
continue;
// buf must be big enough for an IPv6 address
// (e.g. 3ffe:2fa0:1010:ca22:020a:95ff:fe8a:1cf8)
char address[64];
address[0] = 0;
if(strncmp("lo", ifa->ifa_name, 2)
&& ifa->ifaaddr->safamily == AF_INET)
struct sockaddr_in * s4 = (struct sockaddr_in *)(ifa->ifa_addr);
inet_ntop(
ifa->ifaaddr->safamily,
(void *) & (s4->sin_addr),
address,
sizeof(address));
if(strlen(address) > 0)
if([result length] > 0)
[result appendString: @"
[result appendFormat: @"%s:%d", address, [self port]];
freeifaddrs(myaddrs);
return [result autorelease];

Similar Messages

  • Someone is using my personal email address for their apple ID and I'm sick of it! I can't sign up for my own itunes account or anything using MY OWN email address. My email address is my property, not theirs.

    Someone is using my personal email address for their apple ID and I'm sick of it! I can't sign up for my own itunes account or anything using MY OWN email address. My email address is my property, not theirs.
    I'm using their account and will continue to reset their password and settings until they either get the message or Apple do something about it and disable or migrate their account so that I can use MY OWN email address for my own purposes.
    I don't want to be informed about Apple products and services for someone else on my email account.
    I want to be able to use it MYSELF for iTunes
    All I am asking you to do is migrate their apple ID to their alternate email account settings and free up my email address so that:
    A. I can use it and B. I stop getting messages about their account history.
    Either that or just cancel their account as they have no right to use my personal details.
    Yes I could set up a new email address but WHY THE **** should I? I've been using this email account for years for personal stuff, it's not mu fault if someone can sign it up as an AppleID without me being able to confirm their sign up process!
    Your move Apple, make it count.

    Hi Sister Kate,
    If you change the Apple ID you are using on an iPhone or other iOS device, there are several places you need to change it on the device. See this article -
    Apple ID: What to do after you change your Apple ID
    Thanks for using Apple Support Communities.
    Best,
    Brett L 

  • I created an Apple ID for my daughter with her own gmail address, but I want her Apple ID and primary email address to be an iCloud email address. How can I do this? I can't set up an icould email address for her without first creating an Apple ID?

    I have created an Apple ID for my daughter with her own gmail address as the primary email address, but I want her Apple ID and primary email address to be an iCloud email address. How can I do this? I can't set up an icould email address for her without first creating an Apple ID right?
    I'm not good with computers so please explain in simple way...:)
    I also wonder what the best way is to set up accounts for children in a family. I dont want them to be able to purchase apps etc through the parents accounts, also some things we like to share as a family and others we don't want to share. Is there any good. clear, simple explanation from Apple Support about these issues? Or best to go to Apple store and go to genius bar or one to one advise?
    thanks

    You can set up an iCloud account which makes the iCloud email address you choose the Apple ID and thus the login for it:
    https://discussions.apple.com/message/22283348#22283348
    though I have to say I think it's more sensible if the ID is another address, both for security reasons (so people don't know what the login is) and as a contact address from Apple if the account were to stop working and they needed to contact you. So personally I would to to System Preferences, enter the GMail address which is an ID, and then choose a nerw @icloud.com address.
    If she has her own iCloud account she will need either her own computer or her own user account on your Mac to be able to make use of it. You should note that under Apple's terms of use Apple IDs are only available to children of 13 and over.
    As to purchasing apps, this is nothing to do with iCloud: it's iTunes, and the login can be different. So you can all sign into the same iTunes account but have different iCloud accounts. Or she can have her own iTunes account if she is of suitable age (credit card needed for purchasing apps).
    If you have other children you should be aware that any one Mac or device can create only three iCloud accounts - this is tied to the serial number, not the user account, and once reached cannot be bypassed. You can of course sign into an iCloud account created on another device.

  • I have an itunes account with 3 ipods can we each have our own email address

    can we have our own email address if we share the 1 itunes account???

    There can be only one emailladdress accociate with an Apple/iTunes ID.  However, after you initiall set up the Messages and FaceTime apps with the Apple/iTunes ID you can add another email amessaging/calling addresses and delete the Apple/iTunes email address.

  • My mac air will not connect to the internet. There is an exclamation point in the wifi icon and when i go into preferences i see that it is setting its own IP address. I have a macbook that is able to connect with no issue. HELP

    My macbook air will not connect to the internet. There is an exclamation point in the wifi icon and when i go into preferences i see that it is setting its own IP address. I have a macbookpro that is able to connect with no issue. HELP

    Reset the TC to factory and start again.
    Use all SMB type names for wireless and base station.. Not apple type names.. this is more important since Mavericks.
    I also recommend different names for the different bands.
    So for example.
    TC name.. TCgenx (I use whatever the generation number is for the x.. eg TCgen4 or latest one TCgen5)
    WIreless name.. TC24ghz for 2.4ghz
    TC5ghz for 5ghz
    You can also set the channel manually.
    If you still have issues.. start with no security and then if it fails to connect there is something seriously wrong with the laptop. Did you upgrade install Mavericks?? That can lead to driver issues.. I would recommend a clean install.

  • My wife and I share an Ipad.   We each have our own email address and calendar.   What is the best way for us to backup both accounts (we currently only have 1 ICloud account)?   Thanks for any help!    Alan

    My wife and I each have our own email address and calendar.  These are on one IPad.   The Ipad has a single ICloud account.
    What's the best way to backup both Calendars, etc?   Does ICloud automatically back up every account on the same IPad?  (I checked ICloud, but I could only find my stuff.)
    Thanks for any help!
    Alan

    First, you need to understand that there's a difference between "syncing" and "backup".  Backup is the saving of content and settings, where syncing is the bidirectional transfer of content for an account to a web-based server (like iCloud, Gmail, Yahoo, etc.)
    If you see your calendar in your iCloud account, that implies that you have set up your iCloud account to host (sync) your calendar, and perhaps contacts, email, and notes.  An iCloud account can only sync one user's information at a time so it is intended to support a single user.  You can have more than one iCloud account, and you can even have more than one iCloud account on the same device (but one has to be primary, and the secondary iCloud has limited capabilities), but a single iCloud account only supports a single user's content.
    Backup is the saving of your device's content and settings to use in case you need to recover these things, but you can't see the contents of your backup (just the size and device name).  You can backup more than one device to iCloud and you can backup to iCloud or you can backup to your computer, or both (one at a time though, you have to choose). 
    So, if your wife has her own email and calendar she can certainly do that in parallel to whatever account(s) you have for email and calendar.  But if you have only one iCloud account then only one of you can use it for email, calendar, etc.  But the backup of these accounts is really just a backup of the device's settings that link the device to these accounts. For example, if she uses Gmail then the backup of the iPad only backs up the fact that your iPad is set up to use her account, it does not backup the account itself (the content of her account is saved and preserved on Google's servers, not your device's backup).
    Does that make better sense?

  • How to get the own IP-Address

    Dear All
    How can I read out the own IP-Address from my MIDP1.0 after I have opened a TCP socket.
    I haven't found any method/way in J2ME so far to get the own address that the GSM-provider has assigned to my mobile.
    Any hints or ideas would be appreciated
    Regards
    Sektionschef

    Hello,
    that is not possible because your mobile phone does not have an actual ip address, at least as far as I understand it. The gprs or hsdc gateway does and then it converts all traffic to some low level protocol which it uses to route the right stuff to your phone.
    A simple test would safice, write a simple servlet which logs all connections and then connect to it from your phone. Then disconnect your gprs/hsdc connection and connect again. Try to access the servlet and it will show the same IP address, the one of the gateway facilitating the communication.
    Hope this helps.
    Regs jP

  • Mail: typing my own email address in composition window PROBLEM

    This is a weird problem which arose in the last few weeks. When I type my own email address in a composition window, Mail will add a bunch of HTTP like text to the text. Here is an example in which I have changed my real address to a fake one:
    This is my email mail@http://www.http://www.http://www.fakedomain.comcomcomcom.
    This does NOT happen with any other addresses, just mine, which is the same address setup in my accounts. If I try using the delete key to remove the faulty text, it just keeps adding more of the same. ***? I'm perplexed.
    Any ideas?
    Mail version 4.2 (1077)
    OS 10.6.2

    The following test might be helpful in deciding what to try next: Create a New User Account, and as that New User try to set up at least one account -- if POP set to leave messages on the server. If not familiar with setting up a New User Account, see:
    http://docs.info.apple.com/article.html?path=Mac/10.5/en/8235.html
    This will be a useful test to now check this behavior in another User Account, and of course is not meant to suggest a permanent switch to the New User Account, but rather a test of the Mail application outside of your normal User Account, and hopefully outside the use of Mail Unread. You could then set that User up to use Mail Unread, and see if the same happens there.
    Ernie

  • Cisco ACE can rserver use it's own VIP address ?

    we've configured a serverfarm with a real server and a VIP.
    The serverfarm can be reached and is functioning well.
    Now we want the rserver to be able to reach it's own VIP address.
    This is needed because the rserver has multiple websites which need each other
    and we want to have load balancing.
    Is this a supported configuration ?
    regards,
    Sebastian

    you can simply add a new policy to match the servers ip addresses and then configure nat.
    ie:
    class-map match-all servers
    2 match source-address 192.168.30.48 255.255.255.255
    policy-map multi-match client-nat
    class servers
    nat dynamic 1 vlan 30
    interface vlan 20
    ip address 192.168.20.121 255.255.255.0
    alias 192.168.20.124 255.255.255.0
    peer ip address 192.168.20.123 255.255.255.0
    no normalization
    mac-sticky enable
    access-group input PERMIT-ANY
    service-policy input ALLOW-ALL
    service-policy input client-nat
    service-policy input SLB1
    no shutdown
    interface vlan 30
    bridge-group 30
    no normalization
    mac-sticky enable
    access-group input PERMIT-ANY
    nat-pool 1 10.10.20.1 10.10.20.100 netmask 255.255.255.0
    In this case I nat the to an address in 10.10.20.0/24 subnet and I have a static route on the servers pointing this subnet to ACE.
    You could also use a free ip from the same server subnet and no static route would be required.
    Also if ACE is already the default gateway for the servers, no specific static route is required.
    Also, in this example, I'm not really nating a server. But the idea is the same. The only difference is that in your case, the outgoing interface will be the same as the incoming interface. Me I have everything in vlan 20 and vlan 30. You will have everything in vlan X and only vlan X.
    Gilles.

  • Can SAPSprint support the printers without own IP address(USB printer)?

    Dear all,
    We want to switch SAPlpd to the new tool SAPSprint for Server based printing.
    Our SAP version is 4.6C. We has SAPlpd on our print server (address is 192.168.214.222).
    We have two kinds of printers.
    One kind are network printers with own IP address.
    The other kind are USB printers without own IP address, need to be connected to user's computer.
    Now we have installed SAPSprint on a new server(address is 192.168.214.223).
    We found that it is OK for network printer.
    For example we have a network printer named NP1, NP1's output device in sap system(SPAD) is named NP01,
    Host spool access method is 'S',
    our old print server(SAPlpd installed on it) address is 192.168.214.222,
    the new print server(SAPSprint installed on it) address is 192.168.214.223.
    We install NP1 on the new print server(install driver for NP1 during this process),
    then change the config of Destination host of output device NP01 in SPAD,
    change it from 192.168.214.222 to 192.168.214.223.
    (the config of Host printer we use the same name NP1,no need to change,also use Host spool access method 'S')
    It is OK for NP1's using,
    the SAPSprint replace SAPlpd to provide sap print service on the new server for NP1.
    But for the USB printers, the SAPSprint seem not support.
    We have a USB printer named UP1, UP1 is connect to a user computer named CP1,
    UP1 is installed on CP1(install driver for UP1 on CP1),
    and set UP1 for share as name UP1,
    UP1's output device in sap system(SPAD) is named UP01,
    Host spool access method is 'S'.
    We add the printer UP1 on the old server(address is 192.168.214.222),
    notice it is add not istall, printer UP1 is installed on CP1,
    it will show as a name 'UP1 on CP1' in 'Printers and Fax' view.
    our config of Host printer in SPAD is
    CP1\UP1,
    the config of Destination host is 192.168.214.222.
    This setting is OK for SAPlpd environment.We can use UP1 sucessfully for sap print.
    But when also add the printer  on the new printer server(address is 192.168.214.223),
    and change the config of Destination host from 192.168.214.222 to 192.168.214.223.
    We found that this setting doesn't work in SAPSprint environment.
    It will reply 'SAPlpd err'.In fact we are using SAPSprint on server 192.168.214.223.
    We found the below important information in sapnote 894444:
    All printers that SAPSprint uses must be installed on the SAPSprint computer.
    In our case, the SAPSprint computer is the new server 192.168.214.223
    Network printer NP1 is installed on  the new server 192.168.214.223, NP1 can work well.
    USB printer UP1 not installed on  the new server 192.168.214.223, 
    it is installed on user computer named CP1, and is set share,
    we add UP1 on the new server 192.168.214.223, UP1 doesn't work.
    Is this means SAPSprint doesn't support the USB printers (without own IP address) in Server based printing conditon?
    Any experienced please give your advice.
    Regards
    Allen
    Edited by: allenGG on Sep 9, 2011 12:00 PM

    In fact, finally we found SAPSprint can support the USB printers, but not good and stable enough.
    Sometimes the SAP print request of USB printers not printed out, we didn't find why it happened.
    And for the network printers, we found it is good working in SAPSprint environment.
    We have more than 10 usb printers. They are used for our production department which is 24 hours running.
    Since each printer is only used for each user computer(not for share),
    so at the end we use front end printing method for these printers.

  • Will not recieve own email address will recieve all other e-mails

    will not recieve own email address will recieve all other e-mails
    When emails are sent from ipad to own address they do not show on thunderbird
    they do show on webmail
    is this in thunderbird settings

    Do you have Pop or IMAP mail account?
    Is it a gmail account?
    When you say 'When emails are sent from ipad to own address', are these emails sent via webmail or Thunderbird?
    When you say 'they do show on webmail', what folder are they in?

  • Mail: Reply all includes own email address

    Apple Mail in Yosmite includes my own email address when I reply to all.
    I can't remember Mavericks or before used to do this.
    Anyway, is there a way to turn this off?

    Same here. I have three seperate mail accounts and when I reply to the emails within their respective inboxes everything is fine. But if its a message that is moved out of the inbox because a rule has been applied, then all bets are off. If I reply to one of those messages it cc's me and does not "Send from the Account of the selected mailbox.
    APPLE WE NEED HELP!!!

  • I have an iPhone 5s running ios 7.1. I am unable to send emails to any of my own email addresses from my iphone.

    I have an iPhone 5s running ios 7.1. I am unable to send emails to any of my own email addresses from my iphone.

    This is a new problem.

  • IMac wifi assigns it's own ip address and won't connect

    I just install Lion hardwired through my ethernet port, but when I try to use the WiFi connection it assigns it's own IP address and won't connect.  I did the exact same process with my other iMac and had no issues.
    Any idea what can be causing this problem?

    Okay, problem resolved.  I rebooted my entire ATT Uverse system and the computer instantly picked up the connection.

  • How to assign a website its own IP Address on mac os x snow leopard?

    How to assign a website its own IP Address on mac os x snow leopard?
    Not the personal website: (http://192.168.1.5/~user/)

    Apache Virtual Host documentation - Apache HTTP Server

Maybe you are looking for

  • Can I use the same charger between my Ipad2 and my Iphone 5s

    Is the plugin charger the same for both Ipad2 and Iphone 5s i.e. The actual charging volts/amps etc. I know the cables are different

  • Adding field from Custom Infotype in Screen Header-PA30

    Hi all, Can we add the fields from custom infotype to the screen header in PA30? When I tried through Change Screen Modifications, I could not see the custom infotype in the Infotype column, so I could not select the required field. Please guide. Tha

  • Safari + 10.4.6 = Problem (HELP)

    I updated to 10.4.6 through my update software. It dowloaded the PPC update. Then every page that I upload in Safari will not have pictures, banners etc. For example I go to myspace.com and backgrounds and pictures will not load up. Here is a list of

  • Blackberry died need help

    my curse 8250 died so have been trying to do a system update like it tells you to do but it get to the stage were it says reconnecting to JVC and a message comes up saying app loader was unable to connect to the device. please re connect type in pass

  • How to convert a word document to pdf

    How do I convert a word document to pdf