#ifndef NMRPD_H
#define NMRPD_H
#include <stdint.h>
+#include <signal.h>
#include <stdbool.h>
#if defined(_WIN32) || defined(_WIN64)
-#define NMRPFLASH_WINDOWS
-#elif defined(__linux__)
-#define NMRPFLASH_LINUX
+# define NMRPFLASH_WINDOWS
#elif defined(__APPLE__) && defined(__MACH__)
-#define NMRPFLASH_OSX
-#elif defined(__unix__)
-#define NMRPFLASH_UNIX
-#warning "nmrpflash is not fully supported on your operating system"
+# define NMRPFLASH_UNIX
+# define NMRPFLASH_OSX
+# define NMRPFLASH_BSD
+#elif defined (__unix__)
+# define NMRPFLASH_UNIX
+# if defined(__linux__)
+# define NMRPFLASH_LINUX
+# elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
+# define NMRPFLASH_BSD
+# else
+# warning "nmrpflash is not fully supported on this platform"
+# endif
+#else
+# warning "nmrpflash is not supported on this platform"
#endif
#ifndef NMRPFLASH_WINDOWS
#include <arpa/inet.h>
+#include <sys/types.h>
#include <sys/socket.h>
+#include <netinet/in.h>
#include <net/if.h>
+#ifndef NMRPFLASH_LINUX
+#include <net/if_dl.h>
+#endif
#else
#include <winsock2.h>
#include <iphlpapi.h>
#include <windows.h>
#endif
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
+#ifndef PACKED
+#define PACKED __attribute__((packed))
+#endif
+
+#define NMRPFLASH_SET_REGION
+
+struct eth_hdr {
+ uint8_t ether_dhost[6];
+ uint8_t ether_shost[6];
+ uint16_t ether_type;
+} PACKED;
+
enum nmrp_op {
NMRP_UPLOAD_FW = 0,
NMRP_UPLOAD_ST = 1,
unsigned rx_timeout;
unsigned ul_timeout;
const char *tftpcmd;
- const char *filename;
+ const char *file_local;
+ const char *file_remote;
+ const char *ipaddr_intf;
const char *ipaddr;
const char *ipmask;
const char *intf;
const char *mac;
enum nmrp_op op;
+ bool blind;
uint16_t port;
- int force_root;
+ const char *region;
};
+const char *leafname(const char *path);
int tftp_put(struct nmrpd_args *args);
+bool tftp_is_valid_filename(const char *filename);
+
int nmrp_do(struct nmrpd_args *args);
int select_fd(int fd, unsigned timeout);
void win_perror2(const char *msg, DWORD err);
void sock_perror(const char *msg);
#else
-#define sock_perror(x) perror(x)
+#define sock_perror(x) xperror(x)
#endif
extern int verbosity;
struct ethsock;
+struct ethsock_arp_undo;
+struct ethsock_ip_undo;
struct ethsock *ethsock_create(const char *intf, uint16_t protocol);
int ethsock_close(struct ethsock *sock);
ssize_t ethsock_recv(struct ethsock *sock, void *buf, size_t len);
int ethsock_set_timeout(struct ethsock *sock, unsigned msec);
uint8_t *ethsock_get_hwaddr(struct ethsock *sock);
+int ethsock_arp_add(struct ethsock *sock, uint8_t *hwaddr, uint32_t ipaddr, struct ethsock_arp_undo **undo);
+int ethsock_arp_del(struct ethsock *sock, struct ethsock_arp_undo **undo);
int ethsock_list_all(void);
+struct ethsock_ip_callback_args
+{
+ struct in_addr *ipaddr;
+ struct in_addr *ipmask;
+ void *arg;
+};
+
+typedef int (*ethsock_ip_callback_t)(struct ethsock_ip_callback_args *args);
+int ethsock_for_each_ip(struct ethsock *sock, ethsock_ip_callback_t callback,
+ void *arg);
+
+int ethsock_ip_add(struct ethsock *sock, uint32_t ipaddr, uint32_t ipmask, struct ethsock_ip_undo **undo);
+int ethsock_ip_del(struct ethsock *sock, struct ethsock_ip_undo **undo);
+
+time_t time_monotonic();
+char *lltostr(long long ll, int base);
+uint32_t bitcount(uint32_t n);
+uint32_t netmask(uint32_t count);
+void xperror(const char *msg);
+
+extern volatile sig_atomic_t g_interrupted;
#endif