mirror of https://github.com/dirtbags/fluffy.git
replace skip with more general drop
This commit is contained in:
parent
bc27cf7b32
commit
c4f4a28867
16
README.md
16
README.md
|
@ -75,17 +75,21 @@ The "-x" option treats values as hex.
|
|||
cbcbcb
|
||||
|
||||
|
||||
### skip: discard initial octets
|
||||
### drop: discard octets
|
||||
|
||||
Throws away some initial octets from stdin,
|
||||
Throws away some octets from stdin,
|
||||
and sends the rest to stdout.
|
||||
|
||||
You could use `dd` for the same purpose.
|
||||
|
||||
$ echo abcdefgh | dd skip=5 bs=1 status=none
|
||||
fgh
|
||||
$ echo abcdefgh | skip 5
|
||||
fgh
|
||||
$ echo 01234567 | drop 0 3
|
||||
34567
|
||||
$ echo 01234567 | drop 4 7
|
||||
01237
|
||||
$ echo 01234567 | drop 4 6
|
||||
012367
|
||||
$ echo 01234567 | drop 3 9999
|
||||
012
|
||||
|
||||
|
||||
### pcat: print text representation of pcap file
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* drop octets -- 2017 Neale Pickett <zephyr@dirtbags.net>
|
||||
*
|
||||
* This file is in the public domain. I make no promises about the functionality
|
||||
* of this program.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
unsigned long int start;
|
||||
unsigned long int end;
|
||||
unsigned long int pos;
|
||||
|
||||
if (3 == argc) {
|
||||
start = strtoul(argv[1], NULL, 0);
|
||||
end = strtoul(argv[2], NULL, 0);
|
||||
} else {
|
||||
fprintf(stderr, "Usage: %s start end\n", argv[0]);
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "Drops octets from input\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (pos = 0; ; pos += 1) {
|
||||
int c = getchar();
|
||||
|
||||
if (EOF == c) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((start <= pos) && (pos < end)) {
|
||||
/* drop */
|
||||
} else {
|
||||
putchar(c);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
42
skip.c
42
skip.c
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* skip octets -- 2017 Neale Pickett <zephyr@dirtbags.net>
|
||||
*
|
||||
* This file is in the public domain. I make no promises about the functionality
|
||||
* of this program.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
long int count;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s count\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
count = strtol(argv[1], NULL, 0);
|
||||
/* Throw away count octets */
|
||||
for (; count > 0; count -= 1) {
|
||||
int c = getchar();
|
||||
|
||||
if (EOF == c) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Spit out the rest */
|
||||
while (1) {
|
||||
int c = getchar();
|
||||
|
||||
if (EOF == c) {
|
||||
break;
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue