English 中文(简体)
我如何从安装的可可/可可目录中获取服务器的主名?
原标题:How do I get the server hostname from a mounted directory with cocoa/obj-c?

目前,当我向我的方案开放档案时,我可以选择服务器上的档案,点击NSOpenPanel旁边的服务器名称,然后选择文件。 没有任何问题,只要共用目录到位,就可使用档案。 我走了“/Volumes/SHARENAME/filename.bla”等道路。

我的问题是,我如何获得服务器的计算机主机名称。 例如,如果我用NSOpenPanel的“共有”名称“SERVERNAME”点击该装置,我如何从“/Volumes/SHARENAME/filename.bla”中获取SERVERNAME。

我已经看过一些文件,无法找到解决这一问题的办法。

对这一努力的任何帮助将受到高度赞赏。 谢谢。

最佳回答

这并不是一种客观的C方法,而是有时使用<代码>popen(>)使你能够从不准确的指挥中获取信息。

#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
", host);
      }
    }
    pclose(fp);
  }
  return 0;
}
问题回答

暂无回答




相关问题
Code snippet paths in GCC

Background: Keil C51 on a PC, currently moving to GCC (CrossPack-AVR) on an iMac. Since I write firmware for micro s I have a lot of driver source files etc. that I need to include with my programs,...

C#/.NET app doesn t recognize Environment Var Change (PATH)

In my C# app, I am programmatically installing an Oracle client if one is not present, which requires adding a dir to the PATH system environment variable. This all works fine, but it doesn t take ...

PHP absolute path to file URI

In order to refer to a local DTD when using PHP SimpleXML, I need to convert the absolute path into a file type URI. For example, convert /home/sitename/www/xml/example.dtd to file:///home/sitename/...

Check if files with absolute and relative path exists

Is there a way to check whether files (with either an absolute or relative path) exists? Im using PHP. I found a couple of method but either they only accept absolute or relative but not both. Thanks.

How to get file path of the file with the running-vba code

I want to get the folder path from the file who is running the vba-code. For example: the vba-code is in the file C:myfolderfile.accdb and I want the vba-code to return C:myfolder Is that ...

热门标签