#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "service.h"

Services::Services(char *fn)
{
    FILE *fp;
    char buf[32]; 
    int port;

    fp = fopen(fn, "r");
    while (!feof(fp)) {
       fscanf(fp, "%s %d", buf, &port);
       serv[port] = (char *) malloc(32);
       strncpy(serv[port], buf, 32);
    } 
    fclose(fp);
}

char *Services::GetName(int port)
{
    if (serv[port])
        return serv[port];
    else
        return (char *) "Unknown";
}

Services::~Services()
{
    int i;
    
    for(i=0;i<1025;i++)
       if (!serv[i])  free(serv[i]);
}

