nmrpd.h 2.3 KB

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