Exemplo n.º 1
0
static int get_ports(uint32_t server, const struct nfs_mount_data *data)
{
	uint32_t nfs_ver, mount_ver;
	uint32_t proto;

	if (data->flags & NFS_MOUNT_VER3) {
		nfs_ver = NFS3_VERSION;
		mount_ver = NFS_MNT3_VERSION;
	} else {
		nfs_ver = NFS2_VERSION;
		mount_ver = NFS_MNT_VERSION;
	}

	proto = (data->flags & NFS_MOUNT_TCP) ? IPPROTO_TCP : IPPROTO_UDP;

	if (nfs_port == 0) {
		nfs_port = portmap(server, NFS_PROGRAM, nfs_ver, proto);
		if (nfs_port == 0) {
			if (proto == IPPROTO_TCP) {
				struct in_addr addr = { server };
				fprintf(stderr, "NFS over TCP not "
					"available from %s\n", inet_ntoa(addr));
				return -1;
			}
			nfs_port = NFS_PORT;
		}
	}

	if (mount_port == 0) {
		mount_port = portmap(server, NFS_MNT_PROGRAM, mount_ver, proto);
		if (mount_port == 0)
			mount_port = MOUNT_PORT;
	}
	return 0;
}
Exemplo n.º 2
0
void handlePortMap(const std::string& portMapFile)
{

    if (portMapFile.size() == 0)
        return;

    std::ifstream portmap(portMapFile);

    if (!portmap.is_open())
    {
        printf("failed to open port map file: %s : %s\n", portMapFile.c_str(), strerror(errno));
        exit(EXIT_FAILURE);
    }

    std::string line;

    while(getline(portmap, line))
    {
        if (line.size() > 0 && (line[0] == '#' || line[0] == ';'))
            continue;

        size_t pos = line.find(" ");

        if (pos == std::string::npos)
        {
            printf("not found ' ' in line %s\n", line.c_str());
            continue;
        }

        std::string fp_value = line.substr(0, pos);
        std::string lanes    = line.substr(pos + 1);

        // ::isspace : C-Style white space predicate. Locale independent.
        lanes.erase(std::remove_if(lanes.begin(), lanes.end(), ::isspace), lanes.end());

        std::istringstream iss(lanes);
        std::string lane_str;
        std::set<int> lane_set;

        while (getline(iss, lane_str, ','))
        {
            int lane = stoi(lane_str);
            lane_set.insert(lane);
        }

        gPortMap.insert(std::pair<std::set<int>,std::string>(lane_set,fp_value));
    }
}
Exemplo n.º 3
0
// FIXME: introduce common config format for SONiC
void handlePortMap(const std::string& portMapFile)
{
    if (portMapFile.size() == 0)
        return;

    std::ifstream portmap(portMapFile);

    if (!portmap.is_open())
    {
        std::cerr << "failed to open port map file:" << portMapFile.c_str() << " : "<< strerror(errno) << std::endl;
        exit(EXIT_FAILURE);
    }

    std::string line;

    while(getline(portmap, line))
    {
        if (line.size() > 0 && (line[0] == '#' || line[0] == ';'))
            continue;

        size_t pos = line.find(" ");

        if (pos == std::string::npos)
        {
            std::cerr << "port map parsing: not found ' ' in line" << line.c_str() << std::endl;
            continue;
        }
		 
        std::string fp_value = line.substr(0, pos);		
        std::string lanes    = line.substr(pos + 1);
        lanes.erase(lanes.begin(), std::find_if(lanes.begin(), lanes.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
        std::istringstream iss(lanes);
        std::string lane_str;
        std::set<int> lane_set;
		
        while (getline(iss, lane_str, ','))
        {
            int lane = stoi(lane_str);
            lane_set.insert(lane);
        }		 

        gPortMap.insert(std::pair<std::set<int>,std::string>(lane_set,fp_value));     
    }
}
Exemplo n.º 4
0
bool Reaction::file_creation()
{

    string entity_code = ENTITY_NAME;
    string port_code = PORT_DECLARATION;
    string equ_code = LOGICAL_EQUATION;


    string pattern_path = "pattern_files\\" + pattern_file_name;
    ifstream r_file(pattern_path.c_str(), ios::in);
    //file_name_user += ".vhd";
    string path = "generated_files\\" + file_name_user + ".vhd";

    ofstream w_file(path.c_str(), ios::out | ios::trunc);

    bool test = r_file;
    bool res = w_file;

    if(r_file && w_file)
    {
        string line;
        size_t found = string::npos;

        while(r_file)
        {
            getline(r_file, line);

            found = line.find(entity_code);
            if(found!=string::npos)
            {
                line.erase(found,entity_code.size());
                line.insert(found,entity_name_user);
            }

            found = line.find(port_code);
            if(found!=string::npos)
            {
                line.erase(found,port_code.size());
                line.insert(found,portmap());
            }


            found = line.find(equ_code);
            if(found!=string::npos)
            {
                line.erase(found,equ_code.size());



                line.insert(found,log_eq());
            }
            w_file << line << endl;
        }

        w_file.close();
        r_file.close();
    }
    else
    {
        cerr << "Impossible d'ouvrir le fichier !" << endl;
    }

    return res;

}