Using the protocolentry class


Introduction

The protocolentry class provides methods for retrieving network protocol definitions. These are usually defined in a file like /etc/protocols on unix-like systems or C:\Windows\System32\drivers\etc\protocol on Windows, or are served from another source via the name-service switch.

Protocols can be looked up by name or number.


Lookup By Name

This example retrieves network protocol information for the "tcp" protocol.

#include <rudiments/protocolentry.h>
#include <rudiments/stdio.h>

int main(int argc, const char **argv) {

        // get the protocol entry for the "tcp" protocol
        protocolentry   pe;
        pe.initialize("tcp");

        // print out details
        stdoutput.printf("      Name:           %s\n",pe.getName());
        stdoutput.printf("      Alias list:\n");
        for (uint32_t i=0; pe.getAliasList() && pe.getAliasList()[i]; i++) {
                stdoutput.printf("              %s\n",pe.getAliasList()[i]);
        }
        stdoutput.printf("      Number:         %d\n",pe.getNumber());
        stdoutput.printf("\n");
}

Lookup By Number

This example retrieves network protocol information for "protocol number 6".

#include <rudiments/protocolentry.h>
#include <rudiments/stdio.h>

int main(int argc, const char **argv) {

        // get the protocol entry for "protocol number 6"
        protocolentry   pe;
        pe.initialize(6);

        // print out details
        stdoutput.printf("      Name:           %s\n",pe.getName());
        stdoutput.printf("      Alias list:\n");
        for (uint32_t i=0; pe.getAliasList() && pe.getAliasList()[i]; i++) {
                stdoutput.printf("              %s\n",pe.getAliasList()[i]);
        }
        stdoutput.printf("      Number:         %d\n",pe.getNumber());
        stdoutput.printf("\n");
}