资源简介
ad hoc网络olsr路由在linux下的实现源代码
代码片段和文件信息
/*
* NetsimPcap - a userspace network bridge with simulated packet loss
* Copyright 2008 H. Rogge (rogge@fgan.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not see .
*/
#include
#include
#include
#include “config.h“
#include “debug.h“
/*
* stripString
*
* this function strips leading and trailing whitespaces from a string
*
* @param string to strip
* @return stripped string
*/
char *
stripString(char *str)
{
/* strip left whitespaces */
while (*str == ‘ ‘ || *str == ‘\t‘) {
str++;
}
/* strip right whitespaces */
int i = strlen(str);
while (--i >= 0) {
if (str[i] == ‘ ‘ || str[i] == ‘\r‘ || str[i] == ‘\n‘ || str[i] == ‘\t‘) {
str[i] = 0;
break;
}
}
return str;
}
/*
* readConnectionMatrix
*
* This function reads the network settings and place them in the
* connection matrix (float array with size “len“ x “len“.
*
* @param pointer to begin of connection matrix
* @param pointer to filename
* @param number of elements in each connection matrix line
* @return 0 if function was successfull 1 if an error happened
*/
int
readConnectionMatrix(float *connectionMatrix char *filename int len)
{
FILE *file = fopen(filename “r“);
if (!file) {
return 1;
}
char buffer[1024];
while (fgets(buffer 1024 file)) {
int from to;
float propability;
char *line = stripString(buffer);
DPRINT(“%s\n“ line);
if (line[0] == ‘#‘ || line[0] == 0) {
continue;
}
if (sscanf(line “%d %d %f“ &from &to &propability) != 3) {
continue;
}
if (from < 0 || from >= len || to < 0 || to >= len || from == to) {
continue;
}
connectionMatrix[GRID(from to len)] = propability;
if (connectionMatrix[GRID(to from len)] == 0) {
connectionMatrix[GRID(to from len)] = propability;
}
}
fclose(file);
return 0;
}
/*
* Local Variables:
* c-basic-offset: 2
* indent-tabs-mode: nil
* End:
*/
- 上一篇:Photon_english.dll
- 下一篇:VHDL语言实现简易多功能信号发生器
评论
共有 条评论