aboutsummaryrefslogtreecommitdiff
path: root/networking/nc_bloaty.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-07-13 12:37:31 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-07-13 12:37:31 +0000
commit828e2a95dac7b708cdcfac5b6b99e7d3597c80a5 (patch)
treef3e3382eb209f933f80b6292151a01cf757f7f66 /networking/nc_bloaty.c
parent8cc9cb8bc51bab014aed0f9a2c9a6119560f96cd (diff)
downloadbusybox-w32-828e2a95dac7b708cdcfac5b6b99e7d3597c80a5.tar.gz
busybox-w32-828e2a95dac7b708cdcfac5b6b99e7d3597c80a5.tar.bz2
busybox-w32-828e2a95dac7b708cdcfac5b6b99e7d3597c80a5.zip
nc: minor code shrink
function old new delta dolisten 731 737 +6 tmtravel 32 21 -11 catch 75 64 -11 oprint 272 229 -43 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 6/-65) Total: -59 bytes text data bss dec hex filename 676698 3340 13936 693974 a96d6 busybox_old 676650 3340 13936 693926 a96a6 busybox_unstripped
Diffstat (limited to 'networking/nc_bloaty.c')
-rw-r--r--networking/nc_bloaty.c91
1 files changed, 37 insertions, 54 deletions
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c
index a318c8126..0d1071499 100644
--- a/networking/nc_bloaty.c
+++ b/networking/nc_bloaty.c
@@ -160,18 +160,23 @@ enum {
160/* catch: no-brainer interrupt handler */ 160/* catch: no-brainer interrupt handler */
161static void catch(int sig) 161static void catch(int sig)
162{ 162{
163 errno = 0;
164 if (o_verbose > 1) /* normally we don't care */ 163 if (o_verbose > 1) /* normally we don't care */
165 fprintf(stderr, SENT_N_RECV_M, wrote_net, wrote_out); 164 fprintf(stderr, SENT_N_RECV_M, wrote_net, wrote_out);
166 fprintf(stderr, "punt!\n"); 165 fprintf(stderr, "punt!\n");
167 exit(1); 166 exit(1);
168} 167}
169 168
170/* timeout and other signal handling cruft */ 169/* unarm */
171static void tmtravel(int sig) 170static void unarm(void)
172{ 171{
173 signal(SIGALRM, SIG_IGN); 172 signal(SIGALRM, SIG_IGN);
174 alarm(0); 173 alarm(0);
174}
175
176/* timeout and other signal handling cruft */
177static void tmtravel(int sig)
178{
179 unarm();
175 longjmp(jbuf, 1); 180 longjmp(jbuf, 1);
176} 181}
177 182
@@ -182,13 +187,6 @@ static void arm(unsigned secs)
182 alarm(secs); 187 alarm(secs);
183} 188}
184 189
185/* unarm */
186static void unarm(void)
187{
188 signal(SIGALRM, SIG_IGN);
189 alarm(0);
190}
191
192/* findline: 190/* findline:
193 find the next newline in a buffer; return inclusive size of that "line", 191 find the next newline in a buffer; return inclusive size of that "line",
194 or the entire buffer size, so the caller knows how much to then write(). 192 or the entire buffer size, so the caller knows how much to then write().
@@ -246,11 +244,11 @@ static int connect_w_timeout(int fd)
246 arm(o_wait); 244 arm(o_wait);
247 if (setjmp(jbuf) == 0) { 245 if (setjmp(jbuf) == 0) {
248 rr = connect(fd, &themaddr->sa, themaddr->len); 246 rr = connect(fd, &themaddr->sa, themaddr->len);
247 unarm();
249 } else { /* setjmp: connect failed... */ 248 } else { /* setjmp: connect failed... */
250 rr = -1; 249 rr = -1;
251 errno = ETIMEDOUT; /* fake it */ 250 errno = ETIMEDOUT; /* fake it */
252 } 251 }
253 unarm();
254 return rr; 252 return rr;
255} 253}
256 254
@@ -319,9 +317,9 @@ static void dolisten(void)
319 &remend.sa, &ouraddr->sa, ouraddr->len); 317 &remend.sa, &ouraddr->sa, ouraddr->len);
320 if (rr < 0) 318 if (rr < 0)
321 bb_perror_msg_and_die("recvfrom"); 319 bb_perror_msg_and_die("recvfrom");
320 unarm();
322 } else 321 } else
323 bb_error_msg_and_die("timeout"); 322 bb_error_msg_and_die("timeout");
324 unarm();
325/* Now we learned *to which IP* peer has connected, and we want to anchor 323/* Now we learned *to which IP* peer has connected, and we want to anchor
326our socket on it, so that our outbound packets will have correct local IP. 324our socket on it, so that our outbound packets will have correct local IP.
327Unfortunately, bind() on already bound socket will fail now (EINVAL): 325Unfortunately, bind() on already bound socket will fail now (EINVAL):
@@ -350,10 +348,9 @@ create new one, and bind() it. TODO */
350 close(rr); 348 close(rr);
351 goto again; 349 goto again;
352 } 350 }
353 351 unarm();
354 } else 352 } else
355 bb_error_msg_and_die("timeout"); 353 bb_error_msg_and_die("timeout");
356 unarm();
357 xmove_fd(rr, netfd); /* dump the old socket, here's our new one */ 354 xmove_fd(rr, netfd); /* dump the old socket, here's our new one */
358 /* find out what address the connection was *to* on our end, in case we're 355 /* find out what address the connection was *to* on our end, in case we're
359 doing a listen-on-any on a multihomed machine. This allows one to 356 doing a listen-on-any on a multihomed machine. This allows one to
@@ -462,68 +459,54 @@ int udptest(void);
462 what when. Adapted from dgaudet's original example -- but must be ripping 459 what when. Adapted from dgaudet's original example -- but must be ripping
463 *fast*, since we don't want to be too disk-bound... */ 460 *fast*, since we don't want to be too disk-bound... */
464#if ENABLE_NC_EXTRA 461#if ENABLE_NC_EXTRA
465static void oprint(int direction, unsigned char *p, int bc) 462static void oprint(int direction, unsigned char *p, unsigned bc)
466{ 463{
467 int obc; /* current "global" offset */ 464 unsigned obc; /* current "global" offset */
468 int soc; /* stage write count */ 465 unsigned x;
469 unsigned char *op; /* out hexdump ptr */ 466 unsigned char *op; /* out hexdump ptr */
470 unsigned char *a; /* out asc-dump ptr */ 467 unsigned char *ap; /* out asc-dump ptr */
471 int x;
472 unsigned char stage[100]; 468 unsigned char stage[100];
473 469
474 if (bc == 0) 470 if (bc == 0)
475 return; 471 return;
476 472
477 op = stage;
478 obc = wrote_net; /* use the globals! */ 473 obc = wrote_net; /* use the globals! */
479 if (direction == '<') 474 if (direction == '<')
480 obc = wrote_out; 475 obc = wrote_out;
481 *op++ = direction; 476 stage[0] = direction;
482 *op = ' '; 477 stage[59] = '#'; /* preload separator */
483 stage[59] = '#'; /* preload separator */
484 stage[60] = ' '; 478 stage[60] = ' ';
485 479
486 while (bc) { /* for chunk-o-data ... */ 480 do { /* for chunk-o-data ... */
487 x = 16; 481 x = 16;
488 soc = 78; /* len of whole formatted line */ 482 if (bc < 16) {
489 if (bc < x) { 483 /* memset(&stage[bc*3 + 11], ' ', 16*3 - bc*3); */
490 soc = soc - 16 + bc; /* fiddle for however much is left */ 484 memset(&stage[11], ' ', 16*3);
491 x = (bc * 3) + 11; /* 2 digits + space per, after D & offset */ 485 x = bc;
492 op = &stage[x]; 486 }
493 x = 16 - bc; 487 sprintf(&stage[1], " %8.8x ", obc); /* xxx: still slow? */
494 while (x) { 488 bc -= x; /* fix current count */
495 *op++ = ' '; /* preload filler spaces */ 489 obc += x; /* fix current offset */
496 *op++ = ' '; 490 op = &stage[11]; /* where hex starts */
497 *op++ = ' '; 491 ap = &stage[61]; /* where ascii starts */
498 x--;
499 }
500 x = bc; /* re-fix current linecount */
501 } /* if bc < x */
502
503 bc -= x; /* fix wrt current line size */
504 sprintf(&stage[2], "%8.8x ", obc); /* xxx: still slow? */
505 obc += x; /* fix current offset */
506 op = &stage[11]; /* where hex starts */
507 a = &stage[61]; /* where ascii starts */
508 492
509 while (x) { /* for line of dump, however long ... */ 493 do { /* for line of dump, however long ... */
510 *op++ = 0x20 | bb_hexdigits_upcase[*p >> 4]; 494 *op++ = 0x20 | bb_hexdigits_upcase[*p >> 4];
511 *op++ = 0x20 | bb_hexdigits_upcase[*p & 0x0f]; 495 *op++ = 0x20 | bb_hexdigits_upcase[*p & 0x0f];
512 *op++ = ' '; 496 *op++ = ' ';
513 if ((*p > 31) && (*p < 127)) 497 if ((*p > 31) && (*p < 127))
514 *a = *p; /* printing */ 498 *ap = *p; /* printing */
515 else 499 else
516 *a = '.'; /* nonprinting, loose def */ 500 *ap = '.'; /* nonprinting, loose def */
517 a++; 501 ap++;
518 p++; 502 p++;
519 x--; 503 } while (--x);
520 } /* while x */ 504 *ap++ = '\n'; /* finish the line */
521 *a = '\n'; /* finish the line */ 505 xwrite(ofd, stage, ap - stage);
522 xwrite(ofd, stage, soc); 506 } while (bc);
523 } /* while bc */
524} 507}
525#else 508#else
526void oprint(int direction, unsigned char *p, int bc); 509void oprint(int direction, unsigned char *p, unsigned bc);
527#endif 510#endif
528 511
529/* readwrite: 512/* readwrite: