Fix Winsock recvfrom() timeouts
[oweals/nmrpflash.git] / nmrpd.h
1 /**
2  * nmrp-flash - Netgear Unbrick Utility
3  * Copyright (C) 2016 Joseph Lehner <joseph.c.lehner@gmail.com>
4  *
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.
9  *
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.
14  *
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/>.
17  *
18  */
19
20 #ifndef NMRPD_H
21 #define NMRPD_H
22 #include <stdint.h>
23 #include <stdbool.h>
24
25 #if defined(_WIN32) || defined(_WIN64)
26 #define NMRPFLASH_WINDOWS
27 #elif defined(__linux__)
28 #define NMRPFLASH_LINUX
29 #elif defined(__APPLE__) && defined(__MACH__)
30 #define NMRPFLASH_OSX
31 #elif defined(__unix__)
32 #define NMRPFLASH_UNIX
33 #warning "nmrp-flash is not fully supported on your operating system"
34 #endif
35
36 #ifndef NMRPFLASH_WINDOWS
37 #include <arpa/inet.h>
38 #include <sys/socket.h>
39 #include <net/if.h>
40 #else
41 #include <winsock2.h>
42 #include <iphlpapi.h>
43 #include <ws2tcpip.h>
44 #include <windows.h>
45 #endif
46
47 #define NMRPD_VERSION "0.9"
48
49 enum nmrp_op {
50         NMRP_UPLOAD_FW = 0,
51         NMRP_UPLOAD_ST = 1,
52         NMRP_SET_REGION = 2,
53 };
54
55 struct nmrpd_args {
56         unsigned rx_timeout;
57         unsigned ul_timeout;
58         const char *tftpcmd;
59         const char *filename;
60         const char *ipaddr;
61         const char *ipmask;
62         const char *intf;
63         const char *mac;
64         enum nmrp_op op;
65         uint16_t port;
66         int force_root;
67 };
68
69 int tftp_put(struct nmrpd_args *args);
70 int nmrp_do(struct nmrpd_args *args);
71 int select_fd(int fd, unsigned timeout);
72
73 #ifdef NMRPFLASH_WINDOWS
74 void win_perror2(const char *msg, DWORD err);
75 void sock_perror(const char *msg);
76 #else
77 #define sock_perror(x) perror(x)
78 #endif
79
80 extern int verbosity;
81
82 #endif