30 lines
720 B
C
30 lines
720 B
C
|
#include "cap_utils.h"
|
||
|
|
||
|
void cap_load(struct cap_file *cf, char* filename) {
|
||
|
if ((cf->fd = fopen(filename, "r")) == NULL) {
|
||
|
perror("Unable to open file");
|
||
|
exit(EXIT_FAILURE);
|
||
|
}
|
||
|
|
||
|
fseek(cf->fd, 0, SEEK_END);
|
||
|
cf->sz = ftell(cf->fd);
|
||
|
fseek(cf->fd, 0, SEEK_SET);
|
||
|
}
|
||
|
|
||
|
void cap_next_bp(struct cap_file *cf, struct buffer_packet* bp) {
|
||
|
fread(bp, sizeof(struct buffer_packet), 1, cf->fd);
|
||
|
}
|
||
|
|
||
|
void cap_peek_bp(struct cap_file *cf, struct buffer_packet* bp) {
|
||
|
size_t n = fread(bp, sizeof(struct buffer_packet), 1, cf->fd);
|
||
|
fseek(cf->fd, -n, SEEK_CUR);
|
||
|
}
|
||
|
|
||
|
size_t cap_count_bp(struct cap_file *cf) {
|
||
|
return cf->sz / sizeof(struct buffer_packet);
|
||
|
}
|
||
|
|
||
|
void cap_unload(struct cap_file *cf) {
|
||
|
fclose(cf->fd);
|
||
|
}
|