blob: 7970e18cfd7503e0c61eed9097e9bf563b0ea4f9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include <stdint.h> // Provides uint8_t, int8_t, etc.
#define HELLO 0
#define SETSTATION 1
#define WELCOME 2
#define ANNOUNCE 3
#define INVALID 4
#define LISTSTATIONS 5
#define STATIONINFO 6
#define STATIONSHUTDOWN 7
#define NEWSTATION 8
#define TCP_TIMEOUT 100000 // 100ms in microseconds
#define MAX_PACKET_SIZE 512
// client to server messages (commands)
struct Hello {
uint8_t commandType; // 0
uint16_t udpPort;
} __attribute__((packed));
struct SetStation {
uint8_t commandType; // 1
uint16_t stationNumber;
} __attribute__((packed));
struct ListStations {
uint8_t commandType; // 5
} __attribute__((packed));
// server to client message (replies)
struct Welcome {
uint8_t replyType; // 2
uint16_t numStations;
} __attribute__((packed));
struct Announce {
uint8_t replyType; // 3
uint8_t songnameSize;
char *songname;
} __attribute__((packed));
struct InvalidCommand {
uint8_t replyType; // 4
uint8_t replyStringSize;
char *replyString;
} __attribute__((packed));
struct StationInfo {
uint8_t replyType; // 6
uint32_t infoStringSize;
char *infoString;
} __attribute__((packed));
struct StationShutdown {
uint8_t replyType; // 7
} __attribute__((packed));
struct NewStation {
uint8_t replyType; // 8
uint16_t stationNumber;
} __attribute__((packed));
int send_all(int sock, char *buf, int *len);
int recv_all(int sock, char *buf, int *len);
void *get_in_addr(struct sockaddr *sa);
|