1 /* $OpenBSD: netdb.c,v 1.3 2003/07/31 21:48:05 deraadt Exp $ */ 2 /* 3 * Copyright (c) 1993, 1994, 1995, 1996 by Chris Provenzano and contributors, 4 * proven@mit.edu All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Chris Provenzano, 17 * the University of California, Berkeley, and contributors. 18 * 4. Neither the name of Chris Provenzano, the University, nor the names of 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL CHRIS PROVENZANO, THE REGENTS OR 26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 /* 36 * Copyright (c) 1995 by Greg Hudson, ghudson@.mit.edu 37 * 38 * Test netdb calls. 39 */ 40 41 #include <pthread.h> 42 #include <string.h> 43 #include <stdio.h> 44 #include <netdb.h> 45 #include <errno.h> 46 #include <netinet/in.h> 47 #include <arpa/inet.h> 48 #include <unistd.h> 49 #include <stdlib.h> 50 #include "test.h" 51 52 static void 53 test_serv(void) 54 { 55 struct servent *serv; 56 57 CHECKhn(serv = getservbyname("telnet", "tcp")); 58 printf("getservbyname -> port %d\n", ntohs(serv->s_port)); 59 } 60 61 static void 62 test_host(void) 63 { 64 struct hostent *host; 65 struct in_addr addr; 66 67 CHECKhn(host = gethostbyname("localhost")); 68 memcpy(&addr, host->h_addr, sizeof(addr)); 69 printf("gethostbyname -> %s\n", inet_ntoa(addr)); 70 } 71 72 static void 73 test_localhost(void) 74 { 75 struct hostent *host; 76 77 CHECKhn(host = gethostbyname("127.0.0.1")); 78 } 79 80 int 81 main(int argc, char **argv) 82 { 83 test_serv(); 84 test_localhost(); 85 test_host(); 86 87 SUCCEED; 88 } 89