2 * \author Torgeir Natvig <torgeir.natvig@redpill-linpro.com>
8 #include "../sys_func.h" // u_ntop
11 #include "log_ringbuffer.h"
14 output_plugin p_ringbuffer
;
16 output_plugin
*init_log_ringbuffer()
21 printf("init_log_ringbuffer\n\n");
23 key
= ftok("/etc/prads/prads.conf", 'R');
24 shm_id
= shmget(key
, sizeof(struct log_ringbuffer
), 0640 | IPC_CREAT
);
30 buffer
= shmat(shm_id
, (void *)0, 0);
31 if (buffer
== (char *)-1) {
36 memset(buffer
, 0, sizeof(struct log_ringbuffer
));
43 .connection
= &log_ringbuffer_connection
,
44 .denit
= &destory_log_ringbuffer
,
51 int destory_log_ringbuffer (output_plugin
*plugin
)
55 rc
= shmctl(shm_id
, IPC_RMID
, NULL
);
62 void log_ringbuffer_connection (output_plugin
*plugin
, connection
*cxt
, int outputmode
)
65 struct log_ringbuffer
*rb
;
66 char stime
[80], ltime
[80];
68 // uint32_t s_ip_t, d_ip_t;
69 char src_s
[INET6_ADDRSTRLEN
];
70 char dst_s
[INET6_ADDRSTRLEN
];
72 strftime(stime
, 80, "%F %H:%M:%S", gmtime(&cxt
->start_time
));
73 strftime(ltime
, 80, "%F %H:%M:%S", gmtime(&cxt
->last_pkt_time
));
74 tot_time
= cxt
->last_pkt_time
- cxt
->start_time
;
76 // if (outputmode != CX_NONE || outputmode || cxt->af == AF_INET6) {
77 if (!inet_ntop(cxt
->af
,
78 (cxt
->af
== AF_INET6
? (void*)&cxt
->s_ip
: (void*)cxt
->s_ip
.s6_addr32
),
79 src_s
, sizeof(src_s
)))
82 if (!inet_ntop(cxt
->af
,
83 (cxt
->af
== AF_INET6
? (void*)&cxt
->d_ip
: (void*)cxt
->d_ip
.s6_addr32
),
84 dst_s
, sizeof(dst_s
)))
87 } else if (cxt->af == AF_INET) {
88 s_ip_t = ntohl(cxt->s_ip.s6_addr32[0]);
89 d_ip_t = ntohl(cxt->d_ip.s6_addr32[0]);
92 rb
= (struct log_ringbuffer
*)plugin
->data
;
93 snprintf(rb
->items
[rb
->head
].text
, sizeof(rb
->items
[head
].text
),
94 "%ld%09ju|%s|%s|%ld|%u|%s|%u|%s|%u|%ju|%ju|%ju|%ju|%u|%u|%d",
117 if (rb
->head
>= RINGBUFFER_ITEMS
)