title: Mount a network drive in linux using c++
body: <p>I want to mount a network drive on linux using c++. Using the command line of "mount" , I am able to mount any drive I want. But using C++, Only those drives are mounted successfully which are shared by the user.</p>
  
  <p>This is my test code:</p>
  
  <pre><code>#include &lt;sys/mount.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main()
  {
    string src = "//192.168.4.11/c$/Users";
    string dst = "/home/krahul/Desktop/test_mount";
    string fstype = "cifs";
  
    printf("src: %s\n", src.c_str());
  
    if( -1 == mount(src.c_str(), dst.c_str(), fstype.c_str(), MS_MGC_VAL | MS_SILENT , "username=uname,password=pswd") )
    {
        printf("mount failed with error: %s\n",strerror(errno));
    }
    else
        printf("mount success!\n");
  
    if( umount2(dst.c_str(), MNT_FORCE) &lt; 0 )
    {
        printf("unmount failed with error: %s\n",strerror(errno));
    }
    else
        printf("unmount success!\n");
  
  
    return 0;
  }
  </code></pre>
  
  <p>I want to mount the "C:/Users" drive of the machine. Using the Command line, It works but not by this code. I don't know why. The error printed by strerror() is "No such device or address". I am using Centos and Samba is configured for this machine. Where am I going wrong?</p>