views:

35

answers:

1

Currently when I open a file with my program I can select files on a server by clicking on the server name in the sidebar in an NSOpenPanel and then selecting the file. No problem, this works fine for using the file as long as the shared directory is mounted. I get a path like "/Volumes/SHARENAME/filename.bla".

My question is how do I get the server hostname of the computer it came from. For instance, if I clicked on the device with name SERVERNAME under "Shared" in the NSOpenPanel how do I get SERVERNAME from "/Volumes/SHARENAME/filename.bla".

I have looked at quite a bit of documentation and have been unable to find a solution for this problem.

Any help toward this will be greatly appreciated. Thank you.

A: 

This is not an Objective-C way of doing this but sometimes using popen(..) can get let you grab information you can parse from a unix command.

Example

#include <stdio.h>
#include <string.h>

int main() {
  FILE *fp = popen("df", "r"); // see man page for df
  if (fp) {
    char line[4096];
    while (line == fgets(line, 4096, fp)) {
      if (strstr(line, "/Volumes/SHARENAME")) { // You need the mount point
        char host[256];
        sscanf(line, "%s", host);
        printf("Connected: %s\n", host);
      }
    }
    pclose(fp);
  }
  return 0;
}
epatel
Thank you for the quick response. I am not savvy enough with C to have figured this out, but it will definitely do the job.
Andrew