From de9fad8d6741d55c32df6ccc00b72e49c3fe36de Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 31 May 2015 17:57:31 -0500 Subject: [PATCH] More small changes for GNO and ORCA/C compatibility. In particular, address a couple instances where GNO's sockets implementation doesn't comply with modern standards. Also, add a few missing prototypes so we can use ORCA/C prototype-checking lint functionality. --- Makefile.mk | 8 ++++---- libtelnet/getaddrinfo.h | 3 +++ sys/cdefs.h | 9 +++++++++ telnet/commands.c | 19 ++++++++++++++----- telnetd/telnetd.c | 6 +++++- telnetd/utility.c | 2 +- 6 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 sys/cdefs.h diff --git a/Makefile.mk b/Makefile.mk index 38b50c8..9d3129c 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -1,12 +1,12 @@ .INCLUDE: Makefile.common -# This should be the ltermcap from GNO 2.0.4. The one from 2.0.6 is broken -# (links to unimplemented functions), so don't use it. +# /usr/lib/libtermcap.204 should be the ltermcap from GNO 2.0.4. The one +# from 2.0.6 is broken (links to unimplemented functions), so don't use it. # The 2.0.4 version is in the "lib.shk" file within # ftp://ftp.gno.org/pub/apple2/gs.specific/gno/base/v204/gnodisk1.sdk -LIBS = -l/usr/lib/libtermcap.204 +LIBS = -l/usr/lib/libtermcap.204 -l/usr/lib/libnetdb -CFLAGS = -i +CFLAGS = -i -w $(OBJS): $(HEADERS) %.o: %.c diff --git a/libtelnet/getaddrinfo.h b/libtelnet/getaddrinfo.h index ab8ec67..334bb22 100644 --- a/libtelnet/getaddrinfo.h +++ b/libtelnet/getaddrinfo.h @@ -50,6 +50,9 @@ #ifdef __GNO__ typedef int socklen_t; typedef unsigned short in_port_t; +/* GNO calls actually expect an older form of "struct sockaddr", + * different from the "struct sockaddr" defined in the headers. */ +# define sockaddr __SOCKADDR #endif /********************************************************************/ diff --git a/sys/cdefs.h b/sys/cdefs.h new file mode 100644 index 0000000..d16fa0e --- /dev/null +++ b/sys/cdefs.h @@ -0,0 +1,9 @@ +/* We use this as a hack to define stuff in every file, since they all + * #include first. When compiling with occ, this file will + * be included in preference to the system header of the same name. */ + +#ifdef __GNO__ +# define __unused +#endif + +#include "/usr/include/sys/cdefs.h" diff --git a/telnet/commands.c b/telnet/commands.c index 932dfd8..9d47c17 100644 --- a/telnet/commands.c +++ b/telnet/commands.c @@ -432,8 +432,7 @@ send_docmd(char *name) } static int -send_dontcmd(name) - char *name; +send_dontcmd(char *name) { return(send_tncmd(send_dont, "dont", name)); } @@ -1386,7 +1385,7 @@ shell(int argc, char **argv __unused) _exit(1); } default: - (void)wait((int *)0); /* Wait for the shell to complete */ + (void)wait(NULL); /* Wait for the shell to complete */ if (TerminalWindowSize(&newrows, &newcols) && connected && (err_ || ((oldrows != newrows) || (oldcols != newcols)))) { @@ -2101,7 +2100,12 @@ static const char * sockaddr_ntop(struct sockaddr *sa) { void *addr; +#if !defined(__GNO__) || defined(INET6) static char addrbuf[INET6_ADDRSTRLEN]; +#else + /* Since we don't have IPv6, the IPv4 size is sufficient. */ + static char addrbuf[16]; +#endif switch (sa->sa_family) { case AF_INET: @@ -2341,7 +2345,12 @@ tn(int argc, char **argv) int gni_err = 1; if (doaddrlookup) - gni_err = getnameinfo(res->ai_addr, res->ai_addr->sa_len, + gni_err = getnameinfo(res->ai_addr, +#ifndef __GNO__ + res->ai_addr->sa_len, +#else + sizeof(struct sockaddr), +#endif _hostname, sizeof(_hostname) - 1, NULL, 0, NI_NAMEREQD); if (gni_err != 0) @@ -2690,7 +2699,7 @@ command(int top, const char *tbuf, int cnt) * Help command. */ static int -help(int argc, char *argv[]) +help(int argc, char **argv) { Command *c; diff --git a/telnetd/telnetd.c b/telnetd/telnetd.c index fd8667e..0342d4e 100644 --- a/telnetd/telnetd.c +++ b/telnetd/telnetd.c @@ -44,6 +44,10 @@ static const char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95"; #ifdef __GNO__ #include "libtelnet/getaddrinfo.h" +/* GNO doesn't have struct sockaddr_storage; just use "struct sockaddr" + * (which is really struct osockaddr). */ +#define sockaddr_storage sockaddr +#define ss_family sa_family #endif #include @@ -418,7 +422,7 @@ main(int argc, char *argv[]) } /* end of main */ void -usage() +usage(void) { fprintf(stderr, "usage: telnetd"); #ifdef AUTHENTICATION diff --git a/telnetd/utility.c b/telnetd/utility.c index ae5f280..5b6f7eb 100644 --- a/telnetd/utility.c +++ b/telnetd/utility.c @@ -68,7 +68,7 @@ static const char sccsid[] = "@(#)utility.c 8.4 (Berkeley) 5/30/95"; */ void -ttloop() +ttloop(void) { DIAG(TD_REPORT, output_data("td: ttloop\r\n"));