'Mount a CIFS client/connection with sys/mount

I am trying to make a CIFS connection between my Ubuntu client desktop and my Windows 10 server Desktop, so I can share folders and files though a local network. My code is the following:

#include <sys/mount.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <string>

using namespace std;

int main()
{
  string src = "//xxx.xxx.x.xxx/shared_folder"; //xxx.xxx.x.xxx should be replaced by the server IP. shared_folder is my folder shared on the server side
  string dst = "/opt/share";//My shared folder on Linux
  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 , "[email protected],password=mypassword") )
  {
      printf("mount failed with error: %s\n",strerror(errno));
  }
  else
      printf("mount success!\n");
  return 0;
}

But it always returns:

src: //xxx.xxx.x.xxx/shared_folder
mount failed with error: Operation not permitted
[1] + Done                       "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-fmryivr5.02p" 1>"/tmp/Microsoft-MIEngine-Out-zfdhv3x2.zc5"

Any clue, please?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source