forked from fnoop/wifibroadcast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.c
64 lines (42 loc) · 1.08 KB
/
lib.c
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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "lib.h"
void lib_init_packet_buffer(packet_buffer_t *p) {
assert(p != NULL);
p->valid = 0;
p->crc_correct = 0;
p->len = 0;
p->data = NULL;
}
void lib_alloc_packet_buffer(packet_buffer_t *p, size_t len) {
assert(p != NULL);
assert(len > 0);
p->len = 0;
p->data = (uint8_t*)malloc(len);
}
void lib_free_packet_buffer(packet_buffer_t *p) {
assert(p != NULL);
free(p->data);
p->len = 0;
}
packet_buffer_t *lib_alloc_packet_buffer_list(size_t num_packets, size_t packet_length) {
packet_buffer_t *retval;
int i;
assert(num_packets > 0 && packet_length > 0);
retval = (packet_buffer_t *)malloc(sizeof(packet_buffer_t) * num_packets);
assert(retval != NULL);
for(i=0; i<num_packets; ++i) {
lib_init_packet_buffer(retval + i);
lib_alloc_packet_buffer(retval + i, packet_length);
}
return retval;
}
void lib_free_packet_buffer_list(packet_buffer_t *p, size_t num_packets) {
int i;
assert(p != NULL && num_packets > 0);
for(i=0; i<num_packets; ++i) {
lib_free_packet_buffer(p+i);
}
free(p);
}