Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / network / common / C / resolve.c
blobd71cd30dc83f5421f5fefaf484fae01993a1470f
1 /* $Id$
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>
30 #include <dos/dos.h>
32 #include <netdb.h>
34 #include <string.h>
35 #include <stdlib.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
40 #define SOCKETVERSION 2 /* minimum version to use */
41 #define SOCKETNAME "bsdsocket.library"
43 #ifndef MAXLINELENGTH
44 #define MAXLINELENGTH 1024
45 #endif
47 int main(void)
49 int retval = 128;
50 struct DosLibrary *DOSBase;
51 struct Library *SocketBase;
53 #if ! (AROS_FLAVOUR & AROS_FLAVOUR_EMULATION)
54 struct ExecBase *SysBase;
55 SysBase = *(struct ExecBase**)4;
56 #endif
58 DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37L);
59 SocketBase = OpenLibrary(SOCKETNAME, SOCKETVERSION);
61 if (DOSBase && SocketBase) {
62 const char *template = "HOST/A";
63 struct {
64 STRPTR a_ipaddr;
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);
70 struct hostent *hp;
71 if (addr == INADDR_NONE)
72 hp = gethostbyname(args->a_ipaddr);
73 else
74 hp = gethostbyaddr((caddr_t)&addr, sizeof(addr), AF_INET);
75 if (hp) {
76 if (addr == -1) {
77 char **ip = hp->h_addr_list;
78 struct in_addr *inaddr;
79 Printf("ADDR %s", args->a_ipaddr);
80 while (ip && *ip) {
81 inaddr = (struct in_addr *)*ip++;
82 Printf(" %s", Inet_NtoA(inaddr->s_addr));
84 } else {
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++);
91 Printf("\n");
92 retval = RETURN_OK;
93 } else {
94 Printf("resolve: unknown host %s\n", args->a_ipaddr);
95 retval = 1;
97 FreeArgs(rdargs);
100 else {
101 Printf("usage: resolve host\n");
102 retval = 1;
106 if (SocketBase) {
107 CloseLibrary(SocketBase);
108 } else {
109 if (DOSBase)
110 Printf("resolve: cannot open bsdsocket.library version 2\n");
113 if (DOSBase)
114 CloseLibrary((struct Library *)DOSBase);
116 return retval;