#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <fcntl.h>
#include <string.h>
#include <limits.h>
#include <sys/types.h>
#include <errno.h>
#include <net/br.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
static void brd_print(char*, struct fdb*);
int main(int argc, char **argv)
{
int status;
int fd;
struct fdb req;
openlog ("brd", LOG_PID | LOG_CONS, LOG_DAEMON);
syslog(LOG_NOTICE, "Initializing, version %s\n", BRD_VERSION);
fd = open("/dev/brd", O_RDWR);
if (fd < 0) {
syslog(LOG_CRIT, "cannot open /dev/brd: %m");
exit(-1);
}
while (1) {
status = read(fd, &req, sizeof(req));
if (status < 0) {
if (errno == EINTR)
continue;
syslog(LOG_CRIT, "cannot read from /dev/brd: %m");
exit(-1);
}
if (status != sizeof(req))
{
syslog(LOG_CRIT, "read from /dev/brd returns %d",
status);
exit(-1);
}
brd_print("UPDATE", &req);
}
return 0;
}
static void brd_print(char * type, struct fdb* request)
{
unsigned short port=request->port;
unsigned char *ula=request->ula;
unsigned int timer=request->timer;
unsigned int flags=request->flags;
unsigned int vlan_id=request->vlan_id;
fprintf(stderr, "Type: UPDATE,\n");
fprintf(stderr, "Port: %i,\n", port);
fprintf(stderr, "Mac: %02x:%02x:%02x:%02x:%02x:%02x,\n",
ula[0], ula[1], ula[2], ula[3], ula[4], ula[5]);
fprintf(stderr, "v_id: %d,\n", vlan_id);
fprintf(stderr, "Flag: %d,\n", flags);
fprintf(stderr, "Updt: %d;\n\n", timer);
}