main.c (204499) | main.c (215434) |
---|---|
1/*- 2 * Copyright (c) 1983, 1988, 1993 3 * Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 30 unchanged lines hidden (view full) --- 39 40#if 0 41#ifndef lint 42static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 3/1/94"; 43#endif /* not lint */ 44#endif 45 46#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1983, 1988, 1993 3 * Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 30 unchanged lines hidden (view full) --- 39 40#if 0 41#ifndef lint 42static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 3/1/94"; 43#endif /* not lint */ 44#endif 45 46#include <sys/cdefs.h> |
47__FBSDID("$FreeBSD: head/usr.bin/netstat/main.c 204499 2010-03-01 00:46:45Z rwatson $"); | 47__FBSDID("$FreeBSD: head/usr.bin/netstat/main.c 215434 2010-11-17 18:55:12Z gnn $"); |
48 49#include <sys/param.h> 50#include <sys/file.h> 51#include <sys/protosw.h> 52#include <sys/socket.h> 53#include <sys/socketvar.h> 54 55#include <netinet/in.h> --- 281 unchanged lines hidden (view full) --- 337int noutputs = 0; /* how much outputs before we exit */ 338int numeric_addr; /* show addresses numerically */ 339int numeric_port; /* show ports numerically */ 340static int pflag; /* show given protocol */ 341int Qflag; /* show netisr information */ 342int rflag; /* show routing tables (or routing stats) */ 343int sflag; /* show protocol statistics */ 344int Wflag; /* wide display */ | 48 49#include <sys/param.h> 50#include <sys/file.h> 51#include <sys/protosw.h> 52#include <sys/socket.h> 53#include <sys/socketvar.h> 54 55#include <netinet/in.h> --- 281 unchanged lines hidden (view full) --- 337int noutputs = 0; /* how much outputs before we exit */ 338int numeric_addr; /* show addresses numerically */ 339int numeric_port; /* show ports numerically */ 340static int pflag; /* show given protocol */ 341int Qflag; /* show netisr information */ 342int rflag; /* show routing tables (or routing stats) */ 343int sflag; /* show protocol statistics */ 344int Wflag; /* wide display */ |
345int Tflag; /* TCP Information */ |
|
345int xflag; /* extra information, includes all socket buffer info */ 346int zflag; /* zero stats */ 347 348int interval; /* repeat interval for i/f stats */ 349 350char *interface; /* desired i/f for stats, or NULL for all i/fs */ 351int unit; /* unit number for above */ 352 353int af; /* address family */ 354int live; /* true if we are examining a live system */ 355 356int 357main(int argc, char *argv[]) 358{ 359 struct protox *tp = NULL; /* for printing cblocks & stats */ 360 int ch; 361 362 af = AF_UNSPEC; 363 | 346int xflag; /* extra information, includes all socket buffer info */ 347int zflag; /* zero stats */ 348 349int interval; /* repeat interval for i/f stats */ 350 351char *interface; /* desired i/f for stats, or NULL for all i/fs */ 352int unit; /* unit number for above */ 353 354int af; /* address family */ 355int live; /* true if we are examining a live system */ 356 357int 358main(int argc, char *argv[]) 359{ 360 struct protox *tp = NULL; /* for printing cblocks & stats */ 361 int ch; 362 363 af = AF_UNSPEC; 364 |
364 while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:Qq:rSsuWw:xz")) | 365 while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:Qq:rSTsuWw:xz")) |
365 != -1) 366 switch(ch) { 367 case 'A': 368 Aflag = 1; 369 break; 370 case 'a': 371 aflag = 1; 372 break; --- 98 unchanged lines hidden (view full) --- 471 case 'W': 472 case 'l': 473 Wflag = 1; 474 break; 475 case 'w': 476 interval = atoi(optarg); 477 iflag = 1; 478 break; | 366 != -1) 367 switch(ch) { 368 case 'A': 369 Aflag = 1; 370 break; 371 case 'a': 372 aflag = 1; 373 break; --- 98 unchanged lines hidden (view full) --- 472 case 'W': 473 case 'l': 474 Wflag = 1; 475 break; 476 case 'w': 477 interval = atoi(optarg); 478 iflag = 1; 479 break; |
480 case 'T': 481 Tflag = 1; 482 break; |
|
479 case 'x': 480 xflag = 1; 481 break; 482 case 'z': 483 zflag = 1; 484 break; 485 case '?': 486 default: --- 23 unchanged lines hidden (view full) --- 510 /* 511 * Discard setgid privileges if not the running kernel so that bad 512 * guys can't print interesting stuff from kernel memory. 513 */ 514 live = (nlistf == NULL && memf == NULL); 515 if (!live) 516 setgid(getgid()); 517 | 483 case 'x': 484 xflag = 1; 485 break; 486 case 'z': 487 zflag = 1; 488 break; 489 case '?': 490 default: --- 23 unchanged lines hidden (view full) --- 514 /* 515 * Discard setgid privileges if not the running kernel so that bad 516 * guys can't print interesting stuff from kernel memory. 517 */ 518 live = (nlistf == NULL && memf == NULL); 519 if (!live) 520 setgid(getgid()); 521 |
522 if (xflag && Tflag) 523 errx(1, "-x and -T are incompatible, pick one."); 524 |
|
518 if (Bflag) { 519 if (!live) 520 usage(); 521 bpf_stats(interface); 522 exit(0); 523 } 524 if (mflag) { 525 if (!live) { --- 263 unchanged lines hidden (view full) --- 789 endprotoent(); 790 return (NULL); 791} 792 793static void 794usage(void) 795{ 796 (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", | 525 if (Bflag) { 526 if (!live) 527 usage(); 528 bpf_stats(interface); 529 exit(0); 530 } 531 if (mflag) { 532 if (!live) { --- 263 unchanged lines hidden (view full) --- 796 endprotoent(); 797 return (NULL); 798} 799 800static void 801usage(void) 802{ 803 (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", |
797"usage: netstat [-AaLnSWx] [-f protocol_family | -p protocol]\n" | 804"usage: netstat [-AaLnSTWx] [-f protocol_family | -p protocol]\n" |
798" [-M core] [-N system]", 799" netstat -i | -I interface [-abdhnW] [-f address_family]\n" 800" [-M core] [-N system]", 801" netstat -w wait [-I interface] [-d] [-M core] [-N system] [-q howmany]", 802" netstat -s [-s] [-z] [-f protocol_family | -p protocol]\n" 803" [-M core] [-N system]", 804" netstat -i | -I interface -s [-f protocol_family | -p protocol]\n" 805" [-M core] [-N system]", 806" netstat -m [-M core] [-N system]", 807" netstat -B [-I interface]", 808" netstat -r [-AanW] [-f address_family] [-M core] [-N system]", 809" netstat -rs [-s] [-M core] [-N system]", 810" netstat -g [-W] [-f address_family] [-M core] [-N system]", 811" netstat -gs [-s] [-f address_family] [-M core] [-N system]", 812" netstat -Q"); 813 exit(1); 814} | 805" [-M core] [-N system]", 806" netstat -i | -I interface [-abdhnW] [-f address_family]\n" 807" [-M core] [-N system]", 808" netstat -w wait [-I interface] [-d] [-M core] [-N system] [-q howmany]", 809" netstat -s [-s] [-z] [-f protocol_family | -p protocol]\n" 810" [-M core] [-N system]", 811" netstat -i | -I interface -s [-f protocol_family | -p protocol]\n" 812" [-M core] [-N system]", 813" netstat -m [-M core] [-N system]", 814" netstat -B [-I interface]", 815" netstat -r [-AanW] [-f address_family] [-M core] [-N system]", 816" netstat -rs [-s] [-M core] [-N system]", 817" netstat -g [-W] [-f address_family] [-M core] [-N system]", 818" netstat -gs [-s] [-f address_family] [-M core] [-N system]", 819" netstat -Q"); 820 exit(1); 821} |