home *** CD-ROM | disk | FTP | other *** search
- RCS_ID_C="$Id: resolve.c,v 2.1 1994/02/21 21:44:32 ppessi Exp $";
- /*
- * resolve.c --- resolve the given IP address
- *
- * Author: ppessi <Pekka.Pessi@hut.fi>
- *
- * Copyright © 1994 AmiTCP/IP Group, <AmiTCP-group@hut.fi>
- * Helsinki University of Technology, Finland.
- *
- * Created : Tue Jan 11 22:33:06 1994 ppessi
- * Last modified: Mon Feb 21 21:44:13 1994 ppessi
- */
-
- #include "resolve_rev.h"
-
- static const char version[] = VERSTAG " "
- "Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>\n"
- "Helsinki University of Technology, Finland.\n";
-
- #include <proto/socket.h>
- #include <proto/dos.h>
-
- #include <clib/exec_protos.h>
- extern struct ExecBase* SysBase;
- #include <pragmas/exec_sysbase_pragmas.h>
-
- #include <dos/dos.h>
-
- #include <netdb.h>
-
- #include <string.h>
- #include <stdlib.h>
-
- #define SOCKETVERSION 2 /* minimum version to use */
- #define SOCKETNAME "bsdsocket.library"
-
- #ifndef MAXLINELENGTH
- #define MAXLINELENGTH 1024
- #endif
-
- LONG main(void)
- {
- LONG retval = 128;
- struct DosLibrary *DOSBase;
- struct ExecBase *SysBase;
- struct Library *SocketBase;
-
- SysBase = *(struct ExecBase**)4;
- DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37L);
- SocketBase = OpenLibrary(SOCKETNAME, SOCKETVERSION);
-
- if (DOSBase && SocketBase) {
- const char *template = "IPADDR";
- struct {
- STRPTR a_ipaddr;
- } args[1] = { 0 };
- struct RDArgs *rdargs = NULL;
-
- if (rdargs = ReadArgs((UBYTE *)template, (LONG *)args, NULL)) {
- long addr = inet_addr(args->a_ipaddr);
- struct hostent *hp =
- gethostbyaddr((caddr_t)&addr, sizeof(addr), AF_INET);
-
- if (hp) {
- char **alias = hp->h_aliases;
- Printf("HOST %s %s", args->a_ipaddr, hp->h_name);
- while (alias && *alias) {
- Printf(" %s", *alias++);
- }
- Printf("\n");
- }
- retval = RETURN_OK;
- FreeArgs(rdargs);
- }
- }
-
- if (SocketBase) {
- CloseLibrary(SocketBase);
- } else {
- if (DOSBase)
- Printf("resolve: cannot open %s\n", SOCKETNAME);
- }
-
- if (DOSBase)
- CloseLibrary((struct Library *)DOSBase);
-
- return retval;
- }
-