2 * nmrp-flash - Netgear Unbrick Utility
3 * Copyright (C) 2016 Joseph Lehner <joseph.c.lehner@gmail.com>
5 * nmrp-flash is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * nmrp-flash is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with nmrp-flash. If not, see <http://www.gnu.org/licenses/>.
30 "Usage: nmrp-flash [OPTIONS...]\n"
32 "Options (-a, -i and -f are mandatory):\n"
33 " -a <ipaddr> IP address to assign to target device\n"
34 " -f <firmware> Firmware file\n"
35 " -i <interface> Network interface directly connected to device\n"
36 " -m <mac> MAC address of target device (xx:xx:xx:xx:xx:xx)\n"
37 " -M <netmask> Subnet mask to assign to target device\n"
38 " -t <timeout> Timeout (in milliseconds) for regular messages\n"
39 " -T <timeout> Time to wait after successfull TFTP upload\n"
40 " -p <port> Port to use for TFTP upload\n"
42 " -V Print version and exit\n"
43 " -L List network interfaces\n"
44 " -h Show this screen\n"
48 #ifndef NMRPFLASH_WINDOWS
49 "$ sudo nmrp-flash -i eth0 -a 192.168.1.254 -f firmware.bin\n"
51 "C:\\> nmrp-flash.exe -i net0 -a 192.168.1.254 -f firmware.bin\n"
54 "nmrp-flash v%s, Copyright (C) 2016 Joseph C. Lehner\n"
55 "nmrp-flash is free software, licensed under the GNU GPLv3.\n"
56 "Source code at https://github.com/jclehner/nmrp-flash\n"
62 int main(int argc, char **argv)
65 struct nmrpd_args args = {
71 .ipmask = "255.255.255.0",
73 .mac = "ff:ff:ff:ff:ff:ff",
78 #ifdef NMRPFLASH_WINDOWS
81 val = WSAStartup(MAKEWORD(2, 2), &wsa);
83 win_perror2("WSAStartup", val);
90 while ((c = getopt(argc, argv, "a:f:i:m:M:p:t:T:hLVv")) != -1) {
97 args.filename = optarg;
106 args.ipmask = optarg;
113 if (val <= 0 || val > max) {
114 fprintf(stderr, "Invalid numeric value for -%c.\n", c);
120 } else if (c == 't') {
121 args.rx_timeout = val;
123 args.ul_timeout = val;
128 printf("nmrp-flash v%s\n", NMRPD_VERSION);
134 return ethsock_list_all();
144 if (!args.filename || !args.intf || !args.ipaddr) {
149 #ifndef NMRPFLASH_WINDOWS
150 if (geteuid() != 0) {
151 fprintf(stderr, "This program must be run as root!\n");
156 val = nmrp_do(&args);
157 #ifdef NMRPFLASH_WINDOWS