mirror of https://github.com/dirtbags/fluffy.git
Reindent everything
This commit is contained in:
parent
31e9beb71a
commit
9bd3e1bd87
4
Makefile
4
Makefile
|
@ -1,6 +1,6 @@
|
|||
CFLAGS = -Wall -Werror
|
||||
TARGETS = pmerge puniq p4split hd
|
||||
TARGETS += pyesc printfesc pcat
|
||||
TARGETS = pmerge puniq p4split pcat
|
||||
TARGETS += hd pyesc printfesc xor unhex
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
|
|
3
hd.c
3
hd.c
|
@ -38,7 +38,8 @@ dump(FILE *f)
|
|||
offset = 16 - offset;
|
||||
|
||||
len = fread(bytes, 1, 16, f);
|
||||
if (0 == len) break;
|
||||
if (0 == len)
|
||||
break;
|
||||
|
||||
if (p && (0 == memcmp(buf, buf + 16, 16))) {
|
||||
if (!skipping) {
|
||||
|
|
41
p4split.c
41
p4split.c
|
@ -5,7 +5,9 @@
|
|||
#include <strings.h>
|
||||
#include "pcap.h"
|
||||
|
||||
/* Gaah so much crap */
|
||||
/*
|
||||
* Gaah so much crap
|
||||
*/
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/ether.h>
|
||||
|
@ -36,7 +38,8 @@ parse_cidr(char *s, uint32_t *addr, uint8_t *bits)
|
|||
*bits = 0;
|
||||
}
|
||||
|
||||
if (0 == inet_aton(s, &inp)) return -1;
|
||||
if (0 == inet_aton(s, &inp))
|
||||
return -1;
|
||||
*addr = ntohl(inp.s_addr);
|
||||
|
||||
return 0;
|
||||
|
@ -55,9 +58,12 @@ main(int argc, char *argv[])
|
|||
uint8_t shr;
|
||||
int i;
|
||||
|
||||
if (argc != 2) return usage(0);
|
||||
if (-1 == parse_cidr(argv[1], &addr, &bits)) return usage(0);
|
||||
if (bits > 24) return usage(0);
|
||||
if (argc != 2)
|
||||
return usage(0);
|
||||
if (-1 == parse_cidr(argv[1], &addr, &bits))
|
||||
return usage(0);
|
||||
if (bits > 24)
|
||||
return usage(0);
|
||||
if (bits % 8) {
|
||||
fprintf(stderr, "Warning: routing prefix is not a multiple of 8.\n");
|
||||
}
|
||||
|
@ -70,7 +76,8 @@ main(int argc, char *argv[])
|
|||
out[i].f = NULL;
|
||||
}
|
||||
|
||||
if (-1 == pcap_open_in(&p, stdin)) return usage(0);
|
||||
if (-1 == pcap_open_in(&p, stdin))
|
||||
return usage(0);
|
||||
|
||||
while (1) {
|
||||
struct pcap_pkthdr hdr;
|
||||
|
@ -78,8 +85,10 @@ main(int argc, char *argv[])
|
|||
char frame[MAXFRAME];
|
||||
|
||||
ok = 1;
|
||||
if (-1 == pcap_read_pkthdr(&p, &hdr)) break;
|
||||
if (1 != fread(frame, hdr.caplen, 1, p.f)) break;
|
||||
if (-1 == pcap_read_pkthdr(&p, &hdr))
|
||||
break;
|
||||
if (1 != fread(frame, hdr.caplen, 1, p.f))
|
||||
break;
|
||||
|
||||
|
||||
{
|
||||
|
@ -87,7 +96,9 @@ main(int argc, char *argv[])
|
|||
struct iphdr *ih = (struct iphdr *) (frame + sizeof(struct ether_header));
|
||||
uint32_t a;
|
||||
|
||||
/* VLAN tag */
|
||||
/*
|
||||
* VLAN tag
|
||||
*/
|
||||
if (ntohs(eh->ether_type) == 0x8100) {
|
||||
ih = (struct iphdr *) ((char *) ih + 4);
|
||||
}
|
||||
|
@ -111,12 +122,16 @@ main(int argc, char *argv[])
|
|||
|
||||
sprintf(fn, "%d.pcap", octet);
|
||||
|
||||
if (NULL == (f = fopen(fn, "wb"))) break;
|
||||
if (-1 == pcap_open_out(&out[octet], f)) break;
|
||||
if (NULL == (f = fopen(fn, "wb")))
|
||||
break;
|
||||
if (-1 == pcap_open_out(&out[octet], f))
|
||||
break;
|
||||
}
|
||||
|
||||
if (-1 == pcap_write_pkthdr(&out[octet], &hdr)) break;
|
||||
if (1 != fwrite(frame, hdr.caplen, 1, out[octet].f)) break;
|
||||
if (-1 == pcap_write_pkthdr(&out[octet], &hdr))
|
||||
break;
|
||||
if (1 != fwrite(frame, hdr.caplen, 1, out[octet].f))
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
|
|
21
pcap.c
21
pcap.c
|
@ -19,10 +19,13 @@ pcap_open_in(struct pcap_file *ctx, FILE *f)
|
|||
} else {
|
||||
return -1;
|
||||
}
|
||||
if ((h.version_major != 2) || (h.version_minor != 4)) return -1;
|
||||
if ((h.version_major != 2) || (h.version_minor != 4))
|
||||
return -1;
|
||||
|
||||
if (ctx->swap) h.snaplen = bswap32(h.snaplen);
|
||||
if (h.snaplen > MAXFRAME) return -1;
|
||||
if (ctx->swap)
|
||||
h.snaplen = bswap32(h.snaplen);
|
||||
if (h.snaplen > MAXFRAME)
|
||||
return -1;
|
||||
|
||||
ctx->f = f;
|
||||
return 0;
|
||||
|
@ -33,7 +36,8 @@ pcap_open_out(struct pcap_file *ctx, FILE *f)
|
|||
{
|
||||
struct pcap_file_header h = { MAGIC, 2, 4, 0, 0, MAXFRAME, 1 };
|
||||
|
||||
if (1 != fwrite(&h, sizeof(h), 1, f)) return -1;
|
||||
if (1 != fwrite(&h, sizeof(h), 1, f))
|
||||
return -1;
|
||||
ctx->f = f;
|
||||
ctx->swap = 0;
|
||||
|
||||
|
@ -54,7 +58,8 @@ pcap_read_pkthdr(struct pcap_file *ctx, struct pcap_pkthdr *hdr)
|
|||
hdr->len = bswap32(hdr->len);
|
||||
}
|
||||
|
||||
if (hdr->caplen > MAXFRAME) return -1;
|
||||
if (hdr->caplen > MAXFRAME)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -71,9 +76,11 @@ pcap_write_pkthdr(struct pcap_file *ctx, struct pcap_pkthdr *hdr)
|
|||
hdr->caplen = bswap32(hdr->caplen);
|
||||
hdr->len = bswap32(hdr->len);
|
||||
|
||||
if (1 != fwrite(&ohdr, sizeof(ohdr), 1, ctx->f)) return -1;
|
||||
if (1 != fwrite(&ohdr, sizeof(ohdr), 1, ctx->f))
|
||||
return -1;
|
||||
} else {
|
||||
if (1 != fwrite(hdr, sizeof(*hdr), 1, ctx->f)) return -1;
|
||||
if (1 != fwrite(hdr, sizeof(*hdr), 1, ctx->f))
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
4
pcap.h
4
pcap.h
|
@ -47,7 +47,9 @@ struct pcap_pkthdr {
|
|||
((i & 0x00ff) << 010))
|
||||
|
||||
|
||||
/* Debugging help */
|
||||
/*
|
||||
* Debugging help
|
||||
*/
|
||||
#define DUMPf(fmt, args...) fprintf(stderr, "%s:%s:%d " fmt "\n", __FILE__, __FUNCTION__, __LINE__, ##args)
|
||||
#define DUMP() DUMPf("")
|
||||
#define DUMP_d(v) DUMPf("%s = %d", #v, v)
|
||||
|
|
35
pcat.c
35
pcat.c
|
@ -15,11 +15,7 @@
|
|||
void
|
||||
ip4_addr(char *addr_s, uint32_t addr)
|
||||
{
|
||||
snprintf(addr_s, 16, "%u.%u.%u.%u",
|
||||
(addr >> 24) & 0xff,
|
||||
(addr >> 16) & 0xff,
|
||||
(addr >> 8) & 0xff,
|
||||
(addr >> 0) & 0xff);
|
||||
snprintf(addr_s, 16, "%u.%u.%u.%u", (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, (addr >> 0) & 0xff);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -51,14 +47,7 @@ process_tcp(struct stream *s, char *saddr_s, char *daddr_s)
|
|||
printf("TCP4 %s:%u %s:%u ", saddr_s, sport, daddr_s, dport);
|
||||
|
||||
// shut the compiler up
|
||||
if (false &&
|
||||
urgent &&
|
||||
chksum &&
|
||||
window &&
|
||||
flags &&
|
||||
ack &&
|
||||
seq &&
|
||||
false);
|
||||
if (false && urgent && chksum && window && flags && ack && seq && false);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -72,10 +61,7 @@ process_udp(struct stream *s, char *saddr_s, char *daddr_s)
|
|||
printf("UDP4 %s:%u %s:%u ", saddr_s, sport, daddr_s, dport);
|
||||
|
||||
// Now, do some shit!
|
||||
if (false &&
|
||||
len &&
|
||||
chksum &&
|
||||
false);
|
||||
if (false && len && chksum && false);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -119,14 +105,10 @@ process_ip4(struct stream *s)
|
|||
|
||||
print_payload(s);
|
||||
|
||||
/* Placate compiler */
|
||||
if (false &&
|
||||
chksum &&
|
||||
id &&
|
||||
tos &&
|
||||
ttl &&
|
||||
off &&
|
||||
false);
|
||||
/*
|
||||
* Placate compiler
|
||||
*/
|
||||
if (false && chksum && id && tos && ttl && off && false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -171,7 +153,8 @@ pcat(FILE *f)
|
|||
{
|
||||
struct pcap_file p;
|
||||
|
||||
if (-1 == pcap_open_in(&p, f)) return;
|
||||
if (-1 == pcap_open_in(&p, f))
|
||||
return;
|
||||
|
||||
for (;;) {
|
||||
struct pcap_pkthdr hdr;
|
||||
|
|
33
pmerge.c
33
pmerge.c
|
@ -21,7 +21,8 @@ usage(int ret)
|
|||
int
|
||||
read_next(struct input_file *file)
|
||||
{
|
||||
if (! file->active) return -1;
|
||||
if (!file->active)
|
||||
return -1;
|
||||
|
||||
if (-1 == pcap_read_pkthdr(&file->p, &file->next)) {
|
||||
pcap_close(&file->p);
|
||||
|
@ -43,15 +44,19 @@ main(int argc, char *argv[])
|
|||
int i;
|
||||
struct pcap_file out;
|
||||
|
||||
if (1 == argc) return usage(0);
|
||||
if (1 == argc)
|
||||
return usage(0);
|
||||
|
||||
/* Open input files */
|
||||
/*
|
||||
* Open input files
|
||||
*/
|
||||
for (i = 0; i < argc - 1; i += 1) {
|
||||
char *fn = argv[i + 1];
|
||||
struct input_file *cur = &files[nfiles];
|
||||
FILE *f;
|
||||
|
||||
if ('-' == fn[0]) return usage(0);
|
||||
if ('-' == fn[0])
|
||||
return usage(0);
|
||||
|
||||
f = fopen(fn, "rb");
|
||||
if (NULL == f) {
|
||||
|
@ -81,7 +86,9 @@ main(int argc, char *argv[])
|
|||
char frame[MAXFRAME];
|
||||
size_t len;
|
||||
|
||||
/* Find next oldest frame */
|
||||
/*
|
||||
* Find next oldest frame
|
||||
*/
|
||||
for (i = 0; i < nfiles; i += 1) {
|
||||
if (files[i].active &&
|
||||
((files[i].next.ts.tv_sec < cur->next.ts.tv_sec) ||
|
||||
|
@ -91,22 +98,30 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
/* Make sure it'll fit */
|
||||
/*
|
||||
* Make sure it'll fit
|
||||
*/
|
||||
if (cur->next.caplen > sizeof(frame)) {
|
||||
fprintf(stderr, "error: huge frame (size %u)\n", (unsigned int) len);
|
||||
return EX_SOFTWARE;
|
||||
}
|
||||
|
||||
/* Read it */
|
||||
/*
|
||||
* Read it
|
||||
*/
|
||||
len = fread(frame, 1, cur->next.caplen, cur->p.f);
|
||||
if (len < cur->next.caplen) {
|
||||
/* Short read */
|
||||
/*
|
||||
* Short read
|
||||
*/
|
||||
cur->next.caplen = len;
|
||||
pcap_close(&cur->p);
|
||||
cur->active = 0;
|
||||
}
|
||||
|
||||
/* Write header + frame */
|
||||
/*
|
||||
* Write header + frame
|
||||
*/
|
||||
if (len) {
|
||||
if (1 != fwrite(&cur->next, sizeof(cur->next), 1, stdout)) {
|
||||
perror("error");
|
||||
|
|
19
puniq.c
19
puniq.c
|
@ -42,15 +42,20 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
while (1) {
|
||||
if (-1 == pcap_read_pkthdr(&p, &hdr[cur])) break;
|
||||
if (1 != fread(frame[cur], hdr[cur].caplen, 1, p.f)) break;
|
||||
if (-1 == pcap_read_pkthdr(&p, &hdr[cur]))
|
||||
break;
|
||||
if (1 != fread(frame[cur], hdr[cur].caplen, 1, p.f))
|
||||
break;
|
||||
|
||||
if ((0 == memcmp(&hdr[0], &hdr[1], sizeof(hdr[0]))) &&
|
||||
(0 == memcmp(frame[0], frame[1], hdr[cur].caplen))) {
|
||||
/* Skip this duplicate */
|
||||
if ((0 == memcmp(&hdr[0], &hdr[1], sizeof(hdr[0]))) && (0 == memcmp(frame[0], frame[1], hdr[cur].caplen))) {
|
||||
/*
|
||||
* Skip this duplicate
|
||||
*/
|
||||
} else {
|
||||
if (-1 == pcap_write_pkthdr(&out, &hdr[cur])) break;
|
||||
if (1 != fwrite(frame[cur], hdr[cur].caplen, 1, out.f)) break;
|
||||
if (-1 == pcap_write_pkthdr(&out, &hdr[cur]))
|
||||
break;
|
||||
if (1 != fwrite(frame[cur], hdr[cur].caplen, 1, out.f))
|
||||
break;
|
||||
}
|
||||
cur = (1 - cur);
|
||||
}
|
||||
|
|
21
stream.c
21
stream.c
|
@ -56,9 +56,7 @@ read_uint16be(struct stream *s)
|
|||
if (!sskip(s, 2)) {
|
||||
return 0;
|
||||
}
|
||||
return (
|
||||
(d[0] << 8) |
|
||||
(d[1] << 0));
|
||||
return ((d[0] << 8) | (d[1] << 0));
|
||||
}
|
||||
|
||||
uint16_t
|
||||
|
@ -69,9 +67,7 @@ read_uint16le(struct stream *s)
|
|||
if (!sskip(s, 2)) {
|
||||
return 0;
|
||||
}
|
||||
return (
|
||||
(d[0] << 0) |
|
||||
(d[1] << 8));
|
||||
return ((d[0] << 0) | (d[1] << 8));
|
||||
}
|
||||
|
||||
uint32_t
|
||||
|
@ -82,11 +78,7 @@ read_uint32be(struct stream *s)
|
|||
if (!sskip(s, 4)) {
|
||||
return 0;
|
||||
}
|
||||
return (
|
||||
(d[0] << 24) |
|
||||
(d[1] << 16) |
|
||||
(d[2] << 8) |
|
||||
(d[3] << 0));
|
||||
return ((d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3] << 0));
|
||||
}
|
||||
|
||||
uint32_t
|
||||
|
@ -97,10 +89,5 @@ read_uint32le(struct stream *s)
|
|||
if (!sskip(s, 4)) {
|
||||
return 0;
|
||||
}
|
||||
return (
|
||||
(d[0] << 0) |
|
||||
(d[1] << 8) |
|
||||
(d[2] << 16) |
|
||||
(d[3] << 24));
|
||||
return ((d[0] << 0) | (d[1] << 8) | (d[2] << 16) | (d[3] << 24));
|
||||
}
|
||||
|
||||
|
|
7
unhex.c
7
unhex.c
|
@ -1,7 +1,6 @@
|
|||
/* Hex Decoder -- 2012 Zephyr <zephyr@dirtbags.net>
|
||||
*
|
||||
* This file is in the public domain. I make no promises
|
||||
* about the functionality of this program.
|
||||
/*
|
||||
* Hex Decoder -- 2012 Zephyr <zephyr@dirtbags.net> This file is in the public domain. I make no promises about the functionality
|
||||
* of this program.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
7
xor.c
7
xor.c
|
@ -1,7 +1,6 @@
|
|||
/* xor filter -- 2012 Zephyr <zephyr@dirtbags.net>
|
||||
*
|
||||
* This file is in the public domain. I make no promises
|
||||
* about the functionality of this program.
|
||||
/*
|
||||
* xor filter -- 2012 Zephyr <zephyr@dirtbags.net> This file is in the public domain. I make no promises about the functionality
|
||||
* of this program.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
Loading…
Reference in New Issue