aboutsummaryrefslogtreecommitdiff
path: root/protocol.h
diff options
context:
space:
mode:
Diffstat (limited to 'protocol.h')
-rw-r--r--protocol.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/protocol.h b/protocol.h
new file mode 100644
index 0000000..aeeaa54
--- /dev/null
+++ b/protocol.h
@@ -0,0 +1,41 @@
+#include <stdint.h> // Provides uint8_t, int8_t, etc.
+
+// client to server messages (commands)
+
+struct Command {
+ uint8_t commandType;
+ uint16_t number;
+} __attribute__((packed));
+
+struct Hello {
+ uint8_t commandType;
+ uint16_t udpPort;
+} __attribute__((packed));
+struct SetStation {
+ uint8_t commandType;
+ uint16_t stationNumber;
+} __attribute__((packed));
+
+// server to client message (replies)
+struct Welcome {
+ uint8_t replyType;
+ uint16_t numStations;
+} __attribute__((packed));
+
+struct Reply {
+ uint8_t replyType;
+ uint8_t stringSize;
+} reply_t __attribute__((packed));
+struct Announce {
+ uint8_t replyType;
+ uint8_t songnameSize;
+ char *songname;
+} __attribute__((packed));
+struct InvalidCommand {
+ uint8_t replyType;
+ uint8_t replyStringSize;
+ char *replyString;
+} __attribute__((packed));
+
+int send_all(int sock, char *buf, int *len);
+int recv_all(int sock, char *buf, int *len);