#include "packet.h" #include #include #include int main(void) { setvbuf(stdout, NULL, _IONBF, 0); union packet packet; for (size_t psz; (psz = fread(packet.buf, 1, sizeof(packet.hdr), stdin)) > 0;) { if (!packet_verify(&packet)) errx(EXIT_FAILURE, "invalid packet"); psz += fread(packet.buf + sizeof(packet.hdr), 1, packet.hdr.size - sizeof(packet.hdr), stdin); if (psz != packet.hdr.size) errx(EXIT_FAILURE, "packet size doesn't match, got %zu, expected %u", psz, packet.hdr.size); packet_crypt(&packet); fwrite(packet.buf, 1, packet.hdr.size, stdout); } return EXIT_SUCCESS; }