From babf7c77ac9344c8b12ca2ce87096e7ed079b687 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 18 Jan 2001 02:23:35 +0000 Subject: [PATCH] net_getservbyport() - Get name of TCP service git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1134 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/core/network.c | 9 +++++++++ src/core/network.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/core/network.c b/src/core/network.c index 3cf42013..96e77ee8 100644 --- a/src/core/network.c +++ b/src/core/network.c @@ -515,6 +515,15 @@ int net_hosterror_notfound(int error) #endif } +/* Get name of TCP service */ +char *net_getservbyport(int port) +{ + struct servent *entry; + + entry = getservbyport(htons((unsigned short) port), "tcp"); + return entry == NULL ? NULL : entry->s_name; +} + int is_ipv4_address(const char *host) { while (*host != '\0') { diff --git a/src/core/network.h b/src/core/network.h index 159bda3e..94f2596b 100644 --- a/src/core/network.h +++ b/src/core/network.h @@ -73,6 +73,9 @@ int net_host2ip(const char *host, IPADDR *ip); /* Get socket error */ int net_geterror(GIOChannel *handle); +/* Get name of TCP service */ +char *net_getservbyport(int port); + int is_ipv4_address(const char *host); int is_ipv6_address(const char *host);