1 /* Copyright (C) 2008 Red Hat, Inc.
2 * Written by Darryl L. Pierce <dpierce@redhat.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16 * MA 02110-1301, USA. A copy of the GNU General Public License is
17 * also available at http://www.gnu.org/copyleft/gpl.html.
20 #ifndef __OVIRT_IDENTIFY_NODE_H
21 #define __OVIRT_IDENTIFY_NODE_H
31 #include <arpa/inet.h>
33 #include <hal/libhal.h>
35 #include <libvirt/libvirt.h>
37 #include <linux/types.h>
38 #include <linux/ethtool.h>
39 #include <linux/sockios.h>
42 #include <netinet/in.h>
44 #include <sys/ioctl.h>
45 #include <sys/types.h>
46 #include <sys/socket.h>
48 #define BUFFER_LENGTH 128
49 #define CPU_FLAGS_BUFFER_LENGTH 256
51 typedef struct _cpu_info
{
52 char cpu_num
[BUFFER_LENGTH
];
53 char core_num
[BUFFER_LENGTH
];
54 char number_of_cores
[BUFFER_LENGTH
];
55 char vendor
[BUFFER_LENGTH
];
56 char model
[BUFFER_LENGTH
];
57 char family
[BUFFER_LENGTH
];
58 char cpuid_level
[BUFFER_LENGTH
];
59 char speed
[BUFFER_LENGTH
];
60 char cache
[BUFFER_LENGTH
];
61 char flags
[CPU_FLAGS_BUFFER_LENGTH
];
62 struct _cpu_info
* next
;
65 typedef t_cpu_info
* cpu_info_ptr
;
67 typedef struct _nic_info
{
68 char mac_address
[BUFFER_LENGTH
];
69 char bandwidth
[BUFFER_LENGTH
];
70 char ip_address
[BUFFER_LENGTH
];
71 char netmask
[BUFFER_LENGTH
];
72 char iface_name
[BUFFER_LENGTH
];
73 char broadcast
[BUFFER_LENGTH
];
74 struct _nic_info
* next
;
77 typedef t_nic_info
* nic_info_ptr
;
79 int config(int argc
,char** argv
);
82 void get_label_and_value(char* text
,
83 char* label
,size_t label_length
,
84 char* value
,size_t value_length
);
86 int send_text(char* text
);
87 int get_text(const char *const expected
);
90 ssize_t
saferead(int fd
, char *buf
, size_t count
);
91 ssize_t
safewrite(int fd
, const void *buf
, size_t count
);
94 void debug_cpu_info(void);
97 int init_gather(void);
99 int get_cpu_info(void);
100 int get_nic_info(void);
103 LibHalContext
* get_hal_ctx(void);
106 int create_connection(void);
107 int start_conversation(void);
108 int send_details(void);
109 int end_conversation(void);
110 int send_value(char* label
,char* value
);
111 int send_text(char* text
);
118 extern char arch
[BUFFER_LENGTH
];
119 extern char uuid
[BUFFER_LENGTH
];
120 extern char memsize
[BUFFER_LENGTH
];
121 extern char numcpus
[BUFFER_LENGTH
];
122 extern char cpuspeed
[BUFFER_LENGTH
];
123 extern char *hostname
;
126 extern cpu_info_ptr cpu_info
;
127 extern nic_info_ptr nic_info
;
129 extern DBusConnection
* dbus_connection
;
130 extern DBusError dbus_error
;
131 extern LibHalContext
* hal_ctx
;
134 #define DEBUG(arg...) if(debug) fprintf(stderr, ##arg)
135 #define VERBOSE(arg...) if(verbose) fprintf(stdout, ##arg)
136 #define COPY_VALUE_TO_BUFFER(value,buffer,length) \
137 snprintf(buffer,length,"%s",value)