/* test-getservbyname.c * * This basically tests the implementation of getservbyname to check * the ports being returned as it appeared that beos had a bug in it's * implementation. After testing it seems at though BeOS is correctly * returning the port network byte order. * * gcc -Wall -g -O0 -o test-getservbyname test-getservbyname.c -lbind * * Test using * * ./test-getservbyname * * The protocol is optional and will default to tcp if not specified. * * This test illustrated the problem that we face. On OpenBSD 3.2 running * this code gives * * $ ./test-getservbyname ftp * trying to get details for service ftp running over tcp...OK * hex dec * Port (as returned) : 0015 21 * Port (ntohs) : 0015 21 * * On FreeBSD 4.9 we see * * $ ./test-getservbyname ftp * trying to get details for service ftp running over tcp...OK * hex dec * Port (as returned) : 1500 5376 * Port (ntohs) : 0015 21 * * On BeOS BONE (7a) we get this * * $ ./test-getservbyname ftp * trying to get details for service ftp running over tcp...OK * hex dec * Port (as returned) : 1500 5376 * Port (ntohs) : 0015 21 */ #include #include void usage(void) { printf("usage: test-getservbyname [: TCP]\n"); exit (-1); } int main(int argc, char *argv[]) { struct servent *sp = NULL; if (argc < 2) usage(); if (argc == 3) { printf("trying to get details for service %s running over %s...", argv[1], argv[2]); sp = getservbyname(argv[1], argv[2]); } else { printf("trying to get details for service %s running over tcp...", argv[1]); sp = getservbyname(argv[1], "tcp"); } if (sp) { printf("OK\n"); printf(" hex dec\n"); printf(" Port (as returned) : %04x %6d\n", sp->s_port, sp->s_port); printf(" Port (ntohs) : %04x %6d\n", ntohs(sp->s_port), ntohs(sp->s_port)); } else printf("failed\n"); return 0; }