3 * resolve.c --- resolve the given IP address or hostname
5 * Author: ppessi <Pekka.Pessi@hut.fi>
6 * Pavel Fedin <sonic_amiga@rambler.ru>
8 * Copyright © 1994 AmiTCP/IP Group, <AmiTCP-group@hut.fi>
9 * Helsinki University of Technology, Finland.
10 8 Copyright © 2005 Pavel Fedin
12 * Created : Tue Jan 11 22:33:06 1994 ppessi
13 * Last modified: Mon Oct 17 12:25:13 2005 sonic
16 static const char version
[] __attribute__((used
)) = "$VER: resolve 4.0 (17.10.2005)\n"
17 "Copyright © 1994 AmiTCP/IP Group, <amitcp-group@hut.fi>\n"
18 "Helsinki University of Technology, Finland.\n"
19 "Copyright © 2005 Pavel Fedin <sonic_amiga@rambler.ru";
21 #define USE_INLINE_STDARG
23 #include <aros/config.h>
25 #include <proto/socket.h>
26 #include <proto/dos.h>
28 #include <proto/exec.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
40 #define SOCKETVERSION 2 /* minimum version to use */
41 #define SOCKETNAME "bsdsocket.library"
44 #define MAXLINELENGTH 1024
50 struct DosLibrary
*DOSBase
;
51 struct Library
*SocketBase
;
53 #if ! (AROS_FLAVOUR & AROS_FLAVOUR_EMULATION)
54 struct ExecBase
*SysBase
;
55 SysBase
= *(struct ExecBase
**)4;
58 DOSBase
= (struct DosLibrary
*)OpenLibrary("dos.library", 37L);
59 SocketBase
= OpenLibrary(SOCKETNAME
, SOCKETVERSION
);
61 if (DOSBase
&& SocketBase
) {
62 const char *template = "HOST/A";
65 } args
[1] = { { 0 } };
66 struct RDArgs
*rdargs
= NULL
;
68 if (rdargs
= ReadArgs((UBYTE
*)template, (IPTR
*)args
, NULL
)) {
69 long addr
= inet_addr(args
->a_ipaddr
);
71 if (addr
== INADDR_NONE
)
72 hp
= gethostbyname(args
->a_ipaddr
);
74 hp
= gethostbyaddr((caddr_t
)&addr
, sizeof(addr
), AF_INET
);
77 char **ip
= hp
->h_addr_list
;
78 struct in_addr
*inaddr
;
79 Printf("ADDR %s", args
->a_ipaddr
);
81 inaddr
= (struct in_addr
*)*ip
++;
82 Printf(" %s", Inet_NtoA(inaddr
->s_addr
));
85 char **alias
= hp
->h_aliases
;
86 Printf("HOST %s %s", args
->a_ipaddr
, hp
->h_name
);
87 while (alias
&& *alias
) {
88 Printf(" %s", *alias
++);
94 Printf("resolve: unknown host %s\n", args
->a_ipaddr
);
101 Printf("usage: resolve host\n");
107 CloseLibrary(SocketBase
);
110 Printf("resolve: cannot open bsdsocket.library version 2\n");
114 CloseLibrary((struct Library
*)DOSBase
);