The attached patch modifies the parser function for the mac addresses (ie. -net 
nic,macaddr=XXXXXX) in the following ways:

- the accepted separators now include "-", because on Windows it is common to 
write a MAC addresses separated by dashes (ie. 54-32-00-12-34-56)
- it supports specifying the lower part of the MAC address (ie. the last three 
bytes) as an integer number (so that you can say -net nic,macaddr=0x1234, which 
would result in the mac address of 54-32-00-00-12-34). This simplifies the 
situations where you want to connect together multiple Qemu virtual machines 
and you want an easy way to ensure that they network cards don't have colliding 
MAC addresses (simpler than having to retype the whole address)

Any comments are welcome.




      __________________________________________________________
Sent from Yahoo! - the World's favourite mail http://uk.mail.yahoo.com
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.376
diff -u -r1.376 vl.c
--- vl.c	4 Dec 2007 00:10:34 -0000	1.376
+++ vl.c	4 Dec 2007 22:58:58 -0000
@@ -3452,18 +3452,32 @@
 static int parse_macaddr(uint8_t *macaddr, const char *p)
 {
     int i;
-    for(i = 0; i < 6; i++) {
-        macaddr[i] = strtol(p, (char **)&p, 16);
-        if (i == 5) {
-            if (*p != '\0')
-                return -1;
-        } else {
-            if (*p != ':')
-                return -1;
-            p++;
-        }
+    char *last_char;
+    long int offset;
+    
+    errno = 0;
+    offset = strtol(p, &last_char, 0);    
+    if ((0 == errno) && ('\0' == *last_char) && (offset >= 0) && (offset <= 0xFFFFFF)) {
+    	macaddr[3] = (offset & 0xFF0000) >> 16;
+    	macaddr[4] = (offset & 0xFF00) >> 8;
+    	macaddr[5] = offset & 0xFF;
+    	return 0;
+    } else {
+		  for(i = 0; i < 6; i++) {
+		      macaddr[i] = strtol(p, (char **)&p, 16);
+		      if (i == 5) {
+		          if (*p != '\0')
+		              return -1;
+		      } else {
+		          if (*p != ':' && *p != '-')
+		              return -1;
+		          p++;
+		      }
+		  }
+		  return 0;    
     }
-    return 0;
+    
+    return -1;
 }
 
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)

Reply via email to