Commit a2479a04 authored by Eduardo L. Buratti's avatar Eduardo L. Buratti

collect: Remove discover-network.c

The functionality of this program will be moved to net/bandwidth.sh and
therefore this program is not needed anymore. Also removing
net/Makefile since it is needed exclusively by net/discover-network.c.
Signed-off-by: Eduardo L. Buratti's avatarEduardo L. Buratti <elb09@c3sl.ufpr.br>
parent eb598762
CC = gcc
CCFLAGS = -m32 -static -g -Wall
BIN = discover-network
all:
$(CC) $(CCFLAGS) -o $(BIN) discover-network.c
install: all
clean:
@find $(PWD) -type f \( -name '*~' -o -name '*.bak' -o -name 'core*' \) \
-exec rm -f {} \;
distclean: clean
@rm -f $(PWD)/$(BIN)
/* Copyright (C) 2004-2011 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This file is part of collect-agent
*
* collect-agent 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA. */
/* -------------------------------------------------------------------------- */
#include <stdio.h>
#include <stdlib.h>
/* Function: discover_network_and_save_to_file
* Function that finds and saves the local networks in the "networks".
* Parameters:
* decimal_array: array that contains the addresses and masks of local networks
* array_size: size of the array that contains the addresses and masks of local
* networks
* networkFile: file where the addresses, masks and interfaces of the local
* networks will be saved
* interfaceFile: file that contains the interfaces of local networks */
void discover_network_and_save_to_file(int *decimal_array, int array_size,
FILE *networkFile, FILE *interfaceFile)
{
int i, j, k, count, decimal_addr[4], decimal_mask[4];
char interface[10];
count = 0;
while (count < array_size)
{
/* Fill the array decimal_addr with content present in decimal_array */
for (i = count, j = 0; i < (count + 4); i++, j++)
{
decimal_addr[j] = decimal_array[i];
}
/* Fill the array decimal_mask with content present in decimal_array */
for (j = i, k = 0; j < (i + 4); j++, k++)
{
decimal_mask[k] = decimal_array[j];
}
/* Indicate the next position of the array that contains an address or
* end of the array */
count += 8;
/* Print the network in the networkFile.
* Do the "&"("and" bit by bit) between the address and mask to
* discover the network address */
for (i = 0; i < 3; i++)
{
fprintf(networkFile, "%d.", (decimal_addr[i] & decimal_mask[i]));
}
fprintf(networkFile, "%d/", (decimal_addr[3] & decimal_mask[3]));
/* Print the mask in the networkFile */
for (i = 0; i < 3; i++)
{
fprintf(networkFile, "%d.", decimal_mask[i]);
}
fprintf(networkFile, "%d\n", decimal_mask[3]);
/* Print the network interface discovered on file networkFile */
fgets(interface , 10, interfaceFile);
fprintf(networkFile, "%s", interface);
}
}
int main(int argc, char **argv)
{
int i, array_size;
int *decimal_array = (int *) malloc(1 * sizeof(int));
/* File that contains the addresses and masks of local networks */
FILE *addrMask;
addrMask = fopen("addr-mask", "r");
if (addrMask == NULL)
{
fputs("File error 1\n\n", stderr);
exit(1);
}
/* File to save the address of the discovered networks */
FILE *networkFile;
networkFile = fopen("networks", "w");
if (networkFile == NULL)
{
fputs("File error 2\n\n", stderr);
exit(2);
}
/* File that contains the interfaces of local networks */
FILE *interfaceFile;
interfaceFile = fopen("interfaces", "r");
if (interfaceFile == NULL)
{
fputs("File error 3\n\n", stderr);
exit(3);
}
/* Read the file with the addresses and masks and stores in the array of
* decimals */
i = 1;
while ((fscanf(addrMask, "%d", &decimal_array[i - 1])) != EOF)
{
i++;
decimal_array = realloc(decimal_array, i * sizeof(int));
}
array_size = i - 1;
discover_network_and_save_to_file(decimal_array, array_size, networkFile,
interfaceFile);
fclose(addrMask);
fclose(networkFile);
fclose(interfaceFile);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment