network.h 872 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef SYSART_NETWORK_H
  2. #define SYSART_NETWORK_H
  3. #include <stdint.h>
  4. #include <unistd.h>
  5. #include "common.h"
  6. #define PORT "29541"
  7. #define PKT_SIZE_MAX 4096
  8. #define assert_packet_size(packet) _Static_assert( \
  9. sizeof(struct packet) < PKT_SIZE_MAX, "PKT_SIZE_MAX violated");
  10. #define PKT_TYPE_UPDATE 0x01
  11. struct packet_update_t {
  12. uint16_t size;
  13. uint8_t type;
  14. uint8_t y;
  15. uint8_t x;
  16. uint8_t ch;
  17. } __attribute__((__packed__));
  18. assert_packet_size(packet_update_t)
  19. #define PKT_TYPE_HELLO 0x02
  20. #define PKT_TYPE_INIT 0x03
  21. struct packet_init_t {
  22. uint16_t size;
  23. uint8_t type;
  24. uint8_t data[(WIDTH+1)*HEIGHT];
  25. } __attribute__((__packed__));
  26. assert_packet_size(packet_init_t)
  27. int recv_packet(int fd, uint8_t* buf, size_t* n);
  28. int recv_dump_all(int fd);
  29. int recv_dump(int fd);
  30. size_t send_packet(int fd, uint8_t* buf, size_t length);
  31. #endif