<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 15, 2021 at 10:25 AM Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fri, Jun 11, 2021 at 11:19 AM Stephen Clark<br>
<<a href="mailto:stephen.clark@oarcorp.com" target="_blank">stephen.clark@oarcorp.com</a>> wrote:<br>
><br>
> Updated ttcp.c to build for RTEMS 6, in addition to the machines<br>
> it originally built for. Also fixed ttcp.c to close network sockets<br>
> after completion. Defined a shell command for TTCP in<br>
> rtems-bsd-shell-ttcp.c. Added TTCP to the list of RTEMS network<br>
> commands in netcmds-config.h. Added declaration of the TTCP shell<br>
> command to rtems-bsd-commands.h. Modified libbsd.py to make waf<br>
> build TTCP and its shell command.<br>
> ---<br>
> libbsd.py | 2 +<br>
> rtemsbsd/include/machine/rtems-bsd-commands.h | 2 +<br>
> rtemsbsd/include/rtems/netcmds-config.h | 2 +<br>
> rtemsbsd/rtems/rtems-bsd-shell-ttcp.c | 39 +++<br>
> rtemsbsd/ttcp/README | 11 +-<br>
> rtemsbsd/ttcp/ttcp.c | 266 ++++++++++++++----<br>
> 6 files changed, 262 insertions(+), 60 deletions(-)<br>
> create mode 100644 rtemsbsd/rtems/rtems-bsd-shell-ttcp.c<br>
><br>
> diff --git a/libbsd.py b/libbsd.py<br>
> index b367d94e..2badfdee 100644<br>
> --- a/libbsd.py<br>
> +++ b/libbsd.py<br>
> @@ -269,6 +269,7 @@ class rtems(builder.Module):<br>
> 'rtems/rtems-bsd-shell-tcpdump.c',<br>
> 'rtems/rtems-bsd-shell-vmstat.c',<br>
> 'rtems/rtems-bsd-shell-wlanstats.c',<br>
> + 'rtems/rtems-bsd-shell-ttcp.c',<br>
> 'rtems/rtems-kvm.c',<br>
> 'rtems/rtems-program.c',<br>
> 'rtems/rtems-program-socket.c',<br>
> @@ -292,6 +293,7 @@ class rtems(builder.Module):<br>
> 'pppd/upap.c',<br>
> 'pppd/utils.c',<br>
> 'telnetd/telnetd-service.c',<br>
> + 'ttcp/ttcp.c',<br>
> ],<br>
> mm.generator['source']()<br>
> )<br>
> diff --git a/rtemsbsd/include/machine/rtems-bsd-commands.h b/rtemsbsd/include/machine/rtems-bsd-commands.h<br>
> index d314471f..d82c274c 100644<br>
> --- a/rtemsbsd/include/machine/rtems-bsd-commands.h<br>
> +++ b/rtemsbsd/include/machine/rtems-bsd-commands.h<br>
> @@ -84,6 +84,8 @@ int rtems_bsd_command_setkey(int argc, char **argv);<br>
><br>
> int rtems_bsd_command_openssl(int argc, char **argv);<br>
><br>
> +int rtems_shell_main_ttcp(int argc, char **argv);<br>
> +<br>
> __END_DECLS<br>
><br>
> #endif /* _RTEMS_BSD_MACHINE_RTEMS_BSD_COMMANDS_H_ */<br>
> diff --git a/rtemsbsd/include/rtems/netcmds-config.h b/rtemsbsd/include/rtems/netcmds-config.h<br>
> index bc493af4..c1d56eb3 100644<br>
> --- a/rtemsbsd/include/rtems/netcmds-config.h<br>
> +++ b/rtemsbsd/include/rtems/netcmds-config.h<br>
> @@ -29,6 +29,8 @@ extern rtems_shell_cmd_t rtems_shell_PFCTL_Command;<br>
> extern rtems_shell_cmd_t rtems_shell_PING_Command;<br>
> extern rtems_shell_cmd_t rtems_shell_PING6_Command;<br>
><br>
> +extern rtems_shell_cmd_t rtems_shell_TTCP_Command;<br>
> +<br>
> extern rtems_shell_cmd_t rtems_shell_IFCONFIG_Command;<br>
><br>
> extern rtems_shell_cmd_t rtems_shell_IFMCSTAT_Command;<br>
> diff --git a/rtemsbsd/rtems/rtems-bsd-shell-ttcp.c b/rtemsbsd/rtems/rtems-bsd-shell-ttcp.c<br>
> new file mode 100644<br>
> index 00000000..babaa011<br>
> --- /dev/null<br>
> +++ b/rtemsbsd/rtems/rtems-bsd-shell-ttcp.c<br>
> @@ -0,0 +1,39 @@<br>
> +/* SPDX-License-Identifier: BSD-2-Clause */<br>
> +<br>
> +/*<br>
> + * COPYRIGHT (c) 2021. On-Line Applications Research Corporation (OAR).<br>
> + * All rights reserved.<br>
> + *<br>
> + * Redistribution and use in source and binary forms, with or without<br>
> + * modification, are permitted provided that the following conditions<br>
> + * are met:<br>
> + * 1. Redistributions of source code must retain the above copyright<br>
> + * notice, this list of conditions and the following disclaimer.<br>
> + * 2. Redistributions in binary form must reproduce the above copyright<br>
> + * notice, this list of conditions and the following disclaimer in the<br>
> + * documentation and/or other materials provided with the distribution.<br>
> + *<br>
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND<br>
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE<br>
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL<br>
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS<br>
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br>
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT<br>
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY<br>
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF<br>
> + * SUCH DAMAGE.<br>
> + */<br>
> +<br>
> +#include <rtems/netcmds-config.h><br>
> +#include <machine/rtems-bsd-commands.h><br>
> +<br>
> +rtems_shell_cmd_t rtems_shell_TTCP_Command = {<br>
> + "ttcp", /* name */<br>
> + "ttcp -h # to get help", /* usage */<br>
> + "net", /* topic */<br>
> + rtems_shell_main_ttcp, /* command */<br>
> + NULL, /* alias */<br>
> + NULL /* next */<br>
> +};<br>
> diff --git a/rtemsbsd/ttcp/README b/rtemsbsd/ttcp/README<br>
> index 215ddacc..8a9bf017 100644<br>
> --- a/rtemsbsd/ttcp/README<br>
> +++ b/rtemsbsd/ttcp/README<br>
> @@ -7,14 +7,9 @@ but please do leave the credit notices in the source and man page intact.<br>
><br>
> Contents of this directory:<br>
><br>
> -ttcp.c Source that runs on IRIX 3.3.x and 4.0.x systems<br>
> - and BSD-based systems. This version also uses getopt(3)<br>
> - and has 2 new options: -f and -T.<br>
> -<br>
> -ttcp.c-brl Original source from BRL.<br>
> -<br>
> -ttcp.1 Manual page (describes ttcp.c options, which are a<br>
> - superset of the other version).<br>
> +ttcp.c Source that runs on IRIX 3.3.x and 4.0.x systems,<br>
> + BSD-based systems, and RTEMS. This version also<br>
> + uses getopt(3) and has 2 new options: -f and -T.<br>
><br>
><br>
> How to get TCP performance numbers:<br>
> diff --git a/rtemsbsd/ttcp/ttcp.c b/rtemsbsd/ttcp/ttcp.c<br>
> index dc62c64b..46e0f3fc 100644<br>
> --- a/rtemsbsd/ttcp/ttcp.c<br>
> +++ b/rtemsbsd/ttcp/ttcp.c<br>
> @@ -74,48 +74,95 @@ struct rusage {<br>
> #include <sys/resource.h><br>
> #endif<br>
><br>
> -struct sockaddr_in sinme;<br>
> -struct sockaddr_in sinhim;<br>
> -struct sockaddr_in frominet;<br>
> +#if defined(__rtems__)<br>
> +#define __need_getopt_newlib<br>
> +#include <getopt.h><br>
> +#include <rtems/shell.h><br>
> +#endif<br>
> +<br>
> +static struct sockaddr_in sinme;<br>
> +static struct sockaddr_in sinhim;<br>
> +static struct sockaddr_in frominet;<br>
><br>
Are some of these changes in line with an upstream copy? Are you<br>
trying to use the __rtems__ guards to demark the RTEMS-specific<br>
changes from the upstream copy?<br>
<br>
Usually we would prefer to have all the upstream code added, and then<br>
add the __rtems__parts, and then add the code to the build system.<br>
Would that be possible and the right thing to do in this case also?<br>
<br>
> /* these make it easier to avoid warnings */<br>
> -struct sockaddr *sinhim_p = (struct sockaddr *) &sinhim;<br>
> -struct sockaddr *sinme_p = (struct sockaddr *) &sinme;<br>
> -struct sockaddr *frominet_p = (struct sockaddr *) &frominet;<br>
> -<br>
> -int domain;<br>
> -socklen_t fromlen;<br>
> -int fd; /* fd of network socket */<br>
> -<br>
> -int buflen = 8 * 1024; /* length of buffer */<br>
> -char *buf; /* ptr to dynamic buffer */<br>
> -int nbuf = 2 * 1024; /* number of buffers to send in sinkmode */<br>
> -<br>
> -int bufoffset = 0; /* align buffer to this */<br>
> -int bufalign = 16*1024; /* modulo this */<br>
> -<br>
> -int udp = 0; /* 0 = tcp, !0 = udp */<br>
> -int options = 0; /* socket options */<br>
> -int one = 1; /* for 4.3 BSD style setsockopt() */<br>
> -short port = 5001; /* TCP port number */<br>
> -char *host; /* ptr to name of host */<br>
> -int trans; /* 0=receive, !0=transmit mode */<br>
> -int sinkmode = 0; /* 0=normal I/O, !0=sink/source mode */<br>
> -int verbose = 0; /* 0=print basic info, 1=print cpu rate, proc<br>
> +static struct sockaddr *sinhim_p = (struct sockaddr *) &sinhim;<br>
> +static struct sockaddr *sinme_p = (struct sockaddr *) &sinme;<br>
> +static struct sockaddr *frominet_p = (struct sockaddr *) &frominet;<br>
> +<br>
> +static int domain;<br>
> +static socklen_t fromlen;<br>
> +static int fd; /* fd of network socket */<br>
> +<br>
> +static int buflen = 8 * 1024; /* length of buffer */<br>
> +static char *buf; /* ptr to dynamic buffer */<br>
> +static char *alloc_buf; /* ptr to beginning of memory allocated for buf */<br>
> +static int nbuf = 2 * 1024; /* number of buffers to send in sinkmode */<br>
> +<br>
> +static int bufoffset = 0; /* align buffer to this */<br>
> +static int bufalign = 16*1024; /* modulo this */<br>
> +<br>
> +static int udp = 0; /* 0 = tcp, !0 = udp */<br>
> +static int options = 0; /* socket options */<br>
> +static int one = 1; /* for 4.3 BSD style setsockopt() */<br>
> +static short port = 5001; /* TCP port number */<br>
> +static char *host; /* ptr to name of host */<br>
> +static int trans; /* 0=receive, !0=transmit mode */<br>
> +static int sinkmode = 0; /* 0=normal I/O, !0=sink/source mode */<br>
> +static int verbose = 0; /* 0=print basic info, 1=print cpu rate, proc<br>
> * resource usage. */<br>
> -int nodelay = 0; /* set TCP_NODELAY socket option */<br>
> -int b_flag = 0; /* use mread() */<br>
> -int sockbufsize = 0; /* socket buffer size to use */<br>
> -char fmt = 'K'; /* output format: k = kilobits, K = kilobytes,<br>
> +static int nodelay = 0; /* set TCP_NODELAY socket option */<br>
> +static int b_flag = 0; /* use mread() */<br>
> +static int sockbufsize = 0; /* socket buffer size to use */<br>
> +static char fmt = 'K'; /* output format: k = kilobits, K = kilobytes,<br>
> * m = megabits, M = megabytes,<br>
> * g = gigabits, G = gigabytes */<br>
> -int touchdata = 0; /* access data after reading */<br>
> -long milliseconds = 0; /* delay in milliseconds */<br>
> +static int touchdata = 0; /* access data after reading */<br>
> +static long milliseconds = 0; /* delay in milliseconds */<br>
><br>
> -struct hostent *addr;<br>
> -extern int errno;<br>
> -extern int optind;<br>
> -extern char *optarg;<br>
> +static struct hostent *addr;<br>
> +static void initialize_vars(void)<br>
> +{<br>
> + memset(&sinme, 0, sizeof(sinme));<br>
> + memset(&sinhim, 0, sizeof(sinhim));<br>
> + memset(&frominet, 0, sizeof(frominet));<br>
> +<br>
> + /* these make it easier to avoid warnings */<br>
> + sinhim_p = (struct sockaddr *) &sinhim;<br>
> + sinme_p = (struct sockaddr *) &sinme;<br>
> + frominet_p = (struct sockaddr *) &frominet;<br>
> +<br>
> + domain = 0;<br>
> + fromlen = 0;<br>
> + fd = 0; /* fd of network socket */<br>
> +<br>
> + buflen = 8 * 1024; /* length of buffer */<br>
> + buf = NULL; /* ptr to dynamic buffer */<br>
> + alloc_buf = NULL; /* ptr to beginning of memory allocated for buf */<br>
> + nbuf = 2 * 1024; /* number of buffers to send in sinkmode */<br>
> +<br>
> + bufoffset = 0; /* align buffer to this */<br>
> + bufalign = 16*1024; /* modulo this */<br>
> +<br>
> + udp = 0; /* 0 = tcp, !0 = udp */<br>
> + options = 0; /* socket options */<br>
> + one = 1; /* for 4.3 BSD style setsockopt() */<br>
> + port = 5001; /* TCP port number */<br>
> + host = NULL; /* ptr to name of host */<br>
> + trans = 0; /* 0=receive, !0=transmit mode */<br>
> + sinkmode = 0; /* 0=normal I/O, !0=sink/source mode */<br>
> + verbose = 0; /* 0=print basic info, 1=print cpu rate, proc<br>
> + * resource usage. */<br>
> + nodelay = 0; /* set TCP_NODELAY socket option */<br>
> + b_flag = 0; /* use mread() */<br>
> + sockbufsize = 0; /* socket buffer size to use */<br>
> + fmt = 'K'; /* output format: k = kilobits, K = kilobytes,<br>
> + * m = megabits, M = megabytes,<br>
> + * g = gigabits, G = gigabytes */<br>
> + touchdata = 0; /* access data after reading */<br>
> + milliseconds = 0; /* delay in milliseconds */<br>
> +<br>
> + addr = NULL;<br>
> +}<br>
><br>
> char Usage[] = "\<br>
> Usage: ttcp -t [-options] host [ < in ]\n\<br>
> @@ -173,16 +220,34 @@ void millisleep(long msec)<br>
> nanosleep( &req, NULL );<br>
> #endif<br>
> }<br>
> +<br>
Avoid making own changes outside of the __rtems__ guards if you're<br>
trying to preserve compatibility with the upstream. Please read<br>
contributing.md.<br></blockquote><div><br></div><div>This one is a weird case. To run the ttcp benchmark, you must have two</div><div>systems running it. One is the Tx and the other is the Rx. This usually </div><div>means you are running TTCP on your RTEMS target and on your development</div><div>system. Some of these are needed to be clean on the native build. Other</div><div>parts are specific to RTEMS.</div><div><br></div><div>As you can tell from the date on the code it is quite old and it is questionable</div><div>if there is a maintained upstream.for this implementation. In answering this,</div><div>I found <a href="https://en.wikipedia.org/wiki/Ttcp">https://en.wikipedia.org/wiki/Ttcp</a> which points to <a href="http://nuttcp.net">nuttcp.net</a> and that</div><div>appears to be maintained since there was a release last year. But that's GPLv2</div><div>so we won't be using that. </div><div><br></div><div>We need some changes to make it clean natively and some to make it work</div><div>on RTEMS. And I don't think there is really an active upstream for this. This</div><div>was a new port based on newer ways of doing things in RTEMS. What</div><div>do you think is best?</div><div><br></div><div>It occurred to me as I typed this that perhaps the native version should</div><div>be built as part of rtems-tools instead of assuming the end user would </div><div>compile this source by hand from libbsd. But then we would be duplicating</div><div>the file.</div><div><br></div><div>Not a good solution all around. I suspect we really cloned and owned.</div><div><br></div><div>--joel</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +#if (defined (__rtems__))<br>
> +int rtems_shell_main_ttcp(argc,argv)<br>
> +#else<br>
> int main(argc,argv)<br>
> +#endif<br>
> int argc;<br>
> char **argv;<br>
> {<br>
> + initialize_vars();<br>
> unsigned long addr_tmp;<br>
> int c;<br>
><br>
> if (argc < 2) goto usage;<br>
><br>
> +#ifdef __rtems__<br>
> + struct getopt_data getopt_reent;<br>
> +#define optarg getopt_reent.optarg<br>
> +#define optind getopt_reent.optind<br>
> +#define opterr getopt.reent.opterr<br>
> +#define optopt getopt.reent.optopt<br>
> + memset(&getopt_reent, 0, sizeof(getopt_data));<br>
> + while ((c = getopt_r(argc, argv,<br>
> + "drstuvBDTb:f:l:m:n:p:A:O:",<br>
> + &getopt_reent)) != -1) {<br>
> +#else<br>
> while ((c = getopt(argc, argv, "drstuvBDTb:f:l:m:n:p:A:O:")) != -1) {<br>
> +#endif<br>
> switch (c) {<br>
><br>
> case 'B':<br>
> @@ -270,8 +335,12 @@ char **argv;<br>
> sinhim.sin_addr.s_addr = inet_addr(host);<br>
> #endif<br>
> } else {<br>
> - if ((addr=gethostbyname(host)) == NULL)<br>
> + if ((addr=gethostbyname(host)) == NULL) {<br>
> err("bad hostname");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
I believe the proper way to do this is<br>
if ((addr=gethostbyname(host)) == NULL)<br>
#ifdef __rtems__<br>
{<br>
#endif /* __rtems__ */<br>
err("bad hostname");<br>
#ifdef __rtems__<br>
return 1;<br>
}<br>
#endif /* __rtems__ */<br>
<br>
or<br>
#ifdef __rtems__<br>
{<br>
err("bad hostname");<br>
return 1;<br>
}<br>
#else /* __rtems__ */<br>
err("bad hostname");<br>
#endif /* __rtems__ */<br>
<br>
> sinhim.sin_family = addr->h_addrtype;<br>
> bcopy(addr->h_addr,(char*)&addr_tmp, addr->h_length);<br>
> #if defined(cray)<br>
> @@ -292,8 +361,13 @@ char **argv;<br>
> buflen = 5; /* send more than the sentinel size */<br>
> }<br>
><br>
> - if ( (buf = (char *)malloc(buflen+bufalign)) == (char *)NULL)<br>
> + if ( (buf = (char *)malloc(buflen+bufalign)) == (char *)NULL) {<br>
> err("malloc");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> + alloc_buf = buf;<br>
> if (bufalign != 0)<br>
> buf +=(bufalign - ((int)buf % bufalign) + bufoffset) % bufalign;<br>
><br>
> @@ -313,24 +387,40 @@ char **argv;<br>
> fprintf(stdout, " %s\n", udp?"udp":"tcp");<br>
> }<br>
><br>
> - if ((fd = socket(AF_INET, udp?SOCK_DGRAM:SOCK_STREAM, 0)) < 0)<br>
> + if ((fd = socket(AF_INET, udp?SOCK_DGRAM:SOCK_STREAM, 0)) < 0) {<br>
> err("socket");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> mes("socket");<br>
><br>
> - if (bind(fd, sinme_p, sizeof(sinme)) < 0)<br>
> + if (bind(fd, sinme_p, sizeof(sinme)) < 0) {<br>
> err("bind");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
><br>
> #if defined(SO_SNDBUF) || defined(SO_RCVBUF)<br>
> if (sockbufsize) {<br>
> if (trans) {<br>
> if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sockbufsize,<br>
> - sizeof sockbufsize) < 0)<br>
> + sizeof sockbufsize) < 0) {<br>
> err("setsockopt: sndbuf");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> mes("sndbuf");<br>
> } else {<br>
> if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &sockbufsize,<br>
> - sizeof sockbufsize) < 0)<br>
> + sizeof sockbufsize) < 0) {<br>
> err("setsockopt: rcvbuf");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> mes("rcvbuf");<br>
> }<br>
> }<br>
> @@ -344,24 +434,36 @@ char **argv;<br>
> /* We are the client if transmitting */<br>
> if (options) {<br>
> #if defined(BSD42)<br>
> - if( setsockopt(fd, SOL_SOCKET, options, 0, 0) < 0)<br>
> + if( setsockopt(fd, SOL_SOCKET, options, 0, 0) < 0) {<br>
> #else /* BSD43 */<br>
> - if( setsockopt(fd, SOL_SOCKET, options, &one, sizeof(one)) < 0)<br>
> + if( setsockopt(fd, SOL_SOCKET, options, &one, sizeof(one)) < 0) {<br>
> #endif<br>
> err("setsockopt");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> }<br>
> #ifdef TCP_NODELAY<br>
> if (nodelay) {<br>
> struct protoent *p;<br>
> p = getprotobyname("tcp");<br>
> if( p && setsockopt(fd, p->p_proto, TCP_NODELAY,<br>
> - &one, sizeof(one)) < 0)<br>
> + &one, sizeof(one)) < 0) {<br>
> err("setsockopt: nodelay");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> mes("nodelay");<br>
> }<br>
> #endif<br>
> - if(connect(fd, sinhim_p, sizeof(sinhim) ) < 0)<br>
> + if(connect(fd, sinhim_p, sizeof(sinhim) ) < 0) {<br>
> err("connect");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> mes("connect");<br>
> } else {<br>
> /* otherwise, we are the server and<br>
> @@ -374,21 +476,41 @@ char **argv;<br>
> #endif<br>
> if(options) {<br>
> #if defined(BSD42)<br>
> - if( setsockopt(fd, SOL_SOCKET, options, 0, 0) < 0)<br>
> + if( setsockopt(fd, SOL_SOCKET, options, 0, 0) < 0) {<br>
> #else /* BSD43 */<br>
> - if( setsockopt(fd, SOL_SOCKET, options, &one, sizeof(one)) < 0)<br>
> + if( setsockopt(fd, SOL_SOCKET, options, &one, sizeof(one)) < 0) {<br>
> #endif<br>
> err("setsockopt");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> }<br>
> fromlen = sizeof(frominet);<br>
> domain = AF_INET;<br>
> - if((fd=accept(fd, frominet_p, &fromlen) ) < 0)<br>
> + int fd_list = fd;<br>
> + if((fd=accept(fd_list, frominet_p, &fromlen) ) < 0) {<br>
> err("accept");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> +<br>
> + if(close(fd_list) < 0) {<br>
> + err("close");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> +<br>
> { struct sockaddr_in peer;<br>
> socklen_t peerlen = sizeof(peer);<br>
> if (getpeername(fd, (struct sockaddr *) &peer,<br>
> &peerlen) < 0) {<br>
> err("getpeername");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> }<br>
> fprintf(stderr,"ttcp-r: accept from %s\n",<br>
> inet_ntoa(peer.sin_addr));<br>
> @@ -438,7 +560,12 @@ char **argv;<br>
> nbytes += cnt;<br>
> }<br>
> }<br>
> - if(errno) err("IO");<br>
> + if(errno) {<br>
> + err("IO");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> (void)read_timer(stats,sizeof(stats));<br>
> if(udp&&trans) {<br>
> (void)Nwrite( fd, buf, 4 ); /* rcvr end */<br>
> @@ -446,6 +573,14 @@ char **argv;<br>
> (void)Nwrite( fd, buf, 4 ); /* rcvr end */<br>
> (void)Nwrite( fd, buf, 4 ); /* rcvr end */<br>
> }<br>
> +<br>
> + if(close(fd) < 0) {<br>
> + err("close");<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#endif<br>
> + }<br>
> +<br>
> if( cput <= 0.0 ) cput = 0.001;<br>
> if( realt <= 0.0 ) realt = 0.001;<br>
> fprintf(stdout,<br>
> @@ -471,22 +606,41 @@ char **argv;<br>
> trans?"-t":"-r",<br>
> buf);<br>
> }<br>
> + free(alloc_buf);<br>
> +#ifdef __rtems__<br>
> + return 0;<br>
> +#else<br>
> exit(0);<br>
> +#endif<br>
><br>
> usage:<br>
> fprintf(stderr,Usage);<br>
> + free(alloc_buf);<br>
> +#ifdef __rtems__<br>
> + return 1;<br>
> +#else<br>
> exit(1);<br>
> - return 0;<br>
> + return 1;<br>
> +#endif<br>
> }<br>
><br>
> void<br>
> -err(s)<br>
> +err(s)<br>
> char *s;<br>
> {<br>
> fprintf(stderr,"ttcp%s: ", trans?"-t":"-r");<br>
> perror(s);<br>
> fprintf(stderr,"errno=%d\n",errno);<br>
> + free(alloc_buf);<br>
> + if (fd != 0)<br>
> + {<br>
> + close(fd);<br>
> + }<br>
> +#ifdef __rtems__<br>
> + return;<br>
> +#else<br>
> exit(1);<br>
> +#endif<br>
> }<br>
><br>
> void<br>
> @@ -540,7 +694,9 @@ double b;<br>
> static struct timeval time0; /* Time at which timing started */<br>
> static struct rusage ru0; /* Resource utilization at the start */<br>
><br>
> +#ifndef __rtems__<br>
> static void prusage();<br>
> +#endif<br>
> static void tvadd();<br>
> static void tvsub();<br>
> static void psecs();<br>
> @@ -601,7 +757,11 @@ int len;<br>
><br>
> getrusage(RUSAGE_SELF, &ru1);<br>
> gettimeofday(&timedol, (struct timezone *)0);<br>
> +#ifndef __rtems__<br>
> prusage(&ru0, &ru1, &timedol, &time0, line);<br>
> +#else<br>
> + line[0] = '\0';<br>
> +#endif<br>
> (void)strncpy( str, line, len );<br>
><br>
> /* Get real time */<br>
> @@ -617,6 +777,7 @@ int len;<br>
> return( cput );<br>
> }<br>
><br>
> +#ifndef __rtems__<br>
> static void<br>
> prusage(r0, r1, e, b, outp)<br>
> register struct rusage *r0, *r1;<br>
> @@ -731,6 +892,7 @@ prusage(r0, r1, e, b, outp)<br>
> }<br>
> *outp = '\0';<br>
> }<br>
> +#endif<br>
><br>
> static void<br>
> tvadd(tsum, t0, t1)<br>
> --<br>
> 2.27.0<br>
><br>
> _______________________________________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div></div>