aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/tests/posix/getservbyname.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mlibc/tests/posix/getservbyname.c')
-rw-r--r--lib/mlibc/tests/posix/getservbyname.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/mlibc/tests/posix/getservbyname.c b/lib/mlibc/tests/posix/getservbyname.c
new file mode 100644
index 0000000..8c51710
--- /dev/null
+++ b/lib/mlibc/tests/posix/getservbyname.c
@@ -0,0 +1,27 @@
+#include <assert.h>
+#include <netdb.h>
+#include <string.h>
+#include <arpa/inet.h>
+
+int main() {
+ struct servent *ret = getservbyname("http", "tcp");
+ assert(ret);
+ assert(!strcmp("http", ret->s_name));
+ assert(ret->s_port == htons(80));
+ assert(!strcmp("tcp", ret->s_proto));
+
+ ret = getservbyname("http", NULL);
+ assert(ret);
+ assert(!strcmp("http", ret->s_name));
+ assert(ret->s_port == htons(80));
+ assert(!strcmp("tcp", ret->s_proto));
+
+ ret = getservbyname("babel", "udp");
+ assert(ret);
+ ret = getservbyname("babel", "tcp");
+ assert(!ret);
+
+ ret = getservbyname("", NULL);
+ assert(!ret);
+ return 0;
+}