2 * nmrpflash - Netgear Unbrick Utility
3 * Copyright (C) 2016 Joseph Lehner <joseph.c.lehner@gmail.com>
5 * nmrpflash 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 * nmrpflash 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 nmrpflash. If not, see <http://www.gnu.org/licenses/>.
31 "Usage: nmrpflash [OPTIONS...]\n"
33 "Options (-a, -i and -f and/or -c are mandatory):\n"
34 " -a <ipaddr> IP address to assign to target device\n"
35 " -c <command> Command to run before (or instead of) TFTP upload\n"
36 " -f <firmware> Firmware file\n"
37 " -F <filename> Remote filename to use during TFTP upload\n"
38 " -i <interface> Network interface directly connected to device\n"
39 " -m <mac> MAC address of target device (xx:xx:xx:xx:xx:xx)\n"
40 " -M <netmask> Subnet mask to assign to target device\n"
41 " -t <timeout> Timeout (in milliseconds) for regular messages\n"
42 " -T <timeout> Time (seconds) to wait after successfull TFTP upload\n"
43 " -p <port> Port to use for TFTP upload\n"
44 #ifdef NMRPFLASH_SET_REGION
45 " -R <region> Set device region\n"
47 #ifdef NMRPFLASH_TFTP_TEST
48 " -U Test TFTP upload\n"
51 " -V Print version and exit\n"
52 " -L List network interfaces\n"
53 " -h Show this screen\n"
57 #ifndef NMRPFLASH_WINDOWS
58 "$ sudo nmrpflash -i eth0 -a 192.168.1.254 -f firmware.bin\n"
60 "C:\\> nmrpflash.exe -i net0 -a 192.168.1.254 -f firmware.bin\n"
63 "nmrpflash %s, Copyright (C) 2016 Joseph C. Lehner\n"
64 "nmrpflash is free software, licensed under the GNU GPLv3.\n"
65 "Source code at https://github.com/jclehner/nmrpflash\n"
71 int main(int argc, char **argv)
74 struct nmrpd_args args = {
81 .ipmask = "255.255.255.0",
83 .mac = "ff:ff:ff:ff:ff:ff",
88 #ifdef NMRPFLASH_WINDOWS
91 val = WSAStartup(MAKEWORD(2, 2), &wsa);
93 win_perror2("WSAStartup", val);
100 while ((c = getopt(argc, argv, "a:c:f:F:i:m:M:p:R:t:T:hLVvU")) != -1) {
104 args.ipaddr = optarg;
107 args.tftpcmd = optarg;
110 args.file_local = optarg;
113 args.file_remote = optarg;
122 args.ipmask = optarg;
125 #ifdef NMRPFLASH_SET_REGION
132 } else if (c == 'R') {
137 if (val <= 0 || val > max) {
138 fprintf(stderr, "Invalid numeric value for -%c.\n", c);
144 } else if (c == 't') {
145 args.rx_timeout = val;
146 } else if (c == 'T') {
147 args.ul_timeout = val * 1000;
148 } else if (c == 'R') {
154 printf("nmrpflash %s\n", NMRPFLASH_VERSION);
161 val = ethsock_list_all();
167 #ifdef NMRPFLASH_TFTP_TEST
169 if (args.ipaddr && args.file_local) {
170 val = tftp_put(&args);
182 if ((!args.file_local && !args.tftpcmd) || !args.intf || !args.ipaddr) {
187 #ifndef NMRPFLASH_WINDOWS
188 if (geteuid() != 0) {
189 fprintf(stderr, "This program must be run as root!\n");
194 val = nmrp_do(&args);
197 #ifdef NMRPFLASH_WINDOWS