Search code examples
csocketsipin-addr

Hold lists of IPs and Host Names


I'm writing a proxy server, and I have a filter file that contains sub-networks (n1.n2.n3.n4/x) and host names. Each IP address that it first x MSB are identical to one from the list should be ignored, so as the host names.

My initial thought was to read the file and hold two lists;

The first

struct Subnet{
    char* IP
    int mask
    Subnet* next
};

The second

struct Host_name{
    char* host
    Host_name* next
};

But I think that using some existing structs (such as in addr) will be better.

I would appreciate any advice on the subject


Solution

  • You should choose the format that is most convenient for your program.

    Because you are going to compare bits and bytes, a binary format (such as struct in_addr) is more convenient for your program.

    If you store it as text (char*) you have to convert it to a binary format every time you access the list.

    It is better to convert the data when reading the configuration file, so that the program only needs to convert the data once.