-
Notifications
You must be signed in to change notification settings - Fork 4
/
wts.c
53 lines (43 loc) · 1.13 KB
/
wts.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Copyright 2023 Google LLC
*
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file or at
* https://developers.google.com/open-source/licenses/bsd */
#include "shared.h"
#include "wts.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Wts wts;
static void logescaped(FILE *f, const void *buf_, size_t sz)
{
const unsigned char *buf = buf_;
while (sz--) {
if (*buf >= ' ' && *buf != 0x7f)
fputc(*buf, f);
else
fprintf(f, "\\%03o", *buf);
buf++;
}
fputc('\n', f);
}
void dump_wts(void)
{
char *dumpfn;
FILE *f;
static unsigned dimp;
xasprintf(&dumpfn, "/tmp/werm.dump.%lld.%u",
(long long)getpid(), dimp++);
f = fopen(dumpfn, "w");
if (!f) perror("fopen for dump file");
free(dumpfn);
if (!f) return;
fprintf(f, "escp: %d (%c)\n", wts.escp, wts.escp);
fprintf(f, "clnttl: %u\n", wts.clnttl);
fprintf(f, "windim: %u:%u\n", wts.swrow, wts.swcol);
fprintf(f, "ttl: (sz=%u)\n", ttl_len());
fprintf(f, "allowtmstate: %u\n", wts.allowtmstate);
logescaped(f, wts.ttl, ttl_len());
fclose(f);
}
unsigned ttl_len(void) { return strnlen(wts.ttl, sizeof wts.ttl); }