1 /* Print information about the host
2 * Copyright (C) 2000 David Helder
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <glib.h>
24
25 #include <gnet.h>
26
27
28 int
main(int argc,char ** argv)29 main(int argc, char** argv)
30 {
31 GInetAddr* ia;
32 GInetAddr* autoia;
33 GList* interfaces;
34 GList* i;
35
36 gnet_init ();
37
38 /* Print info about me */
39 ia = gnet_inetaddr_get_host_addr();
40 if (ia != NULL)
41 {
42 gchar* cname;
43 gchar* name;
44
45 name = gnet_inetaddr_get_name(ia);
46 if (!name)
47 name = g_strdup ("<none>");
48 cname = gnet_inetaddr_get_canonical_name(ia);
49 g_assert (cname != NULL);
50
51 g_print ("Host name is %s (%s)\n", name, cname);
52 gnet_inetaddr_delete (ia);
53 g_free(name);
54 g_free(cname);
55 }
56 else
57 g_print ("Host name is <none> (<none>)\n");
58
59 /* Print interfaces */
60 g_print ("Interfaces:\n");
61
62 interfaces = gnet_inetaddr_list_interfaces();
63
64 for (i = interfaces; i != NULL; i = g_list_next(i))
65 {
66 gchar* name;
67 gchar* cname;
68
69 ia = (GInetAddr*) i->data;
70 g_assert (ia != NULL);
71
72 name = gnet_inetaddr_get_name(ia);
73 g_assert (name != NULL);
74
75 cname = gnet_inetaddr_get_canonical_name(ia);
76 g_assert (cname != NULL);
77
78 g_print ("%s (%s)\n", name, cname);
79 gnet_inetaddr_delete (ia);
80 g_free(name);
81 }
82
83 g_list_free(interfaces);
84
85 autoia = gnet_inetaddr_get_internet_interface();
86 g_print ("Internet inteface: ");
87 if (autoia)
88 {
89 gchar* cname;
90
91 cname = gnet_inetaddr_get_canonical_name (autoia);
92 g_print ("%s\n", cname);
93 g_free (cname);
94 }
95 else
96 g_print ("<none>\n");
97
98 autoia = gnet_inetaddr_autodetect_internet_interface();
99 g_print ("Auto-detected internet inteface: ");
100 if (autoia)
101 {
102 gchar* cname;
103
104 cname = gnet_inetaddr_get_canonical_name (autoia);
105 g_print ("%s\n", cname);
106 g_free (cname);
107 }
108 else
109 g_print ("<none>\n");
110
111 exit(EXIT_SUCCESS);
112 }
113