]>
The Tcpdump Group git mirrors - tcpdump/blob - util.c
2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * txtproto_print() derived from original code by Hannes Gredler
24 * (hannes@juniper.net):
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that: (1) source code
28 * distributions retain the above copyright notice and this paragraph
29 * in its entirety, and (2) distributions including binary code include
30 * the above copyright notice and this paragraph in its entirety in
31 * the documentation or other materials provided with the distribution.
32 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
33 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
34 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35 * FOR A PARTICULAR PURPOSE.
42 #include <netdissect-stdinc.h>
54 #include "interface.h"
58 error(const char *fmt
, ...)
62 (void)fprintf(stderr
, "%s: ", program_name
);
64 (void)vfprintf(stderr
, fmt
, ap
);
69 (void)fputc('\n', stderr
);
77 warning(const char *fmt
, ...)
81 (void)fprintf(stderr
, "%s: WARNING: ", program_name
);
83 (void)vfprintf(stderr
, fmt
, ap
);
88 (void)fputc('\n', stderr
);
93 * Copy arg vector into a new buffer, concatenating arguments with spaces.
96 copy_argv(register char **argv
)
99 register u_int len
= 0;
108 len
+= strlen(*p
++) + 1;
110 buf
= (char *)malloc(len
);
112 error("copy_argv: malloc");
116 while ((src
= *p
++) != NULL
) {
117 while ((*dst
++ = *src
++) != '\0')
127 * On Windows, we need to open the file in binary mode, so that
128 * we get all the bytes specified by the size we get from "fstat()".
129 * On UNIX, that's not necessary. O_BINARY is defined on Windows;
130 * we define it as 0 if it's not defined, so it does nothing.
137 read_infile(char *fname
)
139 register int i
, fd
, cc
;
143 fd
= open(fname
, O_RDONLY
|O_BINARY
);
145 error("can't open %s: %s", fname
, pcap_strerror(errno
));
147 if (fstat(fd
, &buf
) < 0)
148 error("can't stat %s: %s", fname
, pcap_strerror(errno
));
150 cp
= malloc((u_int
)buf
.st_size
+ 1);
152 error("malloc(%d) for %s: %s", (u_int
)buf
.st_size
+ 1,
153 fname
, pcap_strerror(errno
));
154 cc
= read(fd
, cp
, (u_int
)buf
.st_size
);
156 error("read %s: %s", fname
, pcap_strerror(errno
));
157 if (cc
!= buf
.st_size
)
158 error("short read %s (%d != %d)", fname
, cc
, (int)buf
.st_size
);
161 /* replace "# comment" with spaces */
162 for (i
= 0; i
< cc
; i
++) {
164 while (i
< cc
&& cp
[i
] != '\n')