home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / internet / amitcp3.0b / src.lha / src / util / resolve / resolve.c next >
Encoding:
C/C++ Source or Header  |  1996-09-08  |  2.0 KB  |  89 lines

  1. RCS_ID_C="$Id: resolve.c,v 2.1 1994/02/21 21:44:32 ppessi Exp $";
  2. /*
  3.  * resolve.c --- resolve the given IP address
  4.  *
  5.  * Author: ppessi <Pekka.Pessi@hut.fi>
  6.  *
  7.  * Copyright © 1994 AmiTCP/IP Group, <AmiTCP-group@hut.fi>
  8.  *                  Helsinki University of Technology, Finland.
  9.  *
  10.  * Created      : Tue Jan 11 22:33:06 1994 ppessi
  11.  * Last modified: Mon Feb 21 21:44:13 1994 ppessi
  12.  */
  13.  
  14. #include "resolve_rev.h"
  15.  
  16. static const char version[] = VERSTAG " "
  17. "Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>\n"
  18.   "Helsinki University of Technology, Finland.\n";
  19.  
  20. #include <proto/socket.h>
  21. #include <proto/dos.h>
  22.  
  23. #include <clib/exec_protos.h>
  24. extern struct ExecBase* SysBase;
  25. #include <pragmas/exec_sysbase_pragmas.h>
  26.  
  27. #include <dos/dos.h>
  28.  
  29. #include <netdb.h>
  30.  
  31. #include <string.h>
  32. #include <stdlib.h>
  33.  
  34. #define SOCKETVERSION 2    /* minimum version to use */
  35. #define SOCKETNAME "bsdsocket.library"
  36.  
  37. #ifndef MAXLINELENGTH 
  38. #define MAXLINELENGTH 1024
  39. #endif
  40.  
  41. LONG main(void)
  42. {
  43.   LONG retval = 128;
  44.   struct DosLibrary *DOSBase;
  45.   struct ExecBase *SysBase;
  46.   struct Library *SocketBase;
  47.  
  48.   SysBase = *(struct ExecBase**)4;
  49.   DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37L);
  50.   SocketBase = OpenLibrary(SOCKETNAME, SOCKETVERSION);
  51.   
  52.   if (DOSBase && SocketBase) {
  53.     const char *template = "IPADDR";
  54.     struct {
  55.       STRPTR a_ipaddr;
  56.     } args[1] = { 0 };
  57.     struct RDArgs *rdargs = NULL;
  58.  
  59.     if (rdargs = ReadArgs((UBYTE *)template, (LONG *)args, NULL)) {
  60.       long addr = inet_addr(args->a_ipaddr);
  61.       struct hostent *hp = 
  62.     gethostbyaddr((caddr_t)&addr, sizeof(addr), AF_INET);
  63.  
  64.       if (hp) {
  65.     char **alias = hp->h_aliases;
  66.     Printf("HOST %s %s", args->a_ipaddr, hp->h_name);
  67.     while (alias && *alias) {
  68.       Printf(" %s", *alias++);
  69.     }
  70.     Printf("\n");
  71.       }
  72.       retval = RETURN_OK;
  73.       FreeArgs(rdargs);
  74.     }
  75.   }
  76.  
  77.   if (SocketBase) {
  78.     CloseLibrary(SocketBase);
  79.   } else {
  80.     if (DOSBase)
  81.       Printf("resolve: cannot open %s\n", SOCKETNAME);
  82.   }
  83.  
  84.   if (DOSBase)
  85.     CloseLibrary((struct Library *)DOSBase);
  86.  
  87.   return retval;
  88. }
  89.