[tyndur-devel] [PATCH 2/3] libc: POSIX: getprotobyname()
Kevin Wolf ·
+ libc: POSIX: getprotobyname() Signed-off-by: Kevin Wolf <kevin at tyndur.org> --- src/modules/include/netdb.h | 14 ++++++++++++++ src/modules/lib/posix/net.c | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 0 deletions(-) diff --git a/src/modules/include/netdb.h b/src/modules/include/netdb.h index 12e6e9a..5fb2747 100644 --- a/src/modules/include/netdb.h +++ b/src/modules/include/netdb.h @@ -49,6 +49,12 @@ struct servent { }; +struct protoent { + char* p_name; + char** p_aliases; + int p_proto; +}; + struct hostent* gethostbyname(const char* name); /** @@ -61,5 +67,13 @@ struct hostent* gethostbyname(const char* name); */ struct servent* getservbyname(const char* name, const char* protocol); +/** + * Gibt Informationen zu einem Netzwerkprotokoll zurueck. Wenn das Protokoll + * nicht gefunden werden kann, wird NULL zurueckgegeben. + * + * @param name Name des Protokolls (z.B. "tcp") + */ +struct protoent* getprotobyname(const char* name); + #endif diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index 0b335a8..4832d29 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -155,3 +155,29 @@ struct servent* getservbyname(const char* name, const char* protocol) return NULL; } + +/* Definition der bekannten Netzwerkprotokolle */ +static char* proto_aliases_tcp[] = { "tcp", NULL }; + +static struct protoent protocols[] = { + { "tcp", proto_aliases_tcp, 6 }, + { NULL, NULL, 0 } +}; + +/** + * Gibt Informationen zu einem Netzwerkprotokoll zurueck. Wenn das Protokoll + * nicht gefunden werden kann, wird NULL zurueckgegeben. + * + * @param name Name des Protokolls (z.B. "tcp") + */ +struct protoent* getprotobyname(const char* name) +{ + int i; + for (i = 0; protocols[i].p_name != NULL; i++) { + if (!strcmp(name, protocols[i].p_name)) { + return &protocols[i]; + } + } + + return NULL; +} -- 1.6.0.2
Antworten
- [tyndur-devel] [PATCH 2/3] libc: POSIX: getprotobyname() · Antoine Kaufmann