blob: 0f9362941dd9bf03150e49a77b35dca4d038c8df [file] [log] [blame]
Holger Hans Peter Freyther65d67dc2009-12-23 12:52:30 +01001/* Routines for parsing an ipacces SDP firmware file */
2
3/* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <fcntl.h>
25#include <unistd.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29
30
31
32static void analyze_file(int fd)
33{
34 char buf[4096];
35 int rc;
36
37 rc = read(fd, buf, 4);
38 if (rc <= 0) {
39 fprintf(stderr, "Not enough space for the header.\n");
40 return;
41 }
42
43 if (strcmp(buf, " SDP") != 0) {
44 fprintf(stderr, "Wrong magic number at the beginning of the file.\n");
45 return;
46 }
47
48 printf("Printing header information:\n");
49}
50
51int main(int argc, char** argv)
52{
53 int i, fd;
54
55 for (i = 1; i < argc; ++i) {
56 printf("Opening possible firmware '%s'\n", argv[i]);
57 fd = open(argv[i], O_RDONLY);
58 if (!fd) {
59 perror("nada");
60 continue;
61 }
62
63 analyze_file(fd);
64 }
65
66 return EXIT_SUCCESS;
67}