return ERROR_FAIL;
}
+_hidden int libxl__parse_mac(const char *s, libxl_mac mac)
+{
+ const char *tok;
+ char *endptr;
+ int i;
+
+ for (i = 0, tok = s; *tok && (i < 6); ++i, tok += 3) {
+ mac[i] = strtol(tok, &endptr, 16);
+ if (endptr != (tok + 2) || (*endptr != '\0' && *endptr != ':') )
+ return ERROR_INVAL;
+ }
+ if ( i != 6 )
+ return ERROR_INVAL;
+
+ return 0;
+}
+
int libxl__fd_set_cloexec(int fd)
{
int flags = 0;
const char *mac, libxl_device_nic *nic)
{
libxl_nicinfo *nics;
- unsigned int nb, i;
+ unsigned int nb, rc, i;
int found;
- uint8_t mac_n[6];
+ libxl_mac mac_n;
uint8_t *a, *b;
- const char *tok;
- char *endptr;
+
+ rc = libxl__parse_mac(mac, mac_n);
+ if (rc)
+ return rc;
nics = libxl_list_nics(ctx, domid, &nb);
if (!nics)
return ERROR_FAIL;
- for (i = 0, tok = mac; *tok && (i < 6); ++i, tok += 3) {
- mac_n[i] = strtol(tok, &endptr, 16);
- if (endptr != (tok + 2))
- return ERROR_INVAL;
- }
memset(nic, 0, sizeof (libxl_device_nic));
found = 0;
for (i = 0; i < nb; ++i) {
const char *devid, libxl_device_nic *nic)
{
libxl__gc gc = LIBXL_INIT_GC(ctx);
- char *tok, *val;
+ char *val;
char *dompath, *nic_path_fe, *nic_path_be;
- unsigned int i;
int rc = ERROR_FAIL;
memset(nic, 0, sizeof (libxl_device_nic));
nic->devid = strtoul(devid, NULL, 10);
val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/mac", nic_path_fe));
- for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
- ++i, tok = strtok(NULL, ":")) {
- nic->mac[i] = strtoul(tok, NULL, 16);
- }
+ rc = libxl__parse_mac(val, nic->mac);
+ if (rc)
+ goto out;
+
nic->script = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/script", nic_path_be), NULL);
rc = 0;
out: