-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDUTransmit.h
More file actions
45 lines (35 loc) · 1.97 KB
/
PDUTransmit.h
File metadata and controls
45 lines (35 loc) · 1.97 KB
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
#ifndef UDPTRANSMIT_H
#define UDPTRANSMIT_H
#include <stdint.h>
#define DataOffset 3 //subtract PDUMsg.length by this to get length of data
#define MaxIPMsgSize 1500
#define maxTextLen 200
#define maxHandleLen 100
//for ease of parsing messages. Not used in these functions, but can be used elsewhere when convenient
struct PDUMsg {
uint16_t nw_length; // length of entire message, including these header bytes
uint8_t flag; // 1 byte at offset 2
uint8_t data[MaxIPMsgSize]; // flexible array starting at offset 3
} __attribute__((__packed__));
//list of possible flags for messages
typedef enum {
FLAG_CLIENT_INITIAL = 1, // Client initial packet to the server
FLAG_SEND_ACCEPTED = 2, // Server confirms good handle
FLAG_SEND_REJECTED = 3, // Server rejects handle (already exists)
FLAG_BROADCAST_MESSAGE = 4, // Broadcast message from client
FLAG_DIRECT_MESSAGE = 5, // Direct message to another client
FLAG_MULTICAST_MESSAGE = 6, // Multicast message to multiple clients
FLAG_INVALID_HANDLE = 7, // Error: destination handle does not exist
FLAG_REQUEST_HANDLE_LIST = 10, // Client requests list of handles (%L)
FLAG_SEND_LIST_COUNT = 11, // Server responds with number of handles
FLAG_SEND_LIST_ENTRY = 12, // Server sends one handle entry
FLAG_SEND_LIST_DONE = 13 // Server signals end of handle list
} ChatFlag;
//add PDU then send (adds 2 bytes indicating msg length)
int sendPDU(int socketNumber, uint8_t* dataBuffer, int lengthOfData); //returns # bytes sent
//same as sendPDU, but also inserts the flag after PDU (but before dataBuffer)
int sendPDUWithFlag(int clientSocket, uint8_t flag, uint8_t* dataBuffer, int lengthOfData);
//sends a message just containing the PDU (2 bytes length, and 1 byte flag), of the corresponding flag passed in
int sendResponseFlag(int clientSocket, uint8_t flag);
int recvPDU(int clientSocket, uint8_t* dataBuffer, int bufferSize);
#endif // UDPTRANSMIT_H