~henrix/ubuntu/precise/open-vm-dkms/lp-1416003

« back to all changes in this revision

Viewing changes to lib/guestInfo/guestInfoPosix.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-10-23 15:32:00 UTC
  • mfrom: (1.1.2 upstream) (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20081023153200-gc1bfx89hj35c799
Tags: 2008.10.10-123053-2
* Correcting typo in dh_installinit call.
* Downgrading depends on module-assistant to recommends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
171
171
/*
172
172
 *-----------------------------------------------------------------------------
173
173
 *
 
174
 * RecordNetworkAddress --
 
175
 *
 
176
 *      Massages a dnet(3)-style interface address (IPv4 or IPv6) and stores it
 
177
 *      as part of a GuestNic structure.
 
178
 *
 
179
 * Results:
 
180
 *      If addr is IPv4 or IPv6, it will be appended to the GuestNic's list of
 
181
 *      IP addresses.
 
182
 *
 
183
 * Side effects:
 
184
 *      None.
 
185
 *
 
186
 *-----------------------------------------------------------------------------
 
187
 */
 
188
 
 
189
static void
 
190
RecordNetworkAddress(GuestNic *nic,             // IN: operand NIC
 
191
                     const struct addr *addr)   // IN: dnet(3) address to process
 
192
{
 
193
   char ipAddress[NICINFO_MAX_IP_LEN];
 
194
   VmIpAddress *ip = NULL;
 
195
 
 
196
   switch (addr->addr_type) {
 
197
   case ADDR_TYPE_IP:
 
198
      /*
 
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.
 
202
       */
 
203
      ip_ntop(&addr->addr_ip, ipAddress, sizeof ipAddress);
 
204
      ip = GuestInfoAddIpAddress(nic, ipAddress, INFO_IP_ADDRESS_FAMILY_IPV4);
 
205
      if (ip) {
 
206
         GuestInfoAddSubnetMask(ip, addr->addr_bits, TRUE);
 
207
      }
 
208
      break;
 
209
   case ADDR_TYPE_IP6:
 
210
      memcpy(ipAddress, addr_ntoa(addr), sizeof ipAddress);
 
211
      GuestInfoAddIpAddress(nic, ipAddress, INFO_IP_ADDRESS_FAMILY_IPV6);
 
212
      break;
 
213
   default:
 
214
      Debug("%s: Unknown address type: %hu\n", __func__, addr->addr_type);
 
215
      break;
 
216
   }
 
217
}
 
218
 
 
219
 
 
220
/*
 
221
 *-----------------------------------------------------------------------------
 
222
 *
174
223
 * ReadInterfaceDetails --
175
224
 *
176
225
 *      Callback function called by libdnet when iterating over all the
197
246
   if ((entry->intf_type & INTF_TYPE_ETH) == INTF_TYPE_ETH) {
198
247
      GuestNic *nic;
199
248
      char macAddress[NICINFO_MAC_LEN];
200
 
      char ipAddress[NICINFO_MAX_IP_LEN];
201
249
 
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);
205
253
 
207
255
         return -1;
208
256
      }
209
257
 
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,
215
 
                                    ipAddress,
216
 
                                    INFO_IP_ADDRESS_FAMILY_IPV4);
217
 
         if (ip) {
218
 
            GuestInfoAddSubnetMask(ip, entry->intf_addr.addr_bits);
219
 
         }
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,
224
 
                       ipAddress,
225
 
                       sizeof ipAddress);
226
 
               ip = GuestInfoAddIpAddress(nic,
227
 
                                          ipAddress,
228
 
                                          INFO_IP_ADDRESS_FAMILY_IPV4);
229
 
               if (ip) {
230
 
                  GuestInfoAddSubnetMask(ip, entry->intf_addr.addr_bits);
231
 
               }
232
 
            } else if (entry->intf_alias_addrs[i].addr_type == ADDR_TYPE_IP6) {
233
 
               memcpy(ipAddress,
234
 
                      addr_ntoa(&entry->intf_alias_addrs[i]),
235
 
                      sizeof ipAddress);
236
 
               GuestInfoAddIpAddress(nic,
237
 
                                     ipAddress,
238
 
                                     INFO_IP_ADDRESS_FAMILY_IPV6);
239
 
            }
 
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);
 
262
      }
 
263
 
 
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);
240
270
         }
241
271
      }
242
272
   }
245
275
}
246
276
#endif
247
277
 
 
278
 
248
279
/*
249
280
 *-----------------------------------------------------------------------------
250
281
 *