Debian Codegraph @

tests/probes/system_info/test_probes_system_info.c

raw symbols SCIP
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4
5 #include <stdio.h>
6 #include "oval_agent_api.h"
7 #include "oval_system_characteristics.h"
8 #include "oval_definitions_impl.h"
9 #include "oval_probe.h"
10 #include "oscap_assert.h"
11
12 int main(void)
13 {
14 struct oval_sysinfo *info;
15
16 /*
17 * Create empty models
18 */
19 struct oval_definition_model *def_model = oval_definition_model_new();
20 oscap_assert(def_model != NULL);
21
22 struct oval_syschar_model *sys_model = oval_syschar_model_new(def_model);
23 oscap_assert(sys_model != NULL);
24
25 /*
26 * Create probe session
27 */
28 oval_probe_session_t *sess = oval_probe_session_new(sys_model);
29 oscap_assert(sess != NULL);
30
31 /*
32 * Call the sysinfo probe.
33 */
34 oscap_assert(oval_probe_query_sysinfo(sess, &info) == 0);
35 oscap_assert(info != NULL);
36
37 if (info != NULL) {
38 char *a, *b, *c, *d;
39
40 printf(" os_name: %s\n"
41 " os_version: %s\n"
42 " os_architecture: %s\n"
43 "primary_host_name: %s\n",
44
45 a = oval_sysinfo_get_os_name(info),
46 b = oval_sysinfo_get_os_version(info),
47 c = oval_sysinfo_get_os_architecture(info),
48 d = oval_sysinfo_get_primary_host_name(info));
49
50 oscap_assert(a != NULL);
51 oscap_assert(b != NULL);
52 oscap_assert(c != NULL);
53 oscap_assert(d != NULL);
54
55 struct oval_sysint_iterator *ifit = oval_sysinfo_get_interfaces(info);
56
57 if (ifit != NULL) {
58 printf("Interfaces:\n");
59
60 while (oval_sysint_iterator_has_more(ifit)) {
61 struct oval_sysint *ife = oval_sysint_iterator_next(ifit);
62 oscap_assert(ife != NULL);
63
64 printf("%s %s %s\n",
65 oval_sysint_get_name(ife),
66 oval_sysint_get_ip_address(ife),
67 oval_sysint_get_mac_address(ife));
68
69 /* oval_sysint_free (ife); */
70 }
71
72 oval_sysint_iterator_free(ifit);
73 }
74
75 oval_sysinfo_free(info);
76 oval_probe_session_destroy(sess);
77
78 return(0);
79 }
80
81 /*
82 * Free the probe context. This also terminates
83 * all running probes executed under this context.
84 */
85 oval_probe_session_destroy(sess);
86
87 return(1);
88 }