login: use %s - we know that string is not too long there
ping[6]: use getopt32: smaller (-50 bytes) and handles -c6 correctly (was requiring '-c 6' with mandatory space)
This commit is contained in:
parent
6a353c8158
commit
4a5cf16a36
@ -323,16 +323,16 @@ auth_failed:
|
|||||||
username);
|
username);
|
||||||
}
|
}
|
||||||
if (getfilecon(full_tty, &old_tty_sid) < 0) {
|
if (getfilecon(full_tty, &old_tty_sid) < 0) {
|
||||||
bb_perror_msg_and_die("getfilecon(%.100s) failed",
|
bb_perror_msg_and_die("getfilecon(%s) failed",
|
||||||
full_tty);
|
full_tty);
|
||||||
}
|
}
|
||||||
if (security_compute_relabel(user_sid, old_tty_sid,
|
if (security_compute_relabel(user_sid, old_tty_sid,
|
||||||
SECCLASS_CHR_FILE, &new_tty_sid) != 0) {
|
SECCLASS_CHR_FILE, &new_tty_sid) != 0) {
|
||||||
bb_perror_msg_and_die("security_change_sid(%.100s) failed",
|
bb_perror_msg_and_die("security_change_sid(%s) failed",
|
||||||
full_tty);
|
full_tty);
|
||||||
}
|
}
|
||||||
if (setfilecon(full_tty, new_tty_sid) != 0) {
|
if (setfilecon(full_tty, new_tty_sid) != 0) {
|
||||||
bb_perror_msg_and_die("chsid(%.100s, %s) failed",
|
bb_perror_msg_and_die("chsid(%s, %s) failed",
|
||||||
full_tty, new_tty_sid);
|
full_tty, new_tty_sid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,17 +41,10 @@ enum {
|
|||||||
PINGINTERVAL = 1 /* second */
|
PINGINTERVAL = 1 /* second */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define O_QUIET (1 << 0)
|
|
||||||
|
|
||||||
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
|
|
||||||
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
|
|
||||||
#define SET(bit) (A(bit) |= B(bit))
|
|
||||||
#define CLR(bit) (A(bit) &= (~B(bit)))
|
|
||||||
#define TST(bit) (A(bit) & B(bit))
|
|
||||||
|
|
||||||
static void ping(const char *host);
|
static void ping(const char *host);
|
||||||
|
|
||||||
/* common routines */
|
/* common routines */
|
||||||
|
|
||||||
static int in_cksum(unsigned short *buf, int sz)
|
static int in_cksum(unsigned short *buf, int sz)
|
||||||
{
|
{
|
||||||
int nleft = sz;
|
int nleft = sz;
|
||||||
@ -75,8 +68,10 @@ static int in_cksum(unsigned short *buf, int sz)
|
|||||||
return (ans);
|
return (ans);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* simple version */
|
|
||||||
#ifndef CONFIG_FEATURE_FANCY_PING
|
#ifndef CONFIG_FEATURE_FANCY_PING
|
||||||
|
|
||||||
|
/* simple version */
|
||||||
|
|
||||||
static char *hostname;
|
static char *hostname;
|
||||||
|
|
||||||
static void noresp(int ign)
|
static void noresp(int ign)
|
||||||
@ -153,14 +148,21 @@ int ping_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else /* ! CONFIG_FEATURE_FANCY_PING */
|
#else /* ! CONFIG_FEATURE_FANCY_PING */
|
||||||
|
|
||||||
/* full(er) version */
|
/* full(er) version */
|
||||||
|
|
||||||
|
#define OPT_STRING "qc:s:I:"
|
||||||
|
enum {
|
||||||
|
OPT_QUIET = 1 << 0,
|
||||||
|
};
|
||||||
|
|
||||||
static struct sockaddr_in pingaddr;
|
static struct sockaddr_in pingaddr;
|
||||||
static struct sockaddr_in sourceaddr;
|
static struct sockaddr_in sourceaddr;
|
||||||
static int pingsock = -1;
|
static int pingsock = -1;
|
||||||
static unsigned datalen; /* intentionally uninitialized to work around gcc bug */
|
static unsigned datalen; /* intentionally uninitialized to work around gcc bug */
|
||||||
|
|
||||||
static unsigned long ntransmitted, nreceived, nrepeats, pingcount;
|
static unsigned long ntransmitted, nreceived, nrepeats, pingcount;
|
||||||
static int myid, options;
|
static int myid;
|
||||||
static unsigned long tmin = ULONG_MAX, tmax, tsum;
|
static unsigned long tmin = ULONG_MAX, tmax, tsum;
|
||||||
static char rcvd_tbl[MAX_DUP_CHK / 8];
|
static char rcvd_tbl[MAX_DUP_CHK / 8];
|
||||||
|
|
||||||
@ -170,6 +172,12 @@ static void sendping(int);
|
|||||||
static void pingstats(int);
|
static void pingstats(int);
|
||||||
static void unpack(char *, int, struct sockaddr_in *);
|
static void unpack(char *, int, struct sockaddr_in *);
|
||||||
|
|
||||||
|
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
|
||||||
|
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
|
||||||
|
#define SET(bit) (A(bit) |= B(bit))
|
||||||
|
#define CLR(bit) (A(bit) &= (~B(bit)))
|
||||||
|
#define TST(bit) (A(bit) & B(bit))
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
static void pingstats(int junk)
|
static void pingstats(int junk)
|
||||||
@ -304,7 +312,7 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from)
|
|||||||
dupflag = 0;
|
dupflag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options & O_QUIET)
|
if (option_mask32 & OPT_QUIET)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf("%d bytes from %s: icmp_seq=%u", sz,
|
printf("%d bytes from %s: icmp_seq=%u", sz,
|
||||||
@ -409,55 +417,26 @@ static int parse_nipquad(const char *str, struct sockaddr_in* addr)
|
|||||||
|
|
||||||
int ping_main(int argc, char **argv)
|
int ping_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *thisarg;
|
char *opt_c, *opt_s, *opt_I;
|
||||||
|
|
||||||
datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
|
datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
|
||||||
|
|
||||||
argc--;
|
/* exactly one argument needed */
|
||||||
argv++;
|
opt_complementary = "=1";
|
||||||
/* Parse any options */
|
getopt32(argc, argv, OPT_STRING, &opt_c, &opt_s, &opt_I);
|
||||||
while (argc >= 1 && **argv == '-') {
|
if (option_mask32 & 2) pingcount = xatoul(opt_c); // -c
|
||||||
thisarg = *argv;
|
if (option_mask32 & 4) datalen = xatou16(opt_s); // -s
|
||||||
thisarg++;
|
if (option_mask32 & 8) { // -I
|
||||||
switch (*thisarg) {
|
/* TODO: ping6 accepts iface too:
|
||||||
case 'q':
|
if_index = if_nametoindex(*argv);
|
||||||
options |= O_QUIET;
|
if (!if_index) ...
|
||||||
break;
|
make it true for ping. */
|
||||||
case 'c':
|
if (parse_nipquad(opt_I, &sourceaddr))
|
||||||
if (--argc <= 0)
|
|
||||||
bb_show_usage();
|
|
||||||
argv++;
|
|
||||||
pingcount = xatoul(*argv);
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
if (--argc <= 0)
|
|
||||||
bb_show_usage();
|
|
||||||
argv++;
|
|
||||||
datalen = xatou16(*argv);
|
|
||||||
break;
|
|
||||||
case 'I':
|
|
||||||
if (--argc <= 0)
|
|
||||||
bb_show_usage();
|
|
||||||
argv++;
|
|
||||||
/* ping6 accepts iface too:
|
|
||||||
if_index = if_nametoindex(*argv);
|
|
||||||
if (!if_index) ...
|
|
||||||
make it true for ping too. TODO.
|
|
||||||
*/
|
|
||||||
if (parse_nipquad(*argv, &sourceaddr))
|
|
||||||
bb_show_usage();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
}
|
|
||||||
argc--;
|
|
||||||
argv++;
|
|
||||||
}
|
}
|
||||||
if (argc < 1)
|
|
||||||
bb_show_usage();
|
|
||||||
|
|
||||||
myid = (int16_t) getpid();
|
myid = (int16_t) getpid();
|
||||||
ping(*argv);
|
ping(argv[optind]);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
#endif /* ! CONFIG_FEATURE_FANCY_PING */
|
#endif /* ! CONFIG_FEATURE_FANCY_PING */
|
||||||
|
@ -53,19 +53,12 @@ enum {
|
|||||||
PINGINTERVAL = 1 /* second */
|
PINGINTERVAL = 1 /* second */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define O_QUIET (1 << 0)
|
|
||||||
#define O_VERBOSE (1 << 1)
|
|
||||||
|
|
||||||
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
|
|
||||||
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
|
|
||||||
#define SET(bit) (A(bit) |= B(bit))
|
|
||||||
#define CLR(bit) (A(bit) &= (~B(bit)))
|
|
||||||
#define TST(bit) (A(bit) & B(bit))
|
|
||||||
|
|
||||||
static void ping(const char *host);
|
static void ping(const char *host);
|
||||||
|
|
||||||
/* simple version */
|
|
||||||
#ifndef CONFIG_FEATURE_FANCY_PING6
|
#ifndef CONFIG_FEATURE_FANCY_PING6
|
||||||
|
|
||||||
|
/* simple version */
|
||||||
|
|
||||||
static struct hostent *h;
|
static struct hostent *h;
|
||||||
|
|
||||||
static void noresp(int ign)
|
static void noresp(int ign)
|
||||||
@ -142,14 +135,22 @@ int ping6_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else /* ! CONFIG_FEATURE_FANCY_PING6 */
|
#else /* ! CONFIG_FEATURE_FANCY_PING6 */
|
||||||
|
|
||||||
/* full(er) version */
|
/* full(er) version */
|
||||||
|
|
||||||
|
#define OPT_STRING "qvc:s:I:"
|
||||||
|
enum {
|
||||||
|
OPT_QUIET = 1 << 0,
|
||||||
|
OPT_VERBOSE = 1 << 1,
|
||||||
|
};
|
||||||
|
|
||||||
static struct sockaddr_in6 pingaddr;
|
static struct sockaddr_in6 pingaddr;
|
||||||
static int pingsock = -1;
|
static int pingsock = -1;
|
||||||
static unsigned datalen; /* intentionally uninitialized to work around gcc bug */
|
static unsigned datalen; /* intentionally uninitialized to work around gcc bug */
|
||||||
static int if_index;
|
static int if_index;
|
||||||
|
|
||||||
static unsigned long ntransmitted, nreceived, nrepeats, pingcount;
|
static unsigned long ntransmitted, nreceived, nrepeats, pingcount;
|
||||||
static int myid, options;
|
static int myid;
|
||||||
static unsigned long tmin = ULONG_MAX, tmax, tsum;
|
static unsigned long tmin = ULONG_MAX, tmax, tsum;
|
||||||
static char rcvd_tbl[MAX_DUP_CHK / 8];
|
static char rcvd_tbl[MAX_DUP_CHK / 8];
|
||||||
|
|
||||||
@ -159,6 +160,12 @@ static void sendping(int);
|
|||||||
static void pingstats(int);
|
static void pingstats(int);
|
||||||
static void unpack(char *, int, struct sockaddr_in6 *, int);
|
static void unpack(char *, int, struct sockaddr_in6 *, int);
|
||||||
|
|
||||||
|
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
|
||||||
|
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
|
||||||
|
#define SET(bit) (A(bit) |= B(bit))
|
||||||
|
#define CLR(bit) (A(bit) &= (~B(bit)))
|
||||||
|
#define TST(bit) (A(bit) & B(bit))
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
||||||
static void pingstats(int junk)
|
static void pingstats(int junk)
|
||||||
@ -294,7 +301,7 @@ static void unpack(char *packet, int sz, struct sockaddr_in6 *from, int hoplimit
|
|||||||
dupflag = 0;
|
dupflag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options & O_QUIET)
|
if (option_mask32 & OPT_QUIET)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf("%d bytes from %s: icmp6_seq=%u", sz,
|
printf("%d bytes from %s: icmp6_seq=%u", sz,
|
||||||
@ -336,7 +343,7 @@ static void ping(const char *host)
|
|||||||
#ifdef ICMP6_FILTER
|
#ifdef ICMP6_FILTER
|
||||||
{
|
{
|
||||||
struct icmp6_filter filt;
|
struct icmp6_filter filt;
|
||||||
if (!(options & O_VERBOSE)) {
|
if (!(option_mask32 & OPT_VERBOSE)) {
|
||||||
ICMP6_FILTER_SETBLOCKALL(&filt);
|
ICMP6_FILTER_SETBLOCKALL(&filt);
|
||||||
ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filt);
|
ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filt);
|
||||||
} else {
|
} else {
|
||||||
@ -416,57 +423,24 @@ static void ping(const char *host)
|
|||||||
|
|
||||||
int ping6_main(int argc, char **argv)
|
int ping6_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *thisarg;
|
char *opt_c, *opt_s, *opt_I;
|
||||||
|
|
||||||
datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
|
datalen = DEFDATALEN; /* initialized here rather than in global scope to work around gcc bug */
|
||||||
|
|
||||||
argc--;
|
/* exactly one argument needed, -v and -q don't mix */
|
||||||
argv++;
|
opt_complementary = "=1:q--v:v--q";
|
||||||
/* Parse any options */
|
getopt32(argc, argv, OPT_STRING, &opt_c, &opt_s, &opt_I);
|
||||||
while (argc >= 1 && **argv == '-') {
|
if (option_mask32 & 4) pingcount = xatoul(opt_c); // -c
|
||||||
thisarg = *argv;
|
if (option_mask32 & 8) datalen = xatou16(opt_s); // -s
|
||||||
thisarg++;
|
if (option_mask32 & 0x10) { // -I
|
||||||
switch (*thisarg) {
|
if_index = if_nametoindex(opt_I);
|
||||||
case 'v':
|
if (!if_index)
|
||||||
options &= ~O_QUIET;
|
bb_error_msg_and_die(
|
||||||
options |= O_VERBOSE;
|
"%s: invalid interface name", opt_I);
|
||||||
break;
|
|
||||||
case 'q':
|
|
||||||
options &= ~O_VERBOSE;
|
|
||||||
options |= O_QUIET;
|
|
||||||
break;
|
|
||||||
case 'c':
|
|
||||||
if (--argc <= 0)
|
|
||||||
bb_show_usage();
|
|
||||||
argv++;
|
|
||||||
pingcount = xatoul(*argv);
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
if (--argc <= 0)
|
|
||||||
bb_show_usage();
|
|
||||||
argv++;
|
|
||||||
datalen = xatou16(*argv);
|
|
||||||
break;
|
|
||||||
case 'I':
|
|
||||||
if (--argc <= 0)
|
|
||||||
bb_show_usage();
|
|
||||||
argv++;
|
|
||||||
if_index = if_nametoindex(*argv);
|
|
||||||
if (!if_index)
|
|
||||||
bb_error_msg_and_die(
|
|
||||||
"%s: invalid interface name", *argv);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
|
||||||
argc--;
|
|
||||||
argv++;
|
|
||||||
}
|
}
|
||||||
if (argc < 1)
|
|
||||||
bb_show_usage();
|
|
||||||
|
|
||||||
myid = (int16_t) getpid();
|
myid = (int16_t)getpid();
|
||||||
ping(*argv);
|
ping(argv[optind]);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
#endif /* ! CONFIG_FEATURE_FANCY_PING6 */
|
#endif /* ! CONFIG_FEATURE_FANCY_PING6 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user