asyncburp: boilerplate
This commit is contained in:
95
specific/burpmsg.c
Normal file
95
specific/burpmsg.c
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* BURPMSG.C
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/select.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include "burpmsg.h"
|
||||
|
||||
/* ------------------------------------------------------------------- */
|
||||
int display_burp_msg(BurpMsg *header, void *data)
|
||||
{
|
||||
char *txt_type;
|
||||
|
||||
if (BURP_MAGIC != header->magic) {
|
||||
fprintf(stderr, "burpmsg at %p : invalid magic %08X\n",
|
||||
header, header->magic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
txt_type = "wtf?"; /* nice default value */
|
||||
|
||||
switch(header->msgtype) {
|
||||
|
||||
case BURP_RESET:
|
||||
txt_type = "reset";
|
||||
break;
|
||||
case BURP_SETSIZE:
|
||||
txt_type = "setsize";
|
||||
break;
|
||||
case BURP_LASER:
|
||||
txt_type = "laser";
|
||||
break;
|
||||
case BURP_SCENE:
|
||||
txt_type = "scene";
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "burpmsg at %p : invalid msgtype %d\n",
|
||||
header, header->msgtype);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "%4d %12s %9d %3d\n",
|
||||
header->msgtype, txt_type, header->serial, header->szdata);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------------------------------------------- */
|
||||
void la_grande_boucle( int fromfifo )
|
||||
{
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
int resval, foo;
|
||||
BurpMsg message;
|
||||
|
||||
for(;;) { /* start of infinite loop */
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(fromfifo, &fds);
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
resval = select(1, &fds, NULL, NULL, &tv);
|
||||
|
||||
if (-1 == resval) {
|
||||
perror("select()");
|
||||
/* ABORTING HERE ? */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resval) {
|
||||
/* message available */
|
||||
foo = read(fromfifo, &message, sizeof(BurpMsg));
|
||||
if (sizeof(BurpMsg) != foo) {
|
||||
fprintf(stderr, "err: %d read, %lu expected\n",
|
||||
foo, sizeof(BurpMsg));
|
||||
}
|
||||
display_burp_msg(&message, NULL);
|
||||
}
|
||||
else {
|
||||
/* got a time out */
|
||||
fprintf(stderr, "TIMEOUT\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* NOT REACHED */
|
||||
|
||||
}
|
||||
/* ------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user