You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tftp.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef TFTP_H
  2. #define TFTP_H
  3. #include "in.h"
  4. #include "buffer.h"
  5. #include "nic.h"
  6. #define TFTP_PORT 69
  7. #define TFTP_DEFAULTSIZE_PACKET 512
  8. #define TFTP_MAX_PACKET 1432 /* 512 */
  9. #define TFTP_RRQ 1
  10. #define TFTP_WRQ 2
  11. #define TFTP_DATA 3
  12. #define TFTP_ACK 4
  13. #define TFTP_ERROR 5
  14. #define TFTP_OACK 6
  15. #define TFTP_CODE_EOF 1
  16. #define TFTP_CODE_MORE 2
  17. #define TFTP_CODE_ERROR 3
  18. #define TFTP_CODE_BOOT 4
  19. #define TFTP_CODE_CFG 5
  20. struct tftp_t {
  21. struct iphdr ip;
  22. struct udphdr udp;
  23. uint16_t opcode;
  24. union {
  25. uint8_t rrq[TFTP_DEFAULTSIZE_PACKET];
  26. struct {
  27. uint16_t block;
  28. uint8_t download[TFTP_MAX_PACKET];
  29. } data;
  30. struct {
  31. uint16_t block;
  32. } ack;
  33. struct {
  34. uint16_t errcode;
  35. uint8_t errmsg[TFTP_DEFAULTSIZE_PACKET];
  36. } err;
  37. struct {
  38. uint8_t data[TFTP_DEFAULTSIZE_PACKET+2];
  39. } oack;
  40. } u;
  41. } PACKED;
  42. /* define a smaller tftp packet solely for making requests to conserve stack
  43. 512 bytes should be enough */
  44. struct tftpreq_t {
  45. struct iphdr ip;
  46. struct udphdr udp;
  47. uint16_t opcode;
  48. union {
  49. uint8_t rrq[512];
  50. struct {
  51. uint16_t block;
  52. } ack;
  53. struct {
  54. uint16_t errcode;
  55. uint8_t errmsg[512-2];
  56. } err;
  57. } u;
  58. } PACKED;
  59. struct tftpreq_info_t {
  60. struct sockaddr_in *server;
  61. const char *name;
  62. unsigned short blksize;
  63. } PACKED;
  64. struct tftpblk_info_t {
  65. char *data;
  66. unsigned int block;
  67. unsigned int len;
  68. int eof;
  69. } PACKED;
  70. #define TFTP_MIN_PACKET (sizeof(struct iphdr) + sizeof(struct udphdr) + 4)
  71. /*
  72. * Functions in tftp.c. Needed for pxe_export.c
  73. *
  74. */
  75. extern int tftp_block ( struct tftpreq_info_t *request,
  76. struct tftpblk_info_t *block );
  77. extern int tftp ( char *url, struct sockaddr_in *server, char *file,
  78. struct buffer *buffer );
  79. #endif /* TFTP_H */