ping/ping6: Use getopt_r and make main unique for RTEMS

This commit is contained in:
Joel Sherrill 2012-08-31 19:33:20 -05:00
parent 1f877f9d52
commit 234dfb80b5
2 changed files with 39 additions and 0 deletions

View File

@ -1,3 +1,7 @@
#ifdef __rtems__
#define __need_getopt_newlib
#include <getopt.h>
#endif
/* /*
* Copyright (c) 1989, 1993 * Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
@ -225,7 +229,11 @@ static void tvsub(struct timeval *, struct timeval *);
static void usage(void) __dead2; static void usage(void) __dead2;
int int
#ifdef __rtems__
main_ping(argc, argv)
#else
main(argc, argv) main(argc, argv)
#endif
int argc; int argc;
char *const *argv; char *const *argv;
{ {
@ -254,6 +262,9 @@ main(argc, argv)
char rspace[MAX_IPOPTLEN]; /* record route space */ char rspace[MAX_IPOPTLEN]; /* record route space */
#endif #endif
unsigned char loop, mttl; unsigned char loop, mttl;
#ifdef __rtems__
struct getopt_data getopt_reent;
#endif
payload = source = NULL; payload = source = NULL;
#ifdef IPSEC_POLICY_IPSEC #ifdef IPSEC_POLICY_IPSEC
@ -274,13 +285,21 @@ main(argc, argv)
alarmtimeout = df = preload = tos = 0; alarmtimeout = df = preload = tos = 0;
outpack = outpackhdr + sizeof(struct ip); outpack = outpackhdr + sizeof(struct ip);
#ifdef __rtems__
memset(&getopt_reent, 0, sizeof(getopt_data));
while ((ch = getopt_r(argc, argv,
#else
while ((ch = getopt(argc, argv, while ((ch = getopt(argc, argv,
#endif
"Aac:DdfG:g:h:I:i:Ll:M:m:nop:QqRrS:s:T:t:vW:z:" "Aac:DdfG:g:h:I:i:Ll:M:m:nop:QqRrS:s:T:t:vW:z:"
#ifdef IPSEC #ifdef IPSEC
#ifdef IPSEC_POLICY_IPSEC #ifdef IPSEC_POLICY_IPSEC
"P:" "P:"
#endif /*IPSEC_POLICY_IPSEC*/ #endif /*IPSEC_POLICY_IPSEC*/
#endif /*IPSEC*/ #endif /*IPSEC*/
#ifdef __rtems__
, &getopt_reent
#endif
)) != -1) )) != -1)
{ {
switch(ch) { switch(ch) {

View File

@ -1,5 +1,8 @@
#ifdef __rtems__ #ifdef __rtems__
#define USE_RFC2292BIS #define USE_RFC2292BIS
#define __need_getopt_newlib
#include <getopt.h>
#endif #endif
/* $KAME: ping6.c,v 1.169 2003/07/25 06:01:47 itojun Exp $ */ /* $KAME: ping6.c,v 1.169 2003/07/25 06:01:47 itojun Exp $ */
@ -263,7 +266,11 @@ volatile sig_atomic_t seenint;
volatile sig_atomic_t seeninfo; volatile sig_atomic_t seeninfo;
#endif #endif
#ifdef __rtems__
int main_ping6(int, char *[]);
#else
int main(int, char *[]); int main(int, char *[]);
#endif
void fill(char *, char *); void fill(char *, char *);
int get_hoplim(struct msghdr *); int get_hoplim(struct msghdr *);
int get_pathmtu(struct msghdr *); int get_pathmtu(struct msghdr *);
@ -295,7 +302,11 @@ char *nigroup(char *);
void usage(void); void usage(void);
int int
#ifdef __rtems__
main_ping6(argc, argv)
#else
main(argc, argv) main(argc, argv)
#endif
int argc; int argc;
char *argv[]; char *argv[];
{ {
@ -341,6 +352,9 @@ main(argc, argv)
#ifdef IPV6_USE_MIN_MTU #ifdef IPV6_USE_MIN_MTU
int mflag = 0; int mflag = 0;
#endif #endif
#ifdef __rtems__
struct getopt_data getopt_reent;
#endif
/* just to be sure */ /* just to be sure */
memset(&smsghdr, 0, sizeof(smsghdr)); memset(&smsghdr, 0, sizeof(smsghdr));
@ -357,8 +371,14 @@ main(argc, argv)
#define ADDOPTS "AE" #define ADDOPTS "AE"
#endif /*IPSEC_POLICY_IPSEC*/ #endif /*IPSEC_POLICY_IPSEC*/
#endif #endif
#ifdef __rtems__
memset(&getopt_reent, 0, sizeof(getopt_data));
while ((ch = getopt_r(argc, argv,
"a:b:c:DdfHg:h:I:i:l:mnNop:qrRS:s:tvwW" ADDOPTS, &getopt_reent)) != -1) {
#else
while ((ch = getopt(argc, argv, while ((ch = getopt(argc, argv,
"a:b:c:DdfHg:h:I:i:l:mnNop:qrRS:s:tvwW" ADDOPTS)) != -1) { "a:b:c:DdfHg:h:I:i:l:mnNop:qrRS:s:tvwW" ADDOPTS)) != -1) {
#endif
#undef ADDOPTS #undef ADDOPTS
switch (ch) { switch (ch) {
case 'a': case 'a':