Tuesday, July 14, 2009

Using C and fopen in mac os x when refering to the /etc/hosts file?

I am trying to write an application for Mac OS X that will modify the /etc/hosts file. It is responsible for mapping IP addresses to domain names. When I use the fopen command with the directory as /etc/hosts, nothing happens. Yet when I made this application for windows, I could point directly to the file, c:/WINDOWS/system32/drivers/etc/hosts, it works fine. Do I need to use a different command, other than fopen, or do I need to be more specific in directing the application to the file. Do hard drives have letter names in OS X like they do in windows?



Using C and fopen in mac os x when refering to the /etc/hosts file?





Did you check the permission of the file? Usually, files in /etc directories are restricted for Write for root user only.



In OS X or in any UNIX operating systems, drives (hardware) has a name in /dev directory. But they are accessed by mounting it to a place somewhere at or under root, then cd into it.



Using C and fopen in mac os x when refering to the /etc/hosts file?



Opening files in OS X is eactly the same as in UNIX or Linux. And unless you machine is different, the default permission on /etc/hosts in OS X is 644 so specifying the path %26quot;/etc/hosts%26quot; should work.



Though the mode when you open the file should be read only %26quot;r%26quot;. There are other UNIX specific file reading functions.

No comments:

Post a Comment