172
172
*-----------------------------------------------------------------------------
174
* RecordNetworkAddress --
176
* Massages a dnet(3)-style interface address (IPv4 or IPv6) and stores it
177
* as part of a GuestNic structure.
180
* If addr is IPv4 or IPv6, it will be appended to the GuestNic's list of
186
*-----------------------------------------------------------------------------
190
RecordNetworkAddress(GuestNic *nic, // IN: operand NIC
191
const struct addr *addr) // IN: dnet(3) address to process
193
char ipAddress[NICINFO_MAX_IP_LEN];
194
VmIpAddress *ip = NULL;
196
switch (addr->addr_type) {
199
* GuestNicInfo clients expect IPv4 addresses and netmasks to be stored
200
* as strings in separate fields. As such, we'll use ip_ntop instead of
201
* addr_ntop to get a string without the netmask bits.
203
ip_ntop(&addr->addr_ip, ipAddress, sizeof ipAddress);
204
ip = GuestInfoAddIpAddress(nic, ipAddress, INFO_IP_ADDRESS_FAMILY_IPV4);
206
GuestInfoAddSubnetMask(ip, addr->addr_bits, TRUE);
210
memcpy(ipAddress, addr_ntoa(addr), sizeof ipAddress);
211
GuestInfoAddIpAddress(nic, ipAddress, INFO_IP_ADDRESS_FAMILY_IPV6);
214
Debug("%s: Unknown address type: %hu\n", __func__, addr->addr_type);
221
*-----------------------------------------------------------------------------
174
223
* ReadInterfaceDetails --
176
225
* Callback function called by libdnet when iterating over all the
197
246
if ((entry->intf_type & INTF_TYPE_ETH) == INTF_TYPE_ETH) {
199
248
char macAddress[NICINFO_MAC_LEN];
200
char ipAddress[NICINFO_MAX_IP_LEN];
202
Str_Sprintf(macAddress, sizeof macAddress,
250
Str_Sprintf(macAddress, sizeof macAddress, "%s",
203
251
addr_ntoa(&entry->intf_link_addr));
204
252
nic = GuestInfoAddNicEntry(nicInfo, macAddress);
210
if (entry->intf_addr.addr_type == ADDR_TYPE_IP) {
211
VmIpAddress *ip = NULL;
212
/* Use ip_ntop instead of addr_ntop since we don't want the netmask bits. */
213
ip_ntop(&entry->intf_addr.addr_ip, ipAddress, sizeof ipAddress);
214
ip = GuestInfoAddIpAddress(nic,
216
INFO_IP_ADDRESS_FAMILY_IPV4);
218
GuestInfoAddSubnetMask(ip, entry->intf_addr.addr_bits);
220
/* Walk the list of alias's and add those that are IPV4 or IPV6 */
221
for (i = 0; i < entry->intf_alias_num; i++) {
222
if (entry->intf_alias_addrs[i].addr_type == ADDR_TYPE_IP) {
223
ip_ntop(&entry->intf_alias_addrs[i].addr_ip,
226
ip = GuestInfoAddIpAddress(nic,
228
INFO_IP_ADDRESS_FAMILY_IPV4);
230
GuestInfoAddSubnetMask(ip, entry->intf_addr.addr_bits);
232
} else if (entry->intf_alias_addrs[i].addr_type == ADDR_TYPE_IP6) {
234
addr_ntoa(&entry->intf_alias_addrs[i]),
236
GuestInfoAddIpAddress(nic,
238
INFO_IP_ADDRESS_FAMILY_IPV6);
258
/* Record the "primary" address. */
259
if (entry->intf_addr.addr_type == ADDR_TYPE_IP ||
260
entry->intf_addr.addr_type == ADDR_TYPE_IP6) {
261
RecordNetworkAddress(nic, &entry->intf_addr);
264
/* Walk the list of alias's and add those that are IPV4 or IPV6 */
265
for (i = 0; i < entry->intf_alias_num; i++) {
266
const struct addr *alias = &entry->intf_alias_addrs[i];
267
if (alias->addr_type == ADDR_TYPE_IP ||
268
alias->addr_type == ADDR_TYPE_IP6) {
269
RecordNetworkAddress(nic, alias);