Commit 702c651c4ae90ac399264c07aded66df2c0efacf
1 parent
1154e441
added -macaddr option
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@697 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
42 additions
and
11 deletions
vl.c
| ... | ... | @@ -1600,6 +1600,7 @@ void help(void) |
| 1600 | 1600 | "Network options:\n" |
| 1601 | 1601 | "-n script set network init script [default=%s]\n" |
| 1602 | 1602 | "-nics n simulate 'n' network interfaces [default=1]\n" |
| 1603 | + "-macaddr addr set the mac address of the first interface\n" | |
| 1603 | 1604 | "-tun-fd fd0[,...] use these fds as already opened tap/tun interfaces\n" |
| 1604 | 1605 | "\n" |
| 1605 | 1606 | "Linux boot specific:\n" |
| ... | ... | @@ -1655,6 +1656,7 @@ struct option long_options[] = { |
| 1655 | 1656 | { "fdb", 1, NULL, 0, }, |
| 1656 | 1657 | { "no-code-copy", 0, NULL, 0 }, |
| 1657 | 1658 | { "nics", 1, NULL, 0 }, |
| 1659 | + { "macaddr", 1, NULL, 0 }, | |
| 1658 | 1660 | { NULL, 0, NULL, 0 }, |
| 1659 | 1661 | }; |
| 1660 | 1662 | |
| ... | ... | @@ -1692,6 +1694,7 @@ int main(int argc, char **argv) |
| 1692 | 1694 | const char *kernel_filename, *kernel_cmdline; |
| 1693 | 1695 | DisplayState *ds = &display_state; |
| 1694 | 1696 | int cyls, heads, secs; |
| 1697 | + uint8_t macaddr[6]; | |
| 1695 | 1698 | |
| 1696 | 1699 | #if !defined(CONFIG_SOFTMMU) |
| 1697 | 1700 | /* we never want that malloc() uses mmap() */ |
| ... | ... | @@ -1717,17 +1720,13 @@ int main(int argc, char **argv) |
| 1717 | 1720 | cyls = heads = secs = 0; |
| 1718 | 1721 | |
| 1719 | 1722 | nb_nics = 1; |
| 1720 | - for(i = 0; i < MAX_NICS; i++) { | |
| 1721 | - NetDriverState *nd = &nd_table[i]; | |
| 1722 | - nd->fd = -1; | |
| 1723 | - /* init virtual mac address */ | |
| 1724 | - nd->macaddr[0] = 0x52; | |
| 1725 | - nd->macaddr[1] = 0x54; | |
| 1726 | - nd->macaddr[2] = 0x00; | |
| 1727 | - nd->macaddr[3] = 0x12; | |
| 1728 | - nd->macaddr[4] = 0x34; | |
| 1729 | - nd->macaddr[5] = 0x56 + i; | |
| 1730 | - } | |
| 1723 | + /* default mac address of the first network interface */ | |
| 1724 | + macaddr[0] = 0x52; | |
| 1725 | + macaddr[1] = 0x54; | |
| 1726 | + macaddr[2] = 0x00; | |
| 1727 | + macaddr[3] = 0x12; | |
| 1728 | + macaddr[4] = 0x34; | |
| 1729 | + macaddr[5] = 0x56; | |
| 1731 | 1730 | |
| 1732 | 1731 | for(;;) { |
| 1733 | 1732 | c = getopt_long_only(argc, argv, "hm:d:n:sp:L:", long_options, &long_index); |
| ... | ... | @@ -1835,6 +1834,27 @@ int main(int argc, char **argv) |
| 1835 | 1834 | exit(1); |
| 1836 | 1835 | } |
| 1837 | 1836 | break; |
| 1837 | + case 17: | |
| 1838 | + { | |
| 1839 | + const char *p; | |
| 1840 | + int i; | |
| 1841 | + p = optarg; | |
| 1842 | + for(i = 0; i < 6; i++) { | |
| 1843 | + macaddr[i] = strtol(p, (char **)&p, 16); | |
| 1844 | + if (i == 5) { | |
| 1845 | + if (*p != '\0') | |
| 1846 | + goto macaddr_error; | |
| 1847 | + } else { | |
| 1848 | + if (*p != ':') { | |
| 1849 | + macaddr_error: | |
| 1850 | + fprintf(stderr, "qemu: invalid syntax for ethernet address\n"); | |
| 1851 | + exit(1); | |
| 1852 | + } | |
| 1853 | + p++; | |
| 1854 | + } | |
| 1855 | + } | |
| 1856 | + } | |
| 1857 | + break; | |
| 1838 | 1858 | } |
| 1839 | 1859 | break; |
| 1840 | 1860 | case 'h': |
| ... | ... | @@ -1912,6 +1932,17 @@ int main(int argc, char **argv) |
| 1912 | 1932 | #endif |
| 1913 | 1933 | |
| 1914 | 1934 | /* init host network redirectors */ |
| 1935 | + for(i = 0; i < MAX_NICS; i++) { | |
| 1936 | + NetDriverState *nd = &nd_table[i]; | |
| 1937 | + nd->fd = -1; | |
| 1938 | + /* init virtual mac address */ | |
| 1939 | + nd->macaddr[0] = macaddr[0]; | |
| 1940 | + nd->macaddr[1] = macaddr[1]; | |
| 1941 | + nd->macaddr[2] = macaddr[2]; | |
| 1942 | + nd->macaddr[3] = macaddr[3]; | |
| 1943 | + nd->macaddr[4] = macaddr[4]; | |
| 1944 | + nd->macaddr[5] = macaddr[5] + i; | |
| 1945 | + } | |
| 1915 | 1946 | net_init(); |
| 1916 | 1947 | |
| 1917 | 1948 | /* init the memory */ | ... | ... |