From 43b4bb1474e092a0b87f3b23b5246900c94e1d4e Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Tue, 4 Jun 2013 23:19:01 +0200 Subject: Use dist_ prefix in Makefile.am rather than EXTRA_DIST where possible. Signed-off-by: Ralf Baechle --- ax25/axgetput/Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/Makefile.am b/ax25/axgetput/Makefile.am index d3f8f8f..8eae7cc 100644 --- a/ax25/axgetput/Makefile.am +++ b/ax25/axgetput/Makefile.am @@ -8,8 +8,7 @@ sbin_PROGRAMS = bin_PROGRAMS = axgetput -man_MANS = axgetput.1 -EXTRA_DIST = $(man_MANS) +dist_man_MANS = axgetput.1 axgetput_SOURCES = axgetput.c axgetput.h util.h proto_bin.h util.c proto_bin.c includes.h -- cgit v1.2.3 From 0b4425760be1f92a1f25daeb5d3dc91814a98622 Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Wed, 5 Jun 2013 00:55:50 +0200 Subject: Nuke trailing blank lines. Signed-off-by: Ralf Baechle --- ax25/axgetput/axgetput.c | 1 - ax25/axgetput/util.c | 1 - 2 files changed, 2 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/axgetput.c b/ax25/axgetput/axgetput.c index d3d3f53..9513a8f 100644 --- a/ax25/axgetput/axgetput.c +++ b/ax25/axgetput/axgetput.c @@ -390,4 +390,3 @@ skiped_crc_only_tag_1: return 0; } - diff --git a/ax25/axgetput/util.c b/ax25/axgetput/util.c index 4aff6a0..5ce6ffb 100644 --- a/ax25/axgetput/util.c +++ b/ax25/axgetput/util.c @@ -205,4 +205,3 @@ void date_unix2dos(int unix_date,unsigned short *time, unsigned short *date) } *date = nl_day-day_n[month-1]+1+(month << 5)+(year << 9); } - -- cgit v1.2.3 From 1245fbd2a8d60bab7b16b8a1d3c0122fee72f53f Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Wed, 5 Jun 2013 00:57:38 +0200 Subject: Nuke trailing whitespace. Signed-off-by: Ralf Baechle --- ax25/axgetput/Makefile.am | 10 +++++----- ax25/axgetput/axgetput.c | 2 +- ax25/axgetput/proto_bin.c | 6 +++--- ax25/axgetput/util.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/Makefile.am b/ax25/axgetput/Makefile.am index 8eae7cc..de92dda 100644 --- a/ax25/axgetput/Makefile.am +++ b/ax25/axgetput/Makefile.am @@ -1,19 +1,19 @@ installconf: -etcfiles = -varfiles = +etcfiles = +varfiles = -sbin_PROGRAMS = +sbin_PROGRAMS = bin_PROGRAMS = axgetput -dist_man_MANS = axgetput.1 +dist_man_MANS = axgetput.1 axgetput_SOURCES = axgetput.c axgetput.h util.h proto_bin.h util.c proto_bin.c includes.h install-exec-hook: (cd $(DESTDIR)$(bindir) && ln -sf axgetput bget && ln -sf axgetput bput) -install-data-hook: +install-data-hook: (cd $(DESTDIR)$(mandir)/man1 && ln -sf axgetput.1 bget.1 && ln -sf axgetput.1 bput.1) diff --git a/ax25/axgetput/axgetput.c b/ax25/axgetput/axgetput.c index 9513a8f..1696dbf 100644 --- a/ax25/axgetput/axgetput.c +++ b/ax25/axgetput/axgetput.c @@ -223,7 +223,7 @@ int main(int argc, char *argv[]) fdin_is_pipe = (isatty(fdin) ? 0 : 1); fdout_is_pipe = (isatty(fdout) ? 0 : 1); - if (fdin_is_pipe && fdout_is_pipe) { + if (fdin_is_pipe && fdout_is_pipe) { fprintf(stderr, "error: cannot work in between two pipes\n"); exit(1); } diff --git a/ax25/axgetput/proto_bin.c b/ax25/axgetput/proto_bin.c index 004ca5e..d02249b 100644 --- a/ax25/axgetput/proto_bin.c +++ b/ax25/axgetput/proto_bin.c @@ -21,7 +21,7 @@ static int crcbit[8] = { static int init_crc(void) { int i,j; - + for (i = 0; i < 256; i++) { crctab[i] = 0; for (j = 0; j < 8; j++) { @@ -192,7 +192,7 @@ int bput(void) goto abort; } if (!len) { - save_close(fddata); + save_close(fddata); if (!term_line) { sprintf(err_msg, "error: unexpected end of file during read: %s\n", strerror(errno)); return 1; @@ -331,7 +331,7 @@ int bget(void) { file_time = statbuf.st_mtime; else file_time = time(0); - + /* compute crc */ while ((len = read(fddata, buf, BLOCKSIZ)) > 0) { int i; diff --git a/ax25/axgetput/util.c b/ax25/axgetput/util.c index 5ce6ffb..98caeeb 100644 --- a/ax25/axgetput/util.c +++ b/ax25/axgetput/util.c @@ -79,7 +79,7 @@ int my_read(int fd, char *s, int len_max, int *eof, char *p_break) return len_got; } - + /*---------------------------------------------------------------------------*/ int secure_write(int fd, char *s, int len_write) { -- cgit v1.2.3 From 5feb3d651dbd1b096a26963bd1dffcfe0a5f9eea Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Wed, 5 Jun 2013 01:42:05 +0200 Subject: Remove useless initializations to 0 or NULL. They only inflate the .data section of the binary. Initializations to FALSE are still left to do. Signed-off-by: Ralf Baechle --- ax25/axgetput/axgetput.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/axgetput.c b/ax25/axgetput/axgetput.c index 1696dbf..c2f4d25 100644 --- a/ax25/axgetput/axgetput.c +++ b/ax25/axgetput/axgetput.c @@ -24,25 +24,25 @@ #include "util.h" #include "proto_bin.h" -int fdin = 0; +int fdin; int fdout = 1; int fderr = 2; -int fdout_is_pipe = 0; -int fdin_is_pipe = 0; +int fdout_is_pipe; +int fdin_is_pipe; -int is_stream = 0; -int mode = 0; -int do_crc_only = 0; +int is_stream; +int mode; +int do_crc_only; char c_eol = '\n'; unsigned int BLOCKSIZ = BLOCKSIZ_DEFAULT; -char *send_on_signal = 0; +char *send_on_signal; static struct termios prev_termios; -static int prev_termios_stored = 0; -static mode_t mode_tty = 0; +static int prev_termios_stored; +static mode_t mode_tty; #ifndef MYNAME #define MYNAME "axgetput" @@ -98,7 +98,7 @@ static void eol_convention(int state_should) /* need patched axspawn */ #define BIN_ON "//BIN ON\r" #define BIN_OFF "//BIN OFF\r" - static int state_is = 0; + static int state_is; /* already in correct state? */ if ((state_is && state_should) || (!state_is && !state_should)) -- cgit v1.2.3 From 90f6ab2eceada8987fc6e5017ae415eade165c00 Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Wed, 5 Jun 2013 01:47:40 +0200 Subject: Use tabs for indentation, not spaces. Signed-off-by: Ralf Baechle --- ax25/axgetput/axgetput.c | 12 ++++---- ax25/axgetput/proto_bin.c | 72 +++++++++++++++++++++++------------------------ ax25/axgetput/util.c | 66 +++++++++++++++++++++---------------------- 3 files changed, 75 insertions(+), 75 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/axgetput.c b/ax25/axgetput/axgetput.c index c2f4d25..595215c 100644 --- a/ax25/axgetput/axgetput.c +++ b/ax25/axgetput/axgetput.c @@ -264,17 +264,17 @@ int main(int argc, char *argv[]) #define get_filename(f) { \ if (!strcmp(f, "-")) { \ if (mode % 2) \ - fdin_is_pipe = 1; \ - else \ - fdout_is_pipe = 1; \ + fdin_is_pipe = 1; \ + else \ + fdout_is_pipe = 1; \ } else { \ - strncpy(filename, f, sizeof(filename)-1); \ - filename[sizeof(filename)-1] = 0; \ + strncpy(filename, f, sizeof(filename)-1); \ + filename[sizeof(filename)-1] = 0; \ if (mode % 2) { \ if (fdin_is_pipe) \ fdin_is_pipe = 0; \ } else { \ - if (fdout_is_pipe) \ + if (fdout_is_pipe) \ fdout_is_pipe = 0; \ } \ } \ diff --git a/ax25/axgetput/proto_bin.c b/ax25/axgetput/proto_bin.c index d02249b..9be7a58 100644 --- a/ax25/axgetput/proto_bin.c +++ b/ax25/axgetput/proto_bin.c @@ -26,7 +26,7 @@ static int init_crc(void) crctab[i] = 0; for (j = 0; j < 8; j++) { if ((bittab[j] & i) != 0) { - crctab[i] = crctab[i] ^ crcbit[j]; + crctab[i] = crctab[i] ^ crcbit[j]; } } } @@ -113,7 +113,7 @@ int bput(void) return 1; } if (buf[len-1] == '\r' && len > 5 && !memcmp(buf, "#BIN#", 5)) { - break; + break; } if (len == sizeof(buf)) { sprintf(err_msg, "line to long\n"); @@ -139,12 +139,12 @@ int bput(void) break; default: if (*p == '|') { - msg_crc = (unsigned int ) atoi(p+1); + msg_crc = (unsigned int ) atoi(p+1); } else if (*p == '$') { - file_time = parse_sfbin_date_to_unix(p+1); + file_time = parse_sfbin_date_to_unix(p+1); } else { - strncpy(filename_given, p, sizeof(filename_given)-1); - filename_given[sizeof(filename_given)-1] = 0; + strncpy(filename_given, p, sizeof(filename_given)-1); + filename_given[sizeof(filename_given)-1] = 0; } } } @@ -159,8 +159,8 @@ int bput(void) if (!stat(filename, &statbuf)) { /* file exist */ if (unlink(filename)) { - sprintf(err_msg, "error: cannot unlink %s (%s)\n", filename, strerror(errno)); - goto abort; + sprintf(err_msg, "error: cannot unlink %s (%s)\n", filename, strerror(errno)); + goto abort; } } if ((fddata = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0640)) < 0) { @@ -194,7 +194,7 @@ int bput(void) if (!len) { save_close(fddata); if (!term_line) { - sprintf(err_msg, "error: unexpected end of file during read: %s\n", strerror(errno)); + sprintf(err_msg, "error: unexpected end of file during read: %s\n", strerror(errno)); return 1; } return 0; @@ -203,14 +203,14 @@ int bput(void) if (msg_crc) { int i; for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], 1, crc); + crc = do_crc((int ) buf[i], 1, crc); } if (buf[len-1] == '\r') { if (last_line_had_CR) { if (IS_BIN_ABORT(buf, len)) { /* "\r#ABORT#\r" was sent */ - if (!fdout_is_pipe) { + if (!fdout_is_pipe) { close(fddata); /* clean up */ unlink(filename); @@ -218,8 +218,8 @@ int bput(void) return 1; } if (term_line && len == len_termline && !memcmp(buf, term_line, len_termline)) { - /* sucessfully read until termination string */ - break; + /* sucessfully read until termination string */ + break; } } last_line_had_CR = 1; @@ -241,7 +241,7 @@ int bput(void) if (is_eof) { if (!term_line && len_read_left) { save_close(fddata); - goto abort; + goto abort; } break; } @@ -304,13 +304,13 @@ int bget(void) { } #define store_line(s, len) { \ - if (!(sl = (struct strlist *) malloc(sizeof(struct strlist *) + sizeof(size_t) + len))) \ + if (!(sl = (struct strlist *) malloc(sizeof(struct strlist *) + sizeof(size_t) + len))) \ return 1; \ sl->next = 0; \ sl->len = len; \ memcpy(sl->data, s, len); \ if (!stored_file) { \ - stored_file = sl; \ + stored_file = sl; \ } else { \ sl_tail->next = sl; \ } \ @@ -336,7 +336,7 @@ int bget(void) { while ((len = read(fddata, buf, BLOCKSIZ)) > 0) { int i; for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], 1, crc); + crc = do_crc((int ) buf[i], 1, crc); file_size += len; } if (len < 0) { @@ -356,17 +356,17 @@ int bget(void) { if (!is_stream || do_crc_only) { sprintf(err_msg, "error: not enough memory\n"); while ((len = read(fddata, buf, sizeof(buf))) > 0) { - int i; - for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], 1, crc); - file_size += len; + int i; + for (i = 0; i < len; i++) + crc = do_crc((int ) buf[i], 1, crc); + file_size += len; if (!do_crc_only) store_line(buf, len); } if (len < 0) { - sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); - close(fddata); - return 1; + sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); + close(fddata); + return 1; } *err_msg = 0; sprintf(buf, "\r#BIN#%ld#|%d#$%s#%s\r", file_size, crc, unix_to_sfbin_date_string(file_time), get_fixed_filename(filename, file_size, crc, 1)); @@ -396,7 +396,7 @@ int bget(void) { /* wait for answer */ for (;;) { - /* + /* * make sure we do not read from a pipe. fdout is also * assigned to the tty */ @@ -442,26 +442,26 @@ int bget(void) { FD_SET(fdin, &readfds); if (select(fdin+1, &readfds, 0, 0, &timeout) && FD_ISSET(fdin, &readfds)) { if ((len = read(fdin, buf, sizeof(buf))) < 0) { - sprintf(err_msg, "read from tty failed (%s)\n", strerror(errno)); - save_close(fddata); - goto abort; + sprintf(err_msg, "read from tty failed (%s)\n", strerror(errno)); + save_close(fddata); + goto abort; } if (IS_BIN_ABORT(buf, len)) { - sprintf(err_msg, "Aborted by user request\n"); - save_close(fddata); - return 1; + sprintf(err_msg, "Aborted by user request\n"); + save_close(fddata); + return 1; } } /* read data */ if (!fdin_is_pipe || is_stream) { p_buf = buf; if ((len = my_read(fddata, buf, ((len_remains > BLOCKSIZ || is_stream) ? BLOCKSIZ : len_remains), &is_eof, 0)) < 1) { - save_close(fddata); - if (len < 0) { - sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); + save_close(fddata); + if (len < 0) { + sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); goto abort; - } - break; + } + break; } len_remains -= len; } else { diff --git a/ax25/axgetput/util.c b/ax25/axgetput/util.c index 98caeeb..f20937f 100644 --- a/ax25/axgetput/util.c +++ b/ax25/axgetput/util.c @@ -54,8 +54,8 @@ int my_read(int fd, char *s, int len_max, int *eof, char *p_break) if ((len = read(fd, s_curr, (p_break ? 1 : len_max))) < 1) { if (len == -1 && errno == EAGAIN) { - sleep(10); - continue; + sleep(10); + continue; } *eof = 1; /* @@ -89,8 +89,8 @@ int secure_write(int fd, char *s, int len_write) { int len; if ((len = write(fd, s, len_write_left_curr)) < 0) { if (len == -1 && errno == EAGAIN) { - sleep(10); - continue; + sleep(10); + continue; } return -1; } @@ -162,22 +162,22 @@ char *get_fixed_filename(char *line, long size, unsigned int msg_crc, int genera /* Linear day numbers of the respective 1sts in non-leap years. */ static int day_n[] = { 0,31,59,90,120,151,181,212,243,273,304,334,0,0,0,0 }; - /* JanFebMarApr May Jun Jul Aug Sep Oct Nov Dec */ + /* JanFebMarApr May Jun Jul Aug Sep Oct Nov Dec */ /*---------------------------------------------------------------------------*/ long date_dos2unix(unsigned short time,unsigned short date) { - int month,year; - long secs; - - month = ((date >> 5) & 15)-1; - year = date >> 9; - secs = (time & 31)*2+60*((time >> 5) & 63)+(time >> 11)*3600+86400* - ((date & 31)-1+day_n[month]+(year/4)+year*365-((year & 3) == 0 && - month < 2 ? 1 : 0)+3653); - /* days since 1.1.70 plus 80's leap day */ - return secs; + int month,year; + long secs; + + month = ((date >> 5) & 15)-1; + year = date >> 9; + secs = (time & 31)*2+60*((time >> 5) & 63)+(time >> 11)*3600+86400* + ((date & 31)-1+day_n[month]+(year/4)+year*365-((year & 3) == 0 && + month < 2 ? 1 : 0)+3653); + /* days since 1.1.70 plus 80's leap day */ + return secs; } /*---------------------------------------------------------------------------*/ @@ -186,22 +186,22 @@ long date_dos2unix(unsigned short time,unsigned short date) void date_unix2dos(int unix_date,unsigned short *time, unsigned short *date) { - int day,year,nl_day,month; - - *time = (unix_date % 60)/2+(((unix_date/60) % 60) << 5)+ - (((unix_date/3600) % 24) << 11); - day = unix_date/86400-3652; - year = day/365; - if ((year+3)/4+365*year > day) year--; - day -= (year+3)/4+365*year; - if (day == 59 && !(year & 3)) { - nl_day = day; - month = 2; - } - else { - nl_day = (year & 3) || day <= 59 ? day : day-1; - for (month = 0; month < 12; month++) - if (day_n[month] > nl_day) break; - } - *date = nl_day-day_n[month-1]+1+(month << 5)+(year << 9); + int day,year,nl_day,month; + + *time = (unix_date % 60)/2+(((unix_date/60) % 60) << 5)+ + (((unix_date/3600) % 24) << 11); + day = unix_date/86400-3652; + year = day/365; + if ((year+3)/4+365*year > day) year--; + day -= (year+3)/4+365*year; + if (day == 59 && !(year & 3)) { + nl_day = day; + month = 2; + } + else { + nl_day = (year & 3) || day <= 59 ? day : day-1; + for (month = 0; month < 12; month++) + if (day_n[month] > nl_day) break; + } + *date = nl_day-day_n[month-1]+1+(month << 5)+(year << 9); } -- cgit v1.2.3 From 1c830798fe54268cc0f9585b5940bea47fa8eb8a Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Wed, 5 Jun 2013 02:20:15 +0200 Subject: Remove parenthesis around arguments of return statements. Signed-off-by: Ralf Baechle --- ax25/axgetput/proto_bin.c | 2 +- ax25/axgetput/util.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/proto_bin.c b/ax25/axgetput/proto_bin.c index 9be7a58..b3e3420 100644 --- a/ax25/axgetput/proto_bin.c +++ b/ax25/axgetput/proto_bin.c @@ -38,7 +38,7 @@ static int init_crc(void) static int do_crc(char b, int n, unsigned int crc) { crc = (crctab[(crc >> 8)] ^ ((crc << 8) | (b & 0xff))) & 0xffff; - return (crc); + return crc; } /*---------------------------------------------------------------------------*/ diff --git a/ax25/axgetput/util.c b/ax25/axgetput/util.c index f20937f..5501035 100644 --- a/ax25/axgetput/util.c +++ b/ax25/axgetput/util.c @@ -62,7 +62,7 @@ int my_read(int fd, char *s, int len_max, int *eof, char *p_break) * len = 0: normal eof. if we're looking for a string, return -1 since * we have'nt found */ - return (len == 0 && p_break ? -1 : (len_got ? len_got : len)); + return len == 0 && p_break ? -1 : (len_got ? len_got : len); } len_got += len; -- cgit v1.2.3 From 4eb951133d9d301184ebd7b675598e11973b6ab8 Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Wed, 5 Jun 2013 02:34:19 +0200 Subject: Always have a space between if, for, switch, while and the following `('. Signed-off-by: Ralf Baechle --- ax25/axgetput/axgetput.c | 2 +- ax25/axgetput/proto_bin.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/axgetput.c b/ax25/axgetput/axgetput.c index 595215c..dc077c5 100644 --- a/ax25/axgetput/axgetput.c +++ b/ax25/axgetput/axgetput.c @@ -281,7 +281,7 @@ int main(int argc, char *argv[]) } while ((c = getopt(argc, argv, (mode % 2) ? "ivh?" : "b:isvh?")) != EOF) { - switch(c) { + switch (c) { case 'b': if (((BLOCKSIZ = (unsigned ) atoi(optarg)) < BLOCKSIZ_MIN) || BLOCKSIZ > BLOCKSIZ_MAX) { fprintf(stderr, "error: invalid blocksize: %d\n", BLOCKSIZ); diff --git a/ax25/axgetput/proto_bin.c b/ax25/axgetput/proto_bin.c index b3e3420..78a6ccc 100644 --- a/ax25/axgetput/proto_bin.c +++ b/ax25/axgetput/proto_bin.c @@ -129,7 +129,7 @@ int bput(void) p_buf = buf; for (i = 0; (p = strsep(&p_buf, "#")); i++) { - switch(i) { + switch (i) { case 0: case 1: break; -- cgit v1.2.3 From f76e0b330f0be28f9f3af3073904ede3a34d48f5 Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Wed, 5 Jun 2013 15:34:56 +0200 Subject: Reformat consistently. Strictly whitespace changes only. Indentation by tabs only. Move case labels in switches are on the same level as the switch keyword. Signed-off-by: Ralf Baechle --- ax25/axgetput/axgetput.c | 536 ++++++++++++++--------------- ax25/axgetput/proto_bin.c | 838 +++++++++++++++++++++++----------------------- 2 files changed, 687 insertions(+), 687 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/axgetput.c b/ax25/axgetput/axgetput.c index dc077c5..de21bc5 100644 --- a/ax25/axgetput/axgetput.c +++ b/ax25/axgetput/axgetput.c @@ -52,92 +52,92 @@ static mode_t mode_tty; static void set_tty_flags(void) { - struct termios termios; - struct stat statbuf; - - if (fdin_is_pipe) - return; - /* mesg no */ - if (!fstat(fdin, &statbuf)) { - /* save old mode */ - mode_tty = statbuf.st_mode; - fchmod(fdin, 0600); - } - /* make tty 8bit clean */ - if (tcgetattr(fdin, &prev_termios) != -1) - prev_termios_stored = 1; - memset((char *) &termios, 0, sizeof(termios)); - termios.c_iflag = IGNBRK | IGNPAR; - termios.c_oflag = 0; - termios.c_cflag = CBAUD | CS8 | CREAD | CLOCAL; - termios.c_cflag = ~(CSTOPB|PARENB|PARODD|HUPCL); - termios.c_lflag = 0; - termios.c_cc[VMIN] = 1; - termios.c_cc[VTIME] = 0; - termios.c_cc[VSTART] = -1; - termios.c_cc[VSTOP] = -1; - tcsetattr(fdin, TCSANOW, &termios); + struct termios termios; + struct stat statbuf; + + if (fdin_is_pipe) + return; + /* mesg no */ + if (!fstat(fdin, &statbuf)) { + /* save old mode */ + mode_tty = statbuf.st_mode; + fchmod(fdin, 0600); + } + /* make tty 8bit clean */ + if (tcgetattr(fdin, &prev_termios) != -1) + prev_termios_stored = 1; + memset((char *) &termios, 0, sizeof(termios)); + termios.c_iflag = IGNBRK | IGNPAR; + termios.c_oflag = 0; + termios.c_cflag = CBAUD | CS8 | CREAD | CLOCAL; + termios.c_cflag = ~(CSTOPB|PARENB|PARODD|HUPCL); + termios.c_lflag = 0; + termios.c_cc[VMIN] = 1; + termios.c_cc[VTIME] = 0; + termios.c_cc[VSTART] = -1; + termios.c_cc[VSTOP] = -1; + tcsetattr(fdin, TCSANOW, &termios); } /*---------------------------------------------------------------------------*/ static void restore_tty_flags(void) { - if (fdin_is_pipe) - return; - if (prev_termios_stored) - tcsetattr(fdin, TCSANOW, &prev_termios); - if (mode_tty) - fchmod(fdin, mode_tty); + if (fdin_is_pipe) + return; + if (prev_termios_stored) + tcsetattr(fdin, TCSANOW, &prev_termios); + if (mode_tty) + fchmod(fdin, mode_tty); } /*---------------------------------------------------------------------------*/ static void eol_convention(int state_should) { - /* need patched axspawn */ + /* need patched axspawn */ #define BIN_ON "//BIN ON\r" #define BIN_OFF "//BIN OFF\r" - static int state_is; + static int state_is; - /* already in correct state? */ - if ((state_is && state_should) || (!state_is && !state_should)) - return; + /* already in correct state? */ + if ((state_is && state_should) || (!state_is && !state_should)) + return; - sleep(1); + sleep(1); - if (state_should) { - write(fderr, BIN_ON, strlen(BIN_ON)); - c_eol = '\r'; - } else { - write(fderr, BIN_OFF, strlen(BIN_OFF)); - c_eol = '\n'; - } - state_is = state_should; + if (state_should) { + write(fderr, BIN_ON, strlen(BIN_ON)); + c_eol = '\r'; + } else { + write(fderr, BIN_OFF, strlen(BIN_OFF)); + c_eol = '\n'; + } + state_is = state_should; - sleep(1); + sleep(1); } /*---------------------------------------------------------------------------*/ static void restore_defaults(void) { - eol_convention(0); - restore_tty_flags(); + eol_convention(0); + restore_tty_flags(); } /*---------------------------------------------------------------------------*/ static void signal_handler(int sig) { - if (send_on_signal) - secure_write(fdout, send_on_signal, strlen(send_on_signal)); - restore_defaults(); - if (*err_msg) { - fputs(err_msg, stderr); - } - fprintf(stderr, "Died by signal %d.\n", sig); - exit(sig); + if (send_on_signal) + secure_write(fdout, send_on_signal, strlen(send_on_signal)); + restore_defaults(); + if (*err_msg) { + fputs(err_msg, stderr); + } + fprintf(stderr, "Died by signal %d.\n", sig); + exit(sig); } /*---------------------------------------------------------------------------*/ @@ -153,40 +153,40 @@ void do_version(void) /*---------------------------------------------------------------------------*/ static void usage(int all) { - fprintf(stderr, "usage: %s ", myname); - if (mode % 2) { - fprintf(stderr, "[-ivh] [filename]\n"); - } else { - fprintf(stderr, "[-isvh] [-b ] [filename]\n"); - } - fprintf(stderr, " -h prints detailed help\n"); - fprintf(stderr, " -i computes checksum only\n"); - fprintf(stderr, " -v prints version and exits\n"); - if (!all) - return; - if (mode % 2) { - fprintf(stderr, " filename is usually got from the remote side by the protocol\n"); - fprintf(stderr, " but can be forced if you like to ignore this.\n"); - fprintf(stderr, " filename should be ommitted if output is sent to a pipe\n."); - } else { - fprintf(stderr, " -b value is the blocksize (framelen) of the transmitted data\n"); - fprintf(stderr, " default %d, which is a useful choice for ampr ax25.\n", BLOCKSIZ_DEFAULT); - fprintf(stderr, " -s indicates a stream with unknown size.\n"); - fprintf(stderr, " otherwise, the data will be read to memory until EOF.\n"); - fprintf(stderr, " -s is only available if stdin is a pipe\n"); - fprintf(stderr, " if filename specified in filter, the given name will be suggested instead.\n"); - fprintf(stderr, " filename may be ommited if used as filter.\n"); - } - fputc('\n', stderr); - fprintf(stderr, "Tips: - compressed download:\n"); - fprintf(stderr, " gzip -c foo.txt | bget foo.txt.gz\n"); - fprintf(stderr, " tar cjf - ~/foo ~/bar/ | bget my_data.tar.bz2\n"); - fputc('\n', stderr); - fprintf(stderr, "Other protocols:\n"); - fprintf(stderr, " bget / bput: receive / send with #BIN# protocol\n"); - fprintf(stderr, " yget / yput: receive / send with yapp\n"); - fprintf(stderr, " rget / rput: receive / send with didadit\n"); - fprintf(stderr, "These are (sym)links to one program: " MYNAME "\n"); + fprintf(stderr, "usage: %s ", myname); + if (mode % 2) { + fprintf(stderr, "[-ivh] [filename]\n"); + } else { + fprintf(stderr, "[-isvh] [-b ] [filename]\n"); + } + fprintf(stderr, " -h prints detailed help\n"); + fprintf(stderr, " -i computes checksum only\n"); + fprintf(stderr, " -v prints version and exits\n"); + if (!all) + return; + if (mode % 2) { + fprintf(stderr, " filename is usually got from the remote side by the protocol\n"); + fprintf(stderr, " but can be forced if you like to ignore this.\n"); + fprintf(stderr, " filename should be ommitted if output is sent to a pipe\n."); + } else { + fprintf(stderr, " -b value is the blocksize (framelen) of the transmitted data\n"); + fprintf(stderr, " default %d, which is a useful choice for ampr ax25.\n", BLOCKSIZ_DEFAULT); + fprintf(stderr, " -s indicates a stream with unknown size.\n"); + fprintf(stderr, " otherwise, the data will be read to memory until EOF.\n"); + fprintf(stderr, " -s is only available if stdin is a pipe\n"); + fprintf(stderr, " if filename specified in filter, the given name will be suggested instead.\n"); + fprintf(stderr, " filename may be ommited if used as filter.\n"); + } + fputc('\n', stderr); + fprintf(stderr, "Tips: - compressed download:\n"); + fprintf(stderr, " gzip -c foo.txt | bget foo.txt.gz\n"); + fprintf(stderr, " tar cjf - ~/foo ~/bar/ | bget my_data.tar.bz2\n"); + fputc('\n', stderr); + fprintf(stderr, "Other protocols:\n"); + fprintf(stderr, " bget / bput: receive / send with #BIN# protocol\n"); + fprintf(stderr, " yget / yput: receive / send with yapp\n"); + fprintf(stderr, " rget / rput: receive / send with didadit\n"); + fprintf(stderr, "These are (sym)links to one program: " MYNAME "\n"); } @@ -203,190 +203,190 @@ static int rput(void) { strcpy(err_msg, "yapp: not implementet yet\n"); return 1 int main(int argc, char *argv[]) { - int len; - int ret = 0; - int c; - char *p; - - /* determine what to so in the way how we are called */ - if ((p = strrchr(argv[0], '/'))) - p++; /* skip '/' */ - else - p = argv[0]; - len = strlen(p); - if (len < 0 || len > sizeof(myname)-1) - len = sizeof(myname)-1; - strncpy(myname, p, len); - myname[len] = 0; - strlwc(myname); - - fdin_is_pipe = (isatty(fdin) ? 0 : 1); - fdout_is_pipe = (isatty(fdout) ? 0 : 1); - - if (fdin_is_pipe && fdout_is_pipe) { - fprintf(stderr, "error: cannot work in between two pipes\n"); - exit(1); - } - - *filename = 0; - *err_msg = 0; - - if (!strcmp(myname, "bput")) - mode = RECV_BIN; - else if (!strcmp(myname, "bget")) - mode = SEND_BIN; - else if (!strcmp(myname, "yput")) - mode = RECV_YAPP; - else if (!strcmp(myname, "yget")) - mode = SEND_YAPP; - else if (!strcmp(myname, "rput")) - mode = RECV_DIDADIT; - else if (!strcmp(myname, "rget")) - mode = SEND_DIDADIT; - - if (mode % 2) { - if (fdin_is_pipe) { - fprintf(stderr, "error: error: stdin must be a tty\n"); - exit(1); - } - } else { - if (fdout_is_pipe) { - fprintf(stderr, "error: stdout must be a tty\n"); - exit(1); - } - } - - signal(SIGHUP, signal_handler); - signal(SIGTERM, signal_handler); - signal(SIGINT, signal_handler); + int len; + int ret = 0; + int c; + char *p; + + /* determine what to so in the way how we are called */ + if ((p = strrchr(argv[0], '/'))) + p++; /* skip '/' */ + else + p = argv[0]; + len = strlen(p); + if (len < 0 || len > sizeof(myname)-1) + len = sizeof(myname)-1; + strncpy(myname, p, len); + myname[len] = 0; + strlwc(myname); + + fdin_is_pipe = (isatty(fdin) ? 0 : 1); + fdout_is_pipe = (isatty(fdout) ? 0 : 1); + + if (fdin_is_pipe && fdout_is_pipe) { + fprintf(stderr, "error: cannot work in between two pipes\n"); + exit(1); + } + + *filename = 0; + *err_msg = 0; + + if (!strcmp(myname, "bput")) + mode = RECV_BIN; + else if (!strcmp(myname, "bget")) + mode = SEND_BIN; + else if (!strcmp(myname, "yput")) + mode = RECV_YAPP; + else if (!strcmp(myname, "yget")) + mode = SEND_YAPP; + else if (!strcmp(myname, "rput")) + mode = RECV_DIDADIT; + else if (!strcmp(myname, "rget")) + mode = SEND_DIDADIT; + + if (mode % 2) { + if (fdin_is_pipe) { + fprintf(stderr, "error: error: stdin must be a tty\n"); + exit(1); + } + } else { + if (fdout_is_pipe) { + fprintf(stderr, "error: stdout must be a tty\n"); + exit(1); + } + } + + signal(SIGHUP, signal_handler); + signal(SIGTERM, signal_handler); + signal(SIGINT, signal_handler); /* for difference betreen "bput -f file" and "bget file" */ -#define get_filename(f) { \ - if (!strcmp(f, "-")) { \ - if (mode % 2) \ - fdin_is_pipe = 1; \ - else \ - fdout_is_pipe = 1; \ - } else { \ - strncpy(filename, f, sizeof(filename)-1); \ - filename[sizeof(filename)-1] = 0; \ - if (mode % 2) { \ - if (fdin_is_pipe) \ - fdin_is_pipe = 0; \ - } else { \ - if (fdout_is_pipe) \ - fdout_is_pipe = 0; \ - } \ - } \ +#define get_filename(f) { \ + if (!strcmp(f, "-")) { \ + if (mode % 2) \ + fdin_is_pipe = 1; \ + else \ + fdout_is_pipe = 1; \ + } else { \ + strncpy(filename, f, sizeof(filename)-1); \ + filename[sizeof(filename)-1] = 0; \ + if (mode % 2) { \ + if (fdin_is_pipe) \ + fdin_is_pipe = 0; \ + } else { \ + if (fdout_is_pipe) \ + fdout_is_pipe = 0; \ + } \ + } \ } - while ((c = getopt(argc, argv, (mode % 2) ? "ivh?" : "b:isvh?")) != EOF) { - switch (c) { - case 'b': - if (((BLOCKSIZ = (unsigned ) atoi(optarg)) < BLOCKSIZ_MIN) || BLOCKSIZ > BLOCKSIZ_MAX) { - fprintf(stderr, "error: invalid blocksize: %d\n", BLOCKSIZ); - fprintf(stderr, " blocksize must be in the range %d <= x <= %d. a value\n", BLOCKSIZ_MIN, BLOCKSIZ_MAX); - fprintf(stderr, " of %d (default) is suggested, because it fits in an ax25 frame.\n", BLOCKSIZ_DEFAULT); - exit(1); - } - break; - case 'i': - do_crc_only = 1; - break; - case 's': - is_stream = 1; - break; - case 'v': - do_version(); - exit(0); - break; - case 'h': - case '?': - usage((c == 'h')); - exit(0); - break; - } - } - - if (mode == 0) { - usage(1); - exit(0); - } - - if (optind < argc) { - get_filename(argv[optind]); - optind++; - } - if (optind < argc) { - usage(0); - exit(1); - } - - if (is_stream && !fdin_is_pipe) { - fprintf(stderr, "error: -s is only available in a pipe\n"); - exit(1); - } - - if (do_crc_only) - goto skiped_crc_only_tag_1; - - if (mode % 2) { - if (fdin_is_pipe) { - fprintf(stderr, "error: error: stdin must be a tty.\n"); - exit(1); - } - if (fdout_is_pipe && *filename) { - fprintf(stderr, "error: filename in a pipe does not make sense.\n"); - exit(1); - } - } else { - if (fdout_is_pipe) { - fprintf(stderr, "error: stdout must be a tty.\n"); - exit(1); - } - if (!fdin_is_pipe && !*filename) { - fprintf(stderr, "error: no file to send.\n"); - exit(1); - } - } - - signal(SIGQUIT, signal_handler); - - set_tty_flags(); - eol_convention(1); + while ((c = getopt(argc, argv, (mode % 2) ? "ivh?" : "b:isvh?")) != EOF) { + switch (c) { + case 'b': + if (((BLOCKSIZ = (unsigned ) atoi(optarg)) < BLOCKSIZ_MIN) || BLOCKSIZ > BLOCKSIZ_MAX) { + fprintf(stderr, "error: invalid blocksize: %d\n", BLOCKSIZ); + fprintf(stderr, " blocksize must be in the range %d <= x <= %d. a value\n", BLOCKSIZ_MIN, BLOCKSIZ_MAX); + fprintf(stderr, " of %d (default) is suggested, because it fits in an ax25 frame.\n", BLOCKSIZ_DEFAULT); + exit(1); + } + break; + case 'i': + do_crc_only = 1; + break; + case 's': + is_stream = 1; + break; + case 'v': + do_version(); + exit(0); + break; + case 'h': + case '?': + usage((c == 'h')); + exit(0); + break; + } + } + + if (mode == 0) { + usage(1); + exit(0); + } + + if (optind < argc) { + get_filename(argv[optind]); + optind++; + } + if (optind < argc) { + usage(0); + exit(1); + } + + if (is_stream && !fdin_is_pipe) { + fprintf(stderr, "error: -s is only available in a pipe\n"); + exit(1); + } + + if (do_crc_only) + goto skiped_crc_only_tag_1; + + if (mode % 2) { + if (fdin_is_pipe) { + fprintf(stderr, "error: error: stdin must be a tty.\n"); + exit(1); + } + if (fdout_is_pipe && *filename) { + fprintf(stderr, "error: filename in a pipe does not make sense.\n"); + exit(1); + } + } else { + if (fdout_is_pipe) { + fprintf(stderr, "error: stdout must be a tty.\n"); + exit(1); + } + if (!fdin_is_pipe && !*filename) { + fprintf(stderr, "error: no file to send.\n"); + exit(1); + } + } + + signal(SIGQUIT, signal_handler); + + set_tty_flags(); + eol_convention(1); skiped_crc_only_tag_1: - switch (mode) { - case RECV_BIN: - if (do_crc_only) - ret = bget(); - else - ret = bput(); - break; - case SEND_BIN: - ret = bget(); - break; - case RECV_YAPP: - ret = yput(); - break; - case SEND_YAPP: - ret = yget(); - break; - case RECV_DIDADIT: - ret = rput(); - break; - case SEND_DIDADIT: - ret = rget(); - break; - } - - restore_defaults(); - if (*err_msg) { - fputs(err_msg, stderr); - } - exit(ret); - - return 0; + switch (mode) { + case RECV_BIN: + if (do_crc_only) + ret = bget(); + else + ret = bput(); + break; + case SEND_BIN: + ret = bget(); + break; + case RECV_YAPP: + ret = yput(); + break; + case SEND_YAPP: + ret = yget(); + break; + case RECV_DIDADIT: + ret = rput(); + break; + case SEND_DIDADIT: + ret = rget(); + break; + } + + restore_defaults(); + if (*err_msg) { + fputs(err_msg, stderr); + } + exit(ret); + + return 0; } diff --git a/ax25/axgetput/proto_bin.c b/ax25/axgetput/proto_bin.c index 78a6ccc..55b836a 100644 --- a/ax25/axgetput/proto_bin.c +++ b/ax25/axgetput/proto_bin.c @@ -11,34 +11,34 @@ #include "util.h" static int crctab[256]; -static int bittab[8] = { 128,64,32,16,8,4,2,1 }; +static int bittab[8] = { 128, 64, 32, 16, 8, 4, 2, 1 }; static int crcbit[8] = { - 0x9188,0x48c4,0x2462,0x1231,0x8108,0x4084,0x2042,0x1021 + 0x9188, 0x48c4, 0x2462, 0x1231, 0x8108, 0x4084, 0x2042, 0x1021 }; /*---------------------------------------------------------------------------*/ static int init_crc(void) { - int i,j; - - for (i = 0; i < 256; i++) { - crctab[i] = 0; - for (j = 0; j < 8; j++) { - if ((bittab[j] & i) != 0) { - crctab[i] = crctab[i] ^ crcbit[j]; - } - } - } - return 0; + int i,j; + + for (i = 0; i < 256; i++) { + crctab[i] = 0; + for (j = 0; j < 8; j++) { + if ((bittab[j] & i) != 0) { + crctab[i] = crctab[i] ^ crcbit[j]; + } + } + } + return 0; } /*---------------------------------------------------------------------------*/ static int do_crc(char b, int n, unsigned int crc) { - crc = (crctab[(crc >> 8)] ^ ((crc << 8) | (b & 0xff))) & 0xffff; - return crc; + crc = (crctab[(crc >> 8)] ^ ((crc << 8) | (b & 0xff))) & 0xffff; + return crc; } /*---------------------------------------------------------------------------*/ @@ -46,11 +46,11 @@ static int do_crc(char b, int n, unsigned int crc) static long parse_sfbin_date_to_unix(const char *s) { - unsigned long x; + unsigned long x; - sscanf(s, "%lX", &x); + sscanf(s, "%lX", &x); - return date_dos2unix(((x << 16) >> 16), (x >> 16)); + return date_dos2unix(((x << 16) >> 16), (x >> 16)); } /*---------------------------------------------------------------------------*/ @@ -58,450 +58,450 @@ static long parse_sfbin_date_to_unix(const char *s) static char * unix_to_sfbin_date_string(long gmt) { - static char buf[9]; - unsigned short s_time, s_date; + static char buf[9]; + unsigned short s_time, s_date; - date_unix2dos(((gmt == -1) ? time(0) : gmt), &s_time, &s_date); - sprintf(buf, "%X", ((s_date << 16) + s_time)); - return buf; + date_unix2dos(((gmt == -1) ? time(0) : gmt), &s_time, &s_date); + sprintf(buf, "%X", ((s_date << 16) + s_time)); + return buf; } /*---------------------------------------------------------------------------*/ int bput(void) { - struct stat statbuf; - char buf[1024]; /* < signed int */ - char filename_given[PATH_MAX]; - unsigned long len_read_expected = 0L; - unsigned long len_read_left; - time_t file_time = 0L; - unsigned int msg_crc = 0; - unsigned int crc = 0; - char *term_line = 0; - int last_line_had_CR = 0; - int len_termline = 0; - int len = 0; - int fddata = fdout; - int is_eof; - int i; - char *p; - char *p_buf; + struct stat statbuf; + char buf[1024]; /* < signed int */ + char filename_given[PATH_MAX]; + unsigned long len_read_expected = 0L; + unsigned long len_read_left; + time_t file_time = 0L; + unsigned int msg_crc = 0; + unsigned int crc = 0; + char *term_line = 0; + int last_line_had_CR = 0; + int len_termline = 0; + int len = 0; + int fddata = fdout; + int is_eof; + int i; + char *p; + char *p_buf; #define save_close(x) { \ - if (!fdout_is_pipe) \ - close(x); \ + if (!fdout_is_pipe) \ + close(x); \ } - for (;;) { - len = my_read(fdin, buf, sizeof(buf), &is_eof, "\r\n"); - if (is_eof || len < 1) { - sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); - return 1; - } - if (buf[len-1] == '\n') { + for (;;) { + len = my_read(fdin, buf, sizeof(buf), &is_eof, "\r\n"); + if (is_eof || len < 1) { + sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); + return 1; + } + if (buf[len-1] == '\n') { #if 0 - p = "warning: received. not 8bit clean?\r"; - secure_write(fdout, p, strlen(p)); + p = "warning: received. not 8bit clean?\r"; + secure_write(fdout, p, strlen(p)); #endif - sprintf(err_msg, "bad EOL: \n"); - return 1; - } - if (IS_BIN_ABORT(buf, len)) { - sprintf(err_msg, "Aborted by user request\n"); - return 1; - } - if (buf[len-1] == '\r' && len > 5 && !memcmp(buf, "#BIN#", 5)) { - break; - } - if (len == sizeof(buf)) { - sprintf(err_msg, "line to long\n"); - return 1; - } - } - buf[len-1] = 0; /* without trailing \r. and: string termination */ - - send_on_signal = bin_send_no_on_sig; - - /* parse #BIN arguments */ - *filename_given = 0; - - p_buf = buf; - for (i = 0; (p = strsep(&p_buf, "#")); i++) { - switch (i) { - case 0: - case 1: - break; - case 2: - if (*p) - len_read_expected = (unsigned long ) atol(p); - break; - default: - if (*p == '|') { - msg_crc = (unsigned int ) atoi(p+1); - } else if (*p == '$') { - file_time = parse_sfbin_date_to_unix(p+1); - } else { - strncpy(filename_given, p, sizeof(filename_given)-1); - filename_given[sizeof(filename_given)-1] = 0; - } - } - } - - if (!fdout_is_pipe) { - /* normal mode: store in given filename */ - if (!*filename) { - p = get_fixed_filename(filename_given, len_read_expected, msg_crc, 1); - strncpy(filename, p, sizeof(filename)-1); - filename[sizeof(filename)-1] = 0; - } - if (!stat(filename, &statbuf)) { - /* file exist */ - if (unlink(filename)) { - sprintf(err_msg, "error: cannot unlink %s (%s)\n", filename, strerror(errno)); - goto abort; - } - } - if ((fddata = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0640)) < 0) { - sprintf(err_msg, "error: cannot open %s (%s)\n", filename, strerror(errno)); - write(fderr, "\r#NO#\r", 6); - return 1; - } - } - - if (!len_read_expected) { - term_line = "***END\r"; - len_termline = strlen(term_line); - } - - /* say helo */ - send_on_signal = bin_send_abort_on_sig; - write(fderr, "\r#OK#\r", 6); - - len_read_left = len_read_expected; - - /* #bin# chechsum initialization */ - init_crc(); - - for (;;) { - - if ((len = my_read(fdin, buf, ((term_line || len_read_left > sizeof(buf)) ? sizeof(buf) : len_read_left), &is_eof, "\r")) < 1) { - save_close(fddata); - sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); - goto abort; - } - if (!len) { - save_close(fddata); - if (!term_line) { - sprintf(err_msg, "error: unexpected end of file during read: %s\n", strerror(errno)); - return 1; - } - return 0; - } - - if (msg_crc) { - int i; - for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], 1, crc); - } - - if (buf[len-1] == '\r') { - if (last_line_had_CR) { - if (IS_BIN_ABORT(buf, len)) { - /* "\r#ABORT#\r" was sent */ - if (!fdout_is_pipe) { - close(fddata); - /* clean up */ - unlink(filename); - } - return 1; + sprintf(err_msg, "bad EOL: \n"); + return 1; + } + if (IS_BIN_ABORT(buf, len)) { + sprintf(err_msg, "Aborted by user request\n"); + return 1; + } + if (buf[len-1] == '\r' && len > 5 && !memcmp(buf, "#BIN#", 5)) { + break; + } + if (len == sizeof(buf)) { + sprintf(err_msg, "line to long\n"); + return 1; + } + } + buf[len-1] = 0; /* without trailing \r. and: string termination */ + + send_on_signal = bin_send_no_on_sig; + + /* parse #BIN arguments */ + *filename_given = 0; + + p_buf = buf; + for (i = 0; (p = strsep(&p_buf, "#")); i++) { + switch (i) { + case 0: + case 1: + break; + case 2: + if (*p) + len_read_expected = (unsigned long ) atol(p); + break; + default: + if (*p == '|') { + msg_crc = (unsigned int ) atoi(p+1); + } else if (*p == '$') { + file_time = parse_sfbin_date_to_unix(p+1); + } else { + strncpy(filename_given, p, sizeof(filename_given)-1); + filename_given[sizeof(filename_given)-1] = 0; + } + } } - if (term_line && len == len_termline && !memcmp(buf, term_line, len_termline)) { - /* sucessfully read until termination string */ - break; + + if (!fdout_is_pipe) { + /* normal mode: store in given filename */ + if (!*filename) { + p = get_fixed_filename(filename_given, len_read_expected, msg_crc, 1); + strncpy(filename, p, sizeof(filename)-1); + filename[sizeof(filename)-1] = 0; + } + if (!stat(filename, &statbuf)) { + /* file exist */ + if (unlink(filename)) { + sprintf(err_msg, "error: cannot unlink %s (%s)\n", filename, strerror(errno)); + goto abort; + } + } + if ((fddata = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0640)) < 0) { + sprintf(err_msg, "error: cannot open %s (%s)\n", filename, strerror(errno)); + write(fderr, "\r#NO#\r", 6); + return 1; + } + } + + if (!len_read_expected) { + term_line = "***END\r"; + len_termline = strlen(term_line); } - } - last_line_had_CR = 1; - } else { - last_line_had_CR = 0; - } - if (!term_line) - len_read_left -= len; - - if (secure_write(fddata, buf, len) == -1) { - save_close(fddata); - sprintf(err_msg, "error: write failed (%s)\n", strerror(errno)); - goto abort; - } - - /* nothing left? */ - if (!term_line && len_read_left == 0L) - break; - if (is_eof) { - if (!term_line && len_read_left) { - save_close(fddata); - goto abort; - } - break; - } - } - if (crc != msg_crc) { - sprintf(err_msg, "Invalid crc: computed %d, expected %d.\n", crc, msg_crc); - /* don't unlink */ - save_close(fddata); - return 1; - } - if (!fdout_is_pipe) { - close(fddata); - if (file_time != 0L) { - struct utimbuf utb; - utb.modtime = file_time; - utb.actime = time(0); - utime(filename, &utb); - } - } - - send_on_signal = 0; - return 0; + + /* say helo */ + send_on_signal = bin_send_abort_on_sig; + write(fderr, "\r#OK#\r", 6); + + len_read_left = len_read_expected; + + /* #bin# chechsum initialization */ + init_crc(); + + for (;;) { + + if ((len = my_read(fdin, buf, ((term_line || len_read_left > sizeof(buf)) ? sizeof(buf) : len_read_left), &is_eof, "\r")) < 1) { + save_close(fddata); + sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); + goto abort; + } + if (!len) { + save_close(fddata); + if (!term_line) { + sprintf(err_msg, "error: unexpected end of file during read: %s\n", strerror(errno)); + return 1; + } + return 0; + } + + if (msg_crc) { + int i; + for (i = 0; i < len; i++) + crc = do_crc((int ) buf[i], 1, crc); + } + + if (buf[len-1] == '\r') { + if (last_line_had_CR) { + if (IS_BIN_ABORT(buf, len)) { + /* "\r#ABORT#\r" was sent */ + if (!fdout_is_pipe) { + close(fddata); + /* clean up */ + unlink(filename); + } + return 1; + } + if (term_line && len == len_termline && !memcmp(buf, term_line, len_termline)) { + /* sucessfully read until termination string */ + break; + } + } + last_line_had_CR = 1; + } else { + last_line_had_CR = 0; + } + if (!term_line) + len_read_left -= len; + + if (secure_write(fddata, buf, len) == -1) { + save_close(fddata); + sprintf(err_msg, "error: write failed (%s)\n", strerror(errno)); + goto abort; + } + + /* nothing left? */ + if (!term_line && len_read_left == 0L) + break; + if (is_eof) { + if (!term_line && len_read_left) { + save_close(fddata); + goto abort; + } + break; + } + } + if (crc != msg_crc) { + sprintf(err_msg, "Invalid crc: computed %d, expected %d.\n", crc, msg_crc); + /* don't unlink */ + save_close(fddata); + return 1; + } + if (!fdout_is_pipe) { + close(fddata); + if (file_time != 0L) { + struct utimbuf utb; + utb.modtime = file_time; + utb.actime = time(0); + utime(filename, &utb); + } + } + + send_on_signal = 0; + return 0; abort: - sleep(1); - write(fderr, "\r#ABORT#\r", 9); - return 1; + sleep(1); + write(fderr, "\r#ABORT#\r", 9); + return 1; #undef save_close } /*---------------------------------------------------------------------------*/ int bget(void) { - struct strlist { - struct strlist *next; - size_t len; - char data[1]; /* actually a the address of char * pointer */ - }; - - struct strlist *stored_file = 0; - struct strlist *sl_tail = 0; - struct strlist *sl; - struct timeval timeout; - struct stat statbuf; - - unsigned int crc = 0; - - char buf[1024]; - fd_set readfds; - int fddata = fdin; - int len; - unsigned long file_size = 0; - unsigned long len_remains; - int is_eof; - time_t file_time = 0L; + struct strlist { + struct strlist *next; + size_t len; + char data[1]; /* actually a the address of char * pointer */ + }; + + struct strlist *stored_file = 0; + struct strlist *sl_tail = 0; + struct strlist *sl; + struct timeval timeout; + struct stat statbuf; + + unsigned int crc = 0; + + char buf[1024]; + fd_set readfds; + int fddata = fdin; + int len; + unsigned long file_size = 0; + unsigned long len_remains; + int is_eof; + time_t file_time = 0L; #define save_close(x) { \ - if (!fdin_is_pipe) \ - close(x); \ + if (!fdin_is_pipe) \ + close(x); \ } #define store_line(s, len) { \ if (!(sl = (struct strlist *) malloc(sizeof(struct strlist *) + sizeof(size_t) + len))) \ - return 1; \ + return 1; \ sl->next = 0; \ sl->len = len; \ memcpy(sl->data, s, len); \ if (!stored_file) { \ - stored_file = sl; \ + stored_file = sl; \ } else { \ - sl_tail->next = sl; \ + sl_tail->next = sl; \ } \ sl_tail = sl; \ } - if (BLOCKSIZ < 1 || BLOCKSIZ > sizeof(buf)) - BLOCKSIZ = BLOCKSIZ_DEFAULT; - - init_crc(); - - if (!fdin_is_pipe && *filename) { - if ((fddata = open(filename, O_RDONLY)) == -1) { - sprintf(err_msg, "error: cannot open %s (%s)\n", filename, strerror(errno)); - return 1; - } - if (!fstat(fddata, &statbuf)) - file_time = statbuf.st_mtime; - else - file_time = time(0); - - /* compute crc */ - while ((len = read(fddata, buf, BLOCKSIZ)) > 0) { - int i; - for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], 1, crc); - file_size += len; - } - if (len < 0) { - sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); - close(fddata); - return 1; - } - /* rewind */ - if (lseek(fddata, 0L, SEEK_SET) != 0L) { - sprintf(err_msg, "error: file io failed on lseek() (%s)\n", strerror(errno)); - close(fddata); - return 1; - } - sprintf(buf, "\r#BIN#%ld#|%d#$%s#%s\r", file_size, crc, unix_to_sfbin_date_string(file_time), get_fixed_filename(filename, file_size, crc, 1)); - } else { - file_time = time(0); - if (!is_stream || do_crc_only) { - sprintf(err_msg, "error: not enough memory\n"); - while ((len = read(fddata, buf, sizeof(buf))) > 0) { - int i; - for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], 1, crc); - file_size += len; - if (!do_crc_only) - store_line(buf, len); - } - if (len < 0) { - sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); - close(fddata); - return 1; - } - *err_msg = 0; - sprintf(buf, "\r#BIN#%ld#|%d#$%s#%s\r", file_size, crc, unix_to_sfbin_date_string(file_time), get_fixed_filename(filename, file_size, crc, 1)); - } else { - sprintf(buf, "\r#BIN###$%s#%s\r", unix_to_sfbin_date_string(file_time), get_fixed_filename(filename, 0, 0, 1)); - } - /* - * hack: check for #ABORT# from fdout (fd 1), because fddata (fd 0) is - * our pipe we read the data from, which we actually tx. - * believe me, it does work. - */ - fdin = fdout; - } - - if (do_crc_only) { - printf("File information for %s:\n", get_fixed_filename(filename, file_size, crc, 1)); - printf(" size %ld bytes, crc %d, date %s (%ld)\n", file_size, crc, unix_to_sfbin_date_string(file_time), file_time); - return 0; - } - - send_on_signal = bin_send_abort_on_sig; - if (secure_write(fdout, buf, strlen(buf)) == -1) { - sprintf(err_msg, "error: write failed (%s)\n", strerror(errno)); - save_close(fddata); - return 1; - } - - /* wait for answer */ - for (;;) { - /* - * make sure we do not read from a pipe. fdout is also - * assigned to the tty - */ - len = my_read(fdout, buf, sizeof(buf), &is_eof, "\r\n"); - if (is_eof || len < 1) { - sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); - save_close(fddata); - return 1; - } - if (buf[len-1] == '\n') { + if (BLOCKSIZ < 1 || BLOCKSIZ > sizeof(buf)) + BLOCKSIZ = BLOCKSIZ_DEFAULT; + + init_crc(); + + if (!fdin_is_pipe && *filename) { + if ((fddata = open(filename, O_RDONLY)) == -1) { + sprintf(err_msg, "error: cannot open %s (%s)\n", filename, strerror(errno)); + return 1; + } + if (!fstat(fddata, &statbuf)) + file_time = statbuf.st_mtime; + else + file_time = time(0); + + /* compute crc */ + while ((len = read(fddata, buf, BLOCKSIZ)) > 0) { + int i; + for (i = 0; i < len; i++) + crc = do_crc((int ) buf[i], 1, crc); + file_size += len; + } + if (len < 0) { + sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); + close(fddata); + return 1; + } + /* rewind */ + if (lseek(fddata, 0L, SEEK_SET) != 0L) { + sprintf(err_msg, "error: file io failed on lseek() (%s)\n", strerror(errno)); + close(fddata); + return 1; + } + sprintf(buf, "\r#BIN#%ld#|%d#$%s#%s\r", file_size, crc, unix_to_sfbin_date_string(file_time), get_fixed_filename(filename, file_size, crc, 1)); + } else { + file_time = time(0); + if (!is_stream || do_crc_only) { + sprintf(err_msg, "error: not enough memory\n"); + while ((len = read(fddata, buf, sizeof(buf))) > 0) { + int i; + for (i = 0; i < len; i++) + crc = do_crc((int ) buf[i], 1, crc); + file_size += len; + if (!do_crc_only) + store_line(buf, len); + } + if (len < 0) { + sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); + close(fddata); + return 1; + } + *err_msg = 0; + sprintf(buf, "\r#BIN#%ld#|%d#$%s#%s\r", file_size, crc, unix_to_sfbin_date_string(file_time), get_fixed_filename(filename, file_size, crc, 1)); + } else { + sprintf(buf, "\r#BIN###$%s#%s\r", unix_to_sfbin_date_string(file_time), get_fixed_filename(filename, 0, 0, 1)); + } + /* + * hack: check for #ABORT# from fdout (fd 1), because fddata (fd 0) is + * our pipe we read the data from, which we actually tx. + * believe me, it does work. + */ + fdin = fdout; + } + + if (do_crc_only) { + printf("File information for %s:\n", get_fixed_filename(filename, file_size, crc, 1)); + printf(" size %ld bytes, crc %d, date %s (%ld)\n", file_size, crc, unix_to_sfbin_date_string(file_time), file_time); + return 0; + } + + send_on_signal = bin_send_abort_on_sig; + if (secure_write(fdout, buf, strlen(buf)) == -1) { + sprintf(err_msg, "error: write failed (%s)\n", strerror(errno)); + save_close(fddata); + return 1; + } + + /* wait for answer */ + for (;;) { + /* + * make sure we do not read from a pipe. fdout is also + * assigned to the tty + */ + len = my_read(fdout, buf, sizeof(buf), &is_eof, "\r\n"); + if (is_eof || len < 1) { + sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); + save_close(fddata); + return 1; + } + if (buf[len-1] == '\n') { #if 0 - char *p = "warning: received. not 8bit clean?\r"; - secure_write(fdout, p, strlen(p)); + char *p = "warning: received. not 8bit clean?\r"; + secure_write(fdout, p, strlen(p)); #endif - sprintf(err_msg, "bad EOL: \n"); - goto abort; - } else if (buf[len-1] != '\r') { - sprintf(err_msg, "line to long\n"); - continue; - } - if (IS_BIN_OK(buf, len)) - break; - if (IS_BIN_NO(buf, len)) { - save_close(fddata); - return 0; - } - if (IS_BIN_ABORT(buf, len)) { - sprintf(err_msg, "Aborted by user request\n"); - save_close(fddata); - return 1; - } - } - - len_remains = file_size; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - - for (;;) { - char *p_buf; - - /* check for user \r#ABORT#\r on tty stream */ - FD_ZERO(&readfds); - FD_SET(fdin, &readfds); - if (select(fdin+1, &readfds, 0, 0, &timeout) && FD_ISSET(fdin, &readfds)) { - if ((len = read(fdin, buf, sizeof(buf))) < 0) { - sprintf(err_msg, "read from tty failed (%s)\n", strerror(errno)); - save_close(fddata); - goto abort; - } - if (IS_BIN_ABORT(buf, len)) { - sprintf(err_msg, "Aborted by user request\n"); - save_close(fddata); - return 1; - } - } - /* read data */ - if (!fdin_is_pipe || is_stream) { - p_buf = buf; - if ((len = my_read(fddata, buf, ((len_remains > BLOCKSIZ || is_stream) ? BLOCKSIZ : len_remains), &is_eof, 0)) < 1) { - save_close(fddata); - if (len < 0) { - sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); - goto abort; + sprintf(err_msg, "bad EOL: \n"); + goto abort; + } else if (buf[len-1] != '\r') { + sprintf(err_msg, "line to long\n"); + continue; + } + if (IS_BIN_OK(buf, len)) + break; + if (IS_BIN_NO(buf, len)) { + save_close(fddata); + return 0; + } + if (IS_BIN_ABORT(buf, len)) { + sprintf(err_msg, "Aborted by user request\n"); + save_close(fddata); + return 1; + } + } + + len_remains = file_size; + timeout.tv_sec = 0; + timeout.tv_usec = 0; + + for (;;) { + char *p_buf; + + /* check for user \r#ABORT#\r on tty stream */ + FD_ZERO(&readfds); + FD_SET(fdin, &readfds); + if (select(fdin+1, &readfds, 0, 0, &timeout) && FD_ISSET(fdin, &readfds)) { + if ((len = read(fdin, buf, sizeof(buf))) < 0) { + sprintf(err_msg, "read from tty failed (%s)\n", strerror(errno)); + save_close(fddata); + goto abort; + } + if (IS_BIN_ABORT(buf, len)) { + sprintf(err_msg, "Aborted by user request\n"); + save_close(fddata); + return 1; + } + } + /* read data */ + if (!fdin_is_pipe || is_stream) { + p_buf = buf; + if ((len = my_read(fddata, buf, ((len_remains > BLOCKSIZ || is_stream) ? BLOCKSIZ : len_remains), &is_eof, 0)) < 1) { + save_close(fddata); + if (len < 0) { + sprintf(err_msg, "error: read failed (%s)\n", strerror(errno)); + goto abort; + } + break; + } + len_remains -= len; + } else { + p_buf = stored_file->data; + len = stored_file->len; + } + /* write to client */ + if (secure_write(fdout, p_buf, len) == -1) { + sprintf(err_msg, "error: write failed (%s)\n", strerror(errno)); + save_close(fddata); + goto abort; + } + if (fdin_is_pipe && !is_stream) { + sl = stored_file; + if (!(stored_file = stored_file->next)) + is_eof = 1; + free(sl); + } + if (!fdin_is_pipe && !len_remains) { + if (read(fddata, buf, 1) == 1) { + sprintf(err_msg, "Warning: file has grown in the meantime\n"); + } + is_eof = 1; + break; + } + /* + * need this because my_read may returned lenth != 0 (data to be written) + * but also has detected EOF. + */ + if (is_eof) + break; } - break; - } - len_remains -= len; - } else { - p_buf = stored_file->data; - len = stored_file->len; - } - /* write to client */ - if (secure_write(fdout, p_buf, len) == -1) { - sprintf(err_msg, "error: write failed (%s)\n", strerror(errno)); - save_close(fddata); - goto abort; - } - if (fdin_is_pipe && !is_stream) { - sl = stored_file; - if (!(stored_file = stored_file->next)) - is_eof = 1; - free(sl); - } - if (!fdin_is_pipe && !len_remains) { - if (read(fddata, buf, 1) == 1) { - sprintf(err_msg, "Warning: file has grown in the meantime\n"); - } - is_eof = 1; - break; - } - /* - * need this because my_read may returned lenth != 0 (data to be written) - * but also has detected EOF. - */ - if (is_eof) - break; - } - - sleep(10); - - return 0; + + sleep(10); + + return 0; abort: - sleep(1); - write(fderr, "\r#ABORT#\r", 9); - return 1; + sleep(1); + write(fderr, "\r#ABORT#\r", 9); + return 1; #undef save_close } -- cgit v1.2.3 From d2f98fb039a1dd860afc4b3a78ddb408c4f0a42b Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Thu, 6 Jun 2013 00:58:56 +0200 Subject: axgetput: Get rid of unused length argument of do_crc(). Signed-off-by: Ralf Baechle --- ax25/axgetput/proto_bin.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/proto_bin.c b/ax25/axgetput/proto_bin.c index 55b836a..aeee8bd 100644 --- a/ax25/axgetput/proto_bin.c +++ b/ax25/axgetput/proto_bin.c @@ -35,7 +35,7 @@ static int init_crc(void) /*---------------------------------------------------------------------------*/ -static int do_crc(char b, int n, unsigned int crc) +static int do_crc(char b, unsigned int crc) { crc = (crctab[(crc >> 8)] ^ ((crc << 8) | (b & 0xff))) & 0xffff; return crc; @@ -203,7 +203,7 @@ int bput(void) if (msg_crc) { int i; for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], 1, crc); + crc = do_crc((int ) buf[i], crc); } if (buf[len-1] == '\r') { @@ -336,7 +336,7 @@ int bget(void) { while ((len = read(fddata, buf, BLOCKSIZ)) > 0) { int i; for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], 1, crc); + crc = do_crc((int ) buf[i], crc); file_size += len; } if (len < 0) { @@ -358,7 +358,7 @@ int bget(void) { while ((len = read(fddata, buf, sizeof(buf))) > 0) { int i; for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], 1, crc); + crc = do_crc((int ) buf[i], crc); file_size += len; if (!do_crc_only) store_line(buf, len); -- cgit v1.2.3 From b1092362e2c2ab04c38061b2701184a8423d99a2 Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Thu, 6 Jun 2013 01:00:31 +0200 Subject: axgetput: Provide calc_crc() function to iterate over memory area. Signed-off-by: Ralf Baechle --- ax25/axgetput/proto_bin.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/proto_bin.c b/ax25/axgetput/proto_bin.c index aeee8bd..d61f72a 100644 --- a/ax25/axgetput/proto_bin.c +++ b/ax25/axgetput/proto_bin.c @@ -41,6 +41,14 @@ static int do_crc(char b, unsigned int crc) return crc; } +unsigned int calc_crc(char *buf, int n, unsigned crc) +{ + while (--n >= 0) + crc = do_crc(*buf++, crc); + + return crc; +} + /*---------------------------------------------------------------------------*/ static long parse_sfbin_date_to_unix(const char *s) -- cgit v1.2.3 From 943fd24fa6f907cd00dde4465bb39e1da382cff9 Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Thu, 6 Jun 2013 01:04:17 +0200 Subject: axgetput: Use calc_crc() to simplify CRC calculations. Signed-off-by: Ralf Baechle --- ax25/axgetput/proto_bin.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/proto_bin.c b/ax25/axgetput/proto_bin.c index d61f72a..401290d 100644 --- a/ax25/axgetput/proto_bin.c +++ b/ax25/axgetput/proto_bin.c @@ -208,11 +208,8 @@ int bput(void) return 0; } - if (msg_crc) { - int i; - for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], crc); - } + if (msg_crc) + crc = calc_crc(buf, len, 0); if (buf[len-1] == '\r') { if (last_line_had_CR) { @@ -342,9 +339,7 @@ int bget(void) { /* compute crc */ while ((len = read(fddata, buf, BLOCKSIZ)) > 0) { - int i; - for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], crc); + crc = calc_crc(buf, len, 0); file_size += len; } if (len < 0) { @@ -364,9 +359,7 @@ int bget(void) { if (!is_stream || do_crc_only) { sprintf(err_msg, "error: not enough memory\n"); while ((len = read(fddata, buf, sizeof(buf))) > 0) { - int i; - for (i = 0; i < len; i++) - crc = do_crc((int ) buf[i], crc); + crc = calc_crc(buf, len, 0); file_size += len; if (!do_crc_only) store_line(buf, len); -- cgit v1.2.3 From 19c4577a90015f6e05066a861d560f9702ad642d Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Thu, 6 Jun 2013 01:05:05 +0200 Subject: axgetput: Simplify do_crc() a bit. Signed-off-by: Ralf Baechle --- ax25/axgetput/proto_bin.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/proto_bin.c b/ax25/axgetput/proto_bin.c index 401290d..c69bc87 100644 --- a/ax25/axgetput/proto_bin.c +++ b/ax25/axgetput/proto_bin.c @@ -37,8 +37,7 @@ static int init_crc(void) static int do_crc(char b, unsigned int crc) { - crc = (crctab[(crc >> 8)] ^ ((crc << 8) | (b & 0xff))) & 0xffff; - return crc; + return (crctab[(crc >> 8)] ^ ((crc << 8) | (b & 0xff))) & 0xffff; } unsigned int calc_crc(char *buf, int n, unsigned crc) -- cgit v1.2.3 From 67d85b3d5cf145a5bf0a1431d6052473b017daa9 Mon Sep 17 00:00:00 2001 From: Ralf Baechle Date: Thu, 6 Jun 2013 01:06:54 +0200 Subject: axgetput: Use shifts instead of a silly table to compute bitmask. Signed-off-by: Ralf Baechle --- ax25/axgetput/proto_bin.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'ax25/axgetput') diff --git a/ax25/axgetput/proto_bin.c b/ax25/axgetput/proto_bin.c index c69bc87..5d1bde9 100644 --- a/ax25/axgetput/proto_bin.c +++ b/ax25/axgetput/proto_bin.c @@ -11,7 +11,6 @@ #include "util.h" static int crctab[256]; -static int bittab[8] = { 128, 64, 32, 16, 8, 4, 2, 1 }; static int crcbit[8] = { 0x9188, 0x48c4, 0x2462, 0x1231, 0x8108, 0x4084, 0x2042, 0x1021 }; @@ -25,9 +24,8 @@ static int init_crc(void) for (i = 0; i < 256; i++) { crctab[i] = 0; for (j = 0; j < 8; j++) { - if ((bittab[j] & i) != 0) { + if ((i << j) & 0x80) crctab[i] = crctab[i] ^ crcbit[j]; - } } } return 0; -- cgit v1.2.3