-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.h
55 lines (45 loc) · 1.32 KB
/
message.h
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
#ifndef _MESSAGE_H
#define _MESSAGE_H
#include <arpa/inet.h>
#include "util.h"
/**
* @brief Message sent to the client by the server.
*
* @member _src_address IP address of the source of the message.
* @member _src_port Port of the source of the message.
* @member _payload Buffer containing actual contents of the message.
*/
struct message {
struct in_addr _src_address;
int _src_port;
char _payload[UDP_BUFFER_SIZE];
} __attribute__((packed));
/**
* @brief Allocate memory for message.
*
* @return Pointer to newly allocated message upon success.
* @return NULL upon failure.
*/
struct message *create_message();
/**
* @brief Extract topic name from message.
*
* @param msg Pointer to message received from the server.
* @param buffer Buffer in which the topic will be stored.
*/
void get_topic(struct message *msg, char *buffer);
/**
* @brief Extract content type from message.
*
* @param msg Pointer to message received from the server.
* @param type Pointer to variable which will hold the content type.
*/
void get_type(struct message *msg, uint8_t *type);
/**
* @brief Extract content from message.
*
* @param msg Pointer to message received from the server.
* @param buffer Buffer in which the content will be stored.
*/
void get_content(struct message *msg, char *buffer);
#endif /* _MESSAGE_H */