I know that in windows, the HOSTS file located in c:/WINDOWS/system32/DRIVERS/etc/HOSTS is used to map ip address to host names. Is there a similar file in mac OS X? if so, where is it located?
12" iBook G4,
Mac OS X (10.4.7),
512Mb RAM upgrade
You can't see this file by poking around in the Finder since it hides /etc, but you can get there via Terminal.app or via the Finder's Go -> Go to Folder option.
One other thought - are you trying to read or write to this file?
If you're trying to write to it (which is an unusual thing to do), it's owned by root so your application will need to run with elevated privileges in order to change it.
If you're just reading it, there shouldn't be any need - the standard system resolver should reference /etc/hosts when you try to resolve any hostname.
im actually trying to write a completely new application, a joke application to give to my friend. I wrote the file for windows, and got it to work just fine with the absolute directory. Now im trying to port it to the mac. The problem is that when i put in the absolute path for the /etc/hosts it does nothing. Someone earlier back said it was because of the permissions. I dont think im using vi or pico to edit it, just the application itself to rewrite the file. Im wondering if it would be easier to just have the modified hosts file bundled in the application, then replace the old with the new. would this be possible. Oh and I think I should tell you, I am using the allegro game library when im programming in xcode.
Well, there's one of the reasons why Mac OS X is considered more secure than Windows.
The hosts file has the potential to compromise a user's system and therefore there are restrictions on the file. Your app can't touch it without some kind of input from the user.
Having a copy of the file won't help (and is actually a bad idea since you don't know what the user has in their /etc/hosts and you risk losing it). You'd still need root permissions to overwrite the file.
You still need to either run your app as root or prompt the user at runtime for elevated privileges to touch the file.
OK, thank you, now im not sure that you are familiar with C, but if I am trying to refer to that file with fopen, what would the directory be, because I try /etc/hosts and it doesn't work.
Technically, /etc is a symlink to /private/etc/passwd, but fopen should be able to deal with that. If /private/etc/passwd doesn't work I don't know what else to try.
yes i am trying to write to the file, so how do i set elevate privledges, i know that in some applications ive seen they ask for the admin password, would i have to have this prompt pop up?
This thread has been closed by the system or the community team.
You may vote for any posts you find helpful, or search the Community for additional answers.
IP mapping in OS X
Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.