Import of pkgsrc-2013Q2

This commit is contained in:
2013-09-26 17:14:40 +02:00
commit 785076ae39
74991 changed files with 4380255 additions and 0 deletions

13
sysutils/socket/DESCR Normal file
View File

@@ -0,0 +1,13 @@
This is the README file for Socket-1.1.
What is it?
The program Socket implements access to TCP sockets from shell level.
First written for the need to open a server socket and read and write
to the socket interactively for testing purposes, it quickly evolved
into a generic tool providing the socket interface for shell script
and interactive use.
Please send any comments, suggestions, bug reports etc. to me:
Juergen Nickelsen <jn@berlin.snafu.de>

30
sysutils/socket/Makefile Normal file
View File

@@ -0,0 +1,30 @@
# $NetBSD: Makefile,v 1.18 2012/10/23 19:51:24 asau Exp $
DISTNAME= socket-1.1
CATEGORIES= sysutils net
MASTER_SITES= http://www.freebsd.org/~wosch/src/
MAINTAINER= pkgsrc-users@NetBSD.org
COMMENT= Create tcp socket and connect to stdin/out
LICENSE= gnu-gpl-v2
MAKE_ENV+= INSTALLBASE=${PREFIX:Q}
PKG_OPTIONS_VAR= PKG_OPTIONS.socket
PKG_SUPPORTED_OPTIONS= inet6
PKG_SUGGESTED_OPTIONS= inet6
INSTALLATION_DIRS+= bin ${PKGMANDIR}/man1
.include "../../mk/bsd.options.mk"
###
### IPv6 support
###
.if !empty(PKG_OPTIONS:Minet6)
MAKE_ENV+= SWITCHES="-DUSE_INET6 -DHAVE_SYS_PARAM_H -Wall"
.else
MAKE_ENV+= SWITCHES="-DHAVE_SYS_PARAM_H -Wall"
.endif
.include "../../mk/bsd.pkg.mk"

3
sysutils/socket/PLIST Normal file
View File

@@ -0,0 +1,3 @@
@comment $NetBSD: PLIST,v 1.2 2009/06/12 19:09:38 rillig Exp $
bin/socket
man/man1/socket.1

14
sysutils/socket/distinfo Normal file
View File

@@ -0,0 +1,14 @@
$NetBSD: distinfo,v 1.10 2010/02/04 20:58:45 heinz Exp $
SHA1 (socket-1.1.tar.gz) = 1ada9bc6d949c303734030b3a34e2d6f0544d1db
RMD160 (socket-1.1.tar.gz) = 9a697cbdc807223f48229caa3349cba216b5ffc0
Size (socket-1.1.tar.gz) = 14426 bytes
SHA1 (patch-aa) = d50e202c0599105fbfd8bb446b3b30e79034111c
SHA1 (patch-ab) = a57ef3243601007113f07493201804a6050f3182
SHA1 (patch-ac) = 73d6cabae5eec437edf39ee1cbb8ceea8cbb9f1e
SHA1 (patch-ad) = 034f34565952f94b4e12cf78f0bb9b5612091e4d
SHA1 (patch-ae) = 97bbe5066b8bf00fe45df1c1088768400abf102e
SHA1 (patch-af) = b40a7bbd22a6773816eb0e52403d67317979451d
SHA1 (patch-ag) = e106aac5b193a43ab208b648deadf173a78a6d6d
SHA1 (patch-ah) = 232f359d1c6256266d1dff9c98891ce591ebc13b
SHA1 (patch-ai) = 7bd6114d85d3c62791b29d521f07e3ea77a736d7

View File

@@ -0,0 +1,82 @@
$NetBSD: patch-aa,v 1.7 2010/02/04 20:58:45 heinz Exp $
--- Makefile.orig 1992-09-10 14:59:31.000000000 +0000
+++ Makefile
@@ -8,10 +8,10 @@
### socket.1 in /usr/local/man/man1/socket.1
### Make sure the target directories exist before doing a "make install".
-INSTALLBASE = /usr/local
+INSTALLBASE = ${PREFIX}
INSTALLBINPATH = $(INSTALLBASE)/bin
INSTALLBINMODE = 755
-INSTALLMANPATH = $(INSTALLBASE)/man
+INSTALLMANPATH = $(INSTALLBASE)/$(PKGMANDIR)
INSTALLMANMODE = 444
CC = cc
CFLAGS = $(SWITCHES) -O
@@ -81,27 +81,25 @@ TAGS: $(PROGSOURCES) $(HEADERS)
installtargets: $(INSTALLBINPATH)/$(TARGET) installmanuals
$(INSTALLBINPATH)/$(TARGET): $(TARGET)
- @-echo "installing $(TARGET) in $(INSTALLBINPATH)"; \
- if [ -f $(INSTALLBINPATH)/$(TARGET) ] && \
- [ ! -w $(INSTALLBINPATH)/$(TARGET) ]; \
+ @-echo "installing $(TARGET) in $(DESTDIR)$(INSTALLBINPATH)"; \
+ if [ -f $(DESTDIR)$(INSTALLBINPATH)/$(TARGET) ] && \
+ [ ! -w $(DESTDIR)$(INSTALLBINPATH)/$(TARGET) ]; \
then \
- chmod u+w $(INSTALLBINPATH)/$(TARGET); \
+ chmod u+w $(DESTDIR)$(INSTALLBINPATH)/$(TARGET); \
fi; \
- cp $(TARGET) $(INSTALLBINPATH)/$(TARGET); \
- chmod $(INSTALLBINMODE) $(INSTALLBINPATH)/$(TARGET);
+ $(BSD_INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(INSTALLBINPATH)/$(TARGET)
installmanuals: $(MANUALS)
@-_manuals="$(MAN1)"; \
for i in $$_manuals; \
do \
- echo "installing $$i in $(INSTALLMANPATH)/man1"; \
- if [ -f $(INSTALLMANPATH)/man1/$$i ] && \
- [ ! -w $(INSTALLMANPATH)/man1/$$i ]; \
+ echo "installing $$i in $(DESTDIR)$(INSTALLMANPATH)/man1"; \
+ if [ -f $(DESTDIR)$(INSTALLMANPATH)/man1/$$i ] && \
+ [ ! -w $(DESTDIR)$(INSTALLMANPATH)/man1/$$i ]; \
then \
- chmod u+w $(INSTALLMANPATH)/man1/$$i; \
+ chmod u+w $(DESTDIR)$(INSTALLMANPATH)/man1/$$i; \
fi; \
- cp $$i $(INSTALLMANPATH)/man1/$$i; \
- chmod $(INSTALLMANMODE) $(INSTALLMANPATH)/man1/$$i; \
+ $(BSD_INSTALL_MAN) $$i $(DESTDIR)$(INSTALLMANPATH)/man1/$$i; \
done
doclean:
@@ -117,7 +115,7 @@ install: +install $(ALLTARGETS)
clean: +clean $(ALLTARGETS)
+all:
- @-if [ -n "$(ALLTARGETS)" ]; \
+ @if [ -n "$(ALLTARGETS)" ]; \
then : ; \
else \
$(MAKE) ALLTARGETS="subsystems targets" MAINTARGET=all \
@@ -137,7 +135,7 @@ clean: +clean $(ALLTARGETS)
fi
+install:
- @-if [ -n "$(ALLTARGETS)" ]; \
+ @if [ -n "$(ALLTARGETS)" ]; \
then : ; \
else \
$(MAKE) ALLTARGETS="subsystems installtargets" \
@@ -158,7 +156,7 @@ clean: +clean $(ALLTARGETS)
fi
+clean:
- @-if [ -n "$(ALLTARGETS)" ]; \
+ @if [ -n "$(ALLTARGETS)" ]; \
then : ; \
else \
$(MAKE) ALLTARGETS="subsystems doclean" MAINTARGET=clean \

View File

@@ -0,0 +1,10 @@
$NetBSD: patch-ab,v 1.1 1999/02/02 23:00:40 tron Exp $
--- README.orig Wed Sep 9 16:45:16 1992
+++ README Tue Feb 2 23:52:02 1999
@@ -166,4 +166,4 @@
1000 Berlin 10
Germany
- <nickel@cs.tu-berlin.de>
+Juergen Nickelsen <jn@berlin.snafu.de>

View File

@@ -0,0 +1,52 @@
$NetBSD: patch-ac,v 1.5 2006/01/25 02:12:10 joerg Exp $
--- globals.h.orig 1992-08-30 19:04:27.000000000 +0000
+++ globals.h
@@ -8,6 +8,12 @@ Please read the file COPYRIGHT for furth
*/
#include "patchlevel.h"
+
+#if HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
+
+#include <stdlib.h>
/* globals for socket */
@@ -22,9 +28,16 @@ Please read the file COPYRIGHT for furth
#define A(args) ()
#endif
+#ifndef USE_INET6
int create_server_socket A((int port, int queue_length)) ;
int create_client_socket A((char **hostname, int port)) ;
int resolve_service A((char *name_or_number, char *protocol, char **name)) ;
+#else /* USE_INET6 */
+int *create_server_sockets A((char **port, int queue_length)) ;
+int create_client_socket A((char **hostname, char **port)) ;
+int socket_local_name A((int socket, char **name, char **ipname, char **port));
+int socket_remote_name A((int socket, char **name, char **ipname, char **port));
+#endif /* USE_INET6 */
void catchsig A((int sig)) ;
void usage A((void)) ;
int do_read_write A((int from, int to)) ;
@@ -37,8 +50,6 @@ void add_crs A((char *from, char *to, in
void strip_crs A((char *from, char *to, int *sizep)) ;
void background A((void)) ;
-extern int errno ;
-
/* global variables */
extern int serverflag ;
extern int loopflag ;
@@ -49,4 +60,7 @@ extern int quitflag ;
extern int crlfflag ;
extern int active_socket ;
extern char *progname ;
-extern char *sys_errlist[], *sys_siglist[] ;
+
+#if !(defined(BSD) && (BSD >=199306)) && !defined(__linux__)
+ extern char *sys_errlist[], *sys_siglist[] ;
+#endif

View File

@@ -0,0 +1,22 @@
$NetBSD: patch-ad,v 1.1 1999/02/02 23:00:40 tron Exp $
--- io.c.orig Sun Aug 30 19:15:26 1992
+++ io.c Tue Feb 2 23:52:03 1999
@@ -16,6 +16,8 @@
#endif
#include <errno.h>
#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
#include "globals.h"
/* read from from, write to to. select(2) has returned, so input
@@ -90,7 +92,7 @@
/* all IO to and from the socket is handled here. The main part is
* a loop around select(2). */
-do_io()
+void do_io()
{
fd_set readfds ;
int fdset_width ;

View File

@@ -0,0 +1,39 @@
$NetBSD: patch-ae,v 1.2 2004/05/10 16:36:33 minskim Exp $
--- siglist.c.orig 1992-08-30 08:50:48.000000000 -0500
+++ siglist.c
@@ -23,6 +23,7 @@ Foundation, 675 Mass Ave, Cambridge, MA
#include <stdio.h>
#include <signal.h>
+#include <stdlib.h>
#if !defined (NSIG)
# if defined (_NSIG)
@@ -32,12 +33,17 @@ Foundation, 675 Mass Ave, Cambridge, MA
# endif /* !_NSIG */
#endif /* !NSIG */
-char *sys_siglist[NSIG];
+#if HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
-extern *malloc ();
+#if !(defined(BSD) && (BSD >=199306)) && !defined(__linux__)
+char *sys_siglist[NSIG];
+#endif
-initialize_siglist ()
+void initialize_siglist ()
{
+#if !(defined(BSD) && (BSD >=199306))
register int i;
for (i = 0; i < NSIG; i++)
@@ -219,4 +225,5 @@ initialize_siglist ()
sprintf (sys_siglist[i], "Unknown Signal #%d", i);
}
}
+#endif /* !(defined(BSD) && (BSD >=199306)) */
}

View File

@@ -0,0 +1,10 @@
$NetBSD: patch-af,v 1.1 1999/02/02 23:00:41 tron Exp $
--- socket.1.orig Wed Sep 9 16:38:19 1992
+++ socket.1 Tue Feb 2 23:52:03 1999
@@ -158,4 +158,4 @@
.SH VERSION
This manual page describes Socket\-1.1.
.SH AUTHOR
-Juergen Nickelsen <nickel@cs.tu-berlin.de>
+Juergen Nickelsen <jn@berlin.snafu.de>

View File

@@ -0,0 +1,297 @@
$NetBSD: patch-ag,v 1.2 1999/09/17 18:23:55 tron Exp $
--- socket.c.orig Thu Sep 16 13:52:48 1999
+++ socket.c Thu Sep 16 12:54:06 1999
@@ -9,6 +9,9 @@
#include <sys/types.h>
#include <sys/socket.h>
+#ifdef USE_INET6
+#include <sys/time.h>
+#endif /* USE_INET6 */
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
@@ -18,6 +21,8 @@
#else
#include <string.h>
#endif
+#include <stdlib.h>
+#include <unistd.h>
#include "globals.h"
/* global variables */
@@ -34,9 +39,17 @@
char *progname ; /* name of the game */
char *pipe_program = NULL ; /* program to execute in two-way pipe */
+#ifndef USE_INET6
void server A((int port, char *service_name)) ;
-void handle_server_connection A((void)) ;
void client A((char *host, int port, char *service_name)) ;
+#else /* USE_INET6 */
+void server A((char *port)) ;
+void client A((char *host, char *port)) ;
+#endif /* USE_INET6 */
+
+void handle_server_connection A((void)) ;
+extern void init_signals A((void)) ;
+extern void do_io A((void)) ;
int main(argc, argv)
int argc ;
@@ -46,9 +59,11 @@
int opt ; /* option character */
int error = 0 ; /* usage error occurred */
extern int optind ; /* from getopt() */
- char *host ; /* name of remote host */
+ /* char *host ; */ /* name of remote host */
+#ifndef USE_INET6
int port ; /* port number for socket */
char *service_name ; /* name of service for port */
+#endif /* USE_INET6 */
/* print version ID if requested */
if (argv[1] && !strcmp(argv[1], "-version")) {
@@ -58,7 +73,8 @@
/* set up progname for later use */
progname = argv[0] ;
- if (cp = strrchr(progname, '/')) progname = cp + 1 ;
+ cp = strrchr(progname, '/');
+ if (cp) progname = cp + 1 ;
/* parse options */
while ((opt = getopt(argc, argv, "bcflp:qrsvw?")) != -1) {
@@ -126,6 +142,7 @@
/* set up signal handling */
init_signals() ;
+#ifndef USE_INET6
/* get port number */
port = resolve_service(argv[optind + 1 - serverflag],
"tcp", &service_name) ;
@@ -134,41 +151,81 @@
exit(5) ;
}
+#endif /* not USE_INET6 */
/* and go */
if (serverflag) {
if (backgflag) {
background() ;
}
+#ifndef USE_INET6
server(port, service_name) ;
+#else /* USE_INET6 */
+ server(argv[optind]) ;
+#endif /* USE_INET6 */
} else {
+#ifndef USE_INET6
client(argv[optind], port, service_name) ;
+#else /* USE_INET6 */
+ client(argv[optind], argv[optind + 1]) ;
+#endif /* USE_INET6 */
}
exit(0) ;
}
+#ifndef USE_INET6
void server(port, service_name)
int port ;
char *service_name ;
+#else /* USE_INET6 */
+void server(port)
+char *port ;
+#endif /* USE_INET6 */
{
+#ifndef USE_INET6
int socket_handle, alen ;
+#else /* USE_INET6 */
+ int *socket_handle_list ;
+#endif /* USE_INET6 */
/* allocate server socket */
+#ifndef USE_INET6
socket_handle = create_server_socket(port, 1) ;
if (socket_handle < 0) {
+#else /* USE_INET6 */
+ socket_handle_list = create_server_sockets(&port, 1) ;
+ if (!socket_handle_list) {
+#endif /* USE_INET6 */
perror2("server socket") ;
exit(1) ;
}
+#ifdef USE_INET6
+
+#endif /* USE_INET6 */
if (verboseflag) {
+#ifndef USE_INET6
fprintf(stderr, "listening on port %d", port) ;
if (service_name) {
fprintf(stderr, " (%s)", service_name) ;
}
fprintf(stderr, "\n") ;
+#else /* USE_INET6 */
+ char *ip, *port;
+ int fd, i;
+
+ fd = socket_handle_list[1];
+ for (i = 1; i <= socket_handle_list[0]; i++) {
+ if (!fd || fd < socket_handle_list[i])
+ fd = socket_handle_list[i];
+ socket_local_name (fd, NULL, &ip, &port);
+ fprintf(stderr, "listening at address %s on port %s\n", ip, port) ;
+ }
+#endif /* USE_INET6 */
}
/* server loop */
do {
+#ifndef USE_INET6
struct sockaddr_in sa ;
alen = sizeof(sa) ;
@@ -185,16 +242,76 @@
long norder ;
char dotted[20] ;
- he = gethostbyaddr(&sa.sin_addr.s_addr,
+ he = gethostbyaddr((const char *)&sa.sin_addr.s_addr,
sizeof(sa.sin_addr.s_addr), AF_INET) ;
if (!he) {
norder = htonl(sa.sin_addr.s_addr) ;
sprintf(dotted, "%d.%d.%d.%d",
- (norder >> 24) & 0xff,
- (norder >> 16) & 0xff,
- (norder >> 8) & 0xff,
- norder & 0xff) ;
+ (int)((norder >> 24) & 0xff),
+ (int)((norder >> 16) & 0xff),
+ (int)((norder >> 8) & 0xff),
+ (int)(norder & 0xff)) ;
+#else /* USE_INET6 */
+ struct timeval tv;
+ fd_set readfd;
+ int fd, i, nfds, retval;
+
+ fd = socket_handle_list[1];
+ for (i = 1; i <= socket_handle_list[0]; i++) {
+ if (!fd || fd < socket_handle_list[i])
+ fd = socket_handle_list[i];
+ }
+ nfds=fd+1;
+
+ FD_ZERO(&readfd);
+ for (i = 1; i <= socket_handle_list[0]; i++)
+ FD_SET(socket_handle_list[i],&readfd);
+
+ tv.tv_sec = 10;
+ tv.tv_usec = 0;
+
+ retval = select(nfds, &readfd, NULL, NULL, &tv);
+
+ if(retval!=-1) {
+ for (i = 1; i <= socket_handle_list[0]; i++) {
+ fd = socket_handle_list[i];
+ if (FD_ISSET(fd, &readfd)) {
+
+ /* accept a connection */
+ active_socket = accept(fd, (struct sockaddr *) 0, (int *)0);
+ if (active_socket == -1) {
+ perror2("accept") ;
+ } else {
+ /* if verbose, get name of peer and give message */
+ if (verboseflag) {
+ char *host, *ip, *port;
+
+ if(!socket_remote_name(active_socket,&host, &ip, &port)) {
+ fprintf(stderr, "connection from %s at %s to %s\n", host, ip, port);
+ }
+ else
+ fprintf(stderr, "cannot get name or address of peer") ;
+ }
+
+ if (forkflag) {
+ switch (fork()) {
+ case 0:
+ handle_server_connection() ;
+ exit(0) ;
+ case -1:
+ perror2("fork") ;
+ break ;
+ default:
+ close(active_socket) ;
+ wait_for_children() ;
+ }
+ } else {
+ handle_server_connection() ;
+ }
+ }
+#endif /* USE_INET6 */
}
+#ifndef USE_INET6
fprintf(stderr, "connection from %s\n",
(he ? he->h_name : dotted)) ;
}
@@ -212,9 +329,14 @@
}
} else {
handle_server_connection() ;
+#endif /* not USE_INET6 */
}
}
} while (loopflag) ;
+#ifdef USE_INET6
+
+ free (socket_handle_list);
+#endif /* USE_INET6 */
}
@@ -235,13 +357,25 @@
}
+#ifndef USE_INET6
void client(host, port, service_name)
+#else /* USE_INET6 */
+void client(host, port)
+#endif /* USE_INET6 */
char *host ;
+#ifndef USE_INET6
int port ;
char *service_name ;
+#else /* USE_INET6 */
+char *port ;
+#endif /* USE_INET6 */
{
/* get connection */
+#ifndef USE_INET6
active_socket = create_client_socket(&host, port) ;
+#else /* USE_INET6 */
+ active_socket = create_client_socket(&host, &port) ;
+#endif /* USE_INET6 */
if (active_socket == -1) {
perror2("client socket") ;
exit(errno) ;
@@ -250,11 +384,18 @@
exit(13) ;
}
if (verboseflag) {
+#ifndef USE_INET6
fprintf(stderr, "connected to %s port %d", host, port) ;
if (service_name) {
fprintf(stderr, " (%s)", service_name) ;
}
fprintf(stderr, "\n") ;
+#else /* USE_INET6 */
+ char *host, *ip, *port;
+
+ socket_local_name (active_socket, &host, &ip, &port);
+ fprintf(stderr, "connected to %s with address %s at port %s\n", host, ip, port) ;
+#endif /* USE_INET6 */
}
/* open pipes to program if requested */

View File

@@ -0,0 +1,332 @@
$NetBSD: patch-ah,v 1.3 2006/01/25 02:12:10 joerg Exp $
--- socketp.c.orig 1992-08-09 01:41:42.000000000 +0000
+++ socketp.c
@@ -9,12 +9,19 @@ Please read the file COPYRIGHT for furth
#include <sys/types.h>
#include <sys/socket.h>
-#include <sys/errno.h>
+#include <errno.h>
#include <netinet/in.h>
+#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include "globals.h"
+extern int is_number A((char *));
+
+#ifndef USE_INET6
/*
* create a server socket on PORT accepting QUEUE_LENGTH connections
*/
@@ -25,9 +32,9 @@ int queue_length ;
struct sockaddr_in sa ;
int s;
- if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s < 0)
return -1 ;
- }
bzero((char *) &sa, sizeof(sa)) ;
sa.sin_family = AF_INET ;
@@ -35,54 +42,270 @@ int queue_length ;
sa.sin_port = htons(port) ;
if (bind(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
- return -1 ;
+ return -1 ;
}
if (listen(s, 1) < 0) {
- return -1 ;
+ return -1 ;
}
return s ;
}
+#else /* USE_INET6 */
+/*
+ * create a server socket(s) on PORT accepting QUEUE_LENGTH connections
+ *
+ * FWD (ifdef USE_INET6):
+ * there can be more than one socket; one for each supported address
+ * family. This is for portability as not all IPv6 stacks implement
+ * the wildcard bind as a bind to *ll IPv4 *and* IPv6 addresses.
+ * so we'll just open a socket for each address getaddrinfo() gives
+ * back to us. The price of portability...
+ */
+int *create_server_sockets(port, queue_length)
+char **port ;
+int queue_length ;
+{
+ struct addrinfo hints, *r, *res;
+ int *s, *slist, error, maxs;
+ int reuse_addr = 1;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = AI_PASSIVE;
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = 0;
+ error = getaddrinfo(NULL, *port, &hints, &res);
+
+ if (!error) {
+ for (maxs = 0, r = res; r; r = r->ai_next, maxs++);
+ slist = malloc ((maxs+1) * sizeof(int));
+ if (slist) {
+ slist[0] = maxs; /* max. num of sockets */
+
+ s = slist+1;
+ for (r = res; r; r = r->ai_next) {
+ *s = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
+ if (*s < 0)
+ continue;
+
+ setsockopt(*s,SOL_SOCKET,SO_REUSEADDR,&reuse_addr,sizeof(reuse_addr));
+
+ if (bind(*s, r->ai_addr, r->ai_addrlen) < 0) {
+ close (*s);
+ continue;
+ }
+
+ if (listen(*s, 1) < 0) {
+ close (*s);
+ continue;
+ }
+ s++;
+ }
+ }
+ }
+ else
+ slist = NULL;
+
+ if (res)
+ freeaddrinfo(res);
+
+ if (slist && !slist[0]) {
+ free (slist);
+ slist = NULL;
+ }
+
+ return (slist);
+}
+#endif /* USE_INET6 */
/* create a client socket connected to PORT on HOSTNAME */
+#ifndef USE_INET6
+/* create a client socket connected to PORT on HOSTNAME */
int create_client_socket(hostname, port)
char **hostname ;
int port ;
{
struct sockaddr_in sa ;
struct hostent *hp ;
- int a, s ;
+ int s ;
long addr ;
bzero(&sa, sizeof(sa)) ;
if ((addr = inet_addr(*hostname)) != -1) {
- /* is Internet addr in octet notation */
- bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
- sa.sin_family = AF_INET ;
+ /* is Internet addr in octet notation */
+ bcopy(&addr, (char *) &sa.sin_addr, sizeof(addr)) ; /* set address */
+ sa.sin_family = AF_INET ;
} else {
- /* do we know the host's address? */
- if ((hp = gethostbyname(*hostname)) == NULL) {
- return -2 ;
- }
- *hostname = hp->h_name ;
- bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
- sa.sin_family = hp->h_addrtype ;
+ /* do we know the host's address? */
+ if ((hp = gethostbyname(*hostname)) == NULL) {
+ return -2 ;
+ }
+ *hostname = hp->h_name ;
+ bcopy(hp->h_addr, (char *) &sa.sin_addr, hp->h_length) ;
+ sa.sin_family = hp->h_addrtype ;
}
sa.sin_port = htons((u_short) port) ;
if ((s = socket(sa.sin_family, SOCK_STREAM, 0)) < 0) { /* get socket */
- return -1 ;
+ return -1 ;
}
- if (connect(s, &sa, sizeof(sa)) < 0) { /* connect */
- close(s) ;
- return -1 ;
+ if (connect(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) { /* connect */
+ close(s) ;
+ return -1 ;
}
return s ;
}
+#else /* USE_INET6 */
+int create_client_socket(hostname, port)
+char **hostname ;
+char **port ;
+{
+ int s, connected, err ;
+ struct addrinfo hints, *r, *res;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = AI_NUMERICHOST;
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype= SOCK_STREAM;
+ err = getaddrinfo(*hostname, *port, &hints, &res);
+ if (res) freeaddrinfo(res);
+
+ if (!err) {
+ /* numeric */
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = AI_CANONNAME;
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = 0;
+ err = getaddrinfo(*hostname, *port, &hints, &res);
+ if (err) s = -2;
+ } else {
+ /* non-numeric */
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = 0;
+ err = getaddrinfo(*hostname, *port, &hints, &res);
+ if (err) s = -2;
+ }
+
+
+ if (!err) {
+ err = 0; s = -1;
+ connected = 0;
+ for (r = res; r && !connected; r = r->ai_next) {
+ s = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
+ if (s < 0)
+ continue;
+
+ if (connect(s, r->ai_addr, r->ai_addrlen) < 0) {
+ err = errno;
+ close(s);
+ s = -1;
+ continue;
+ }
+ connected++;
+ break;
+ }
+ if (!connected) s = -1;
+ }
+
+ if (res)
+ freeaddrinfo(res);
+
+ return (s);
+}
+#endif /* USE_INET6 */
+
+#ifdef USE_INET6
+/* Determines hostname, address and port number used for the peer of socket */
+int socket_remote_name(socket, name, ipname, port)
+int socket;
+char **name;
+char **ipname;
+char **port;
+{
+ struct sockaddr_storage server;
+ int length=sizeof(server), retval, error;
+ static char host[NI_MAXHOST],ip[NI_MAXHOST],portstr[NI_MAXSERV];
+
+ error = getpeername(socket,(struct sockaddr*)&server,&length);
+ if(!error) {
+ error = getnameinfo((struct sockaddr*)&server, length, host,
+ NI_MAXHOST, NULL, 0, 0);
+ error = getnameinfo((struct sockaddr*)&server, length, ip,
+ NI_MAXHOST, NULL, NI_MAXSERV,
+ NI_NUMERICHOST);
+ retval = error;
+
+ error = getnameinfo((struct sockaddr*)&server, length, NULL, 0,
+ portstr, NI_MAXSERV, 0);
+
+ if (error)
+ retval = getnameinfo((struct sockaddr*)&server, length, ip,
+ NI_MAXHOST, portstr, NI_MAXSERV,
+ NI_NUMERICSERV);
+ }
+ else
+ retval = error;
+
+ if(name)
+ *name=host;
+ if(ipname)
+ *ipname=ip;
+ if(port)
+ *port=portstr;
+
+ return(retval);
+}
+
+/* Determines the hostname, address and port number used for our socket */
+int socket_local_name(socket, name, ipname, port)
+int socket;
+char **name;
+char **ipname;
+char **port;
+{
+ struct sockaddr_storage server;
+ int length=sizeof(server), retval, error;
+ static char host[NI_MAXHOST],ip[NI_MAXHOST],portstr[NI_MAXSERV];
+
+ error = getsockname(socket,(struct sockaddr*)&server,&length);
+ if(!error) {
+ error = getnameinfo((struct sockaddr*)&server, length, host,
+ NI_MAXHOST, NULL, 0, 0);
+ error = getnameinfo((struct sockaddr*)&server, length, ip,
+ NI_MAXHOST, NULL, NI_MAXSERV,
+ NI_NUMERICHOST);
+ retval = error;
+
+ error = getnameinfo((struct sockaddr*)&server, length, NULL, 0,
+ portstr, NI_MAXSERV, 0);
+
+ if (error)
+ retval = getnameinfo((struct sockaddr*)&server, length, ip,
+ NI_MAXHOST, portstr, NI_MAXSERV,
+ NI_NUMERICSERV);
+ }
+ else
+ retval = error;
+
+ if(name)
+ *name=host;
+ if(ipname)
+ *ipname=ip;
+ if(port)
+ *port=portstr;
+
+ return(retval);
+}
+#endif /* USE_INET6 */
+
+#ifndef USE_INET6
/* return the port number for service NAME_OR_NUMBER. If NAME is non-null,
* the name is the service is written there.
*/
@@ -116,5 +339,6 @@ char **name ;
return ntohs(servent->s_port) ;
}
}
+#endif /* !USE_INET6 */
/*EOF*/

View File

@@ -0,0 +1,60 @@
$NetBSD: patch-ai,v 1.4 2006/11/28 16:48:31 tv Exp $
--- utils.c.orig 1992-09-09 10:31:16.000000000 -0400
+++ utils.c
@@ -18,6 +18,7 @@ Please read the file COPYRIGHT for furth
#include <signal.h>
#include <sys/wait.h>
#include <sys/time.h>
+#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#ifdef ISC
@@ -25,8 +26,10 @@ Please read the file COPYRIGHT for furth
#else
#include <sys/resource.h>
#endif
+#include <unistd.h>
#include "globals.h"
+extern void initialize_siglist A((void)) ;
/* Signal handler, print message and exit */
SIG_HANDLER_RET exitsig(sig)
@@ -70,10 +73,10 @@ char *s ;
/* set up signal handling. All except TSTP, CONT, CLD, and QUIT
* are caught with exitsig(). */
-init_signals()
+void init_signals()
{
int i ;
-#ifdef SIG_SETMASK /* only with BSD signals */
+#if defined(SIG_SETMASK) && !defined(__NetBSD__) /* only with BSD signals */
static struct sigvec svec = { exitsig, ~0, 0 } ;
#endif
@@ -103,7 +106,7 @@ init_signals()
case SIGQUIT: /* if the user wants a core dump, */
continue ; /* they can have it. */
default:
-#ifdef SIG_SETMASK
+#if defined(SIG_SETMASK) && !defined(__NetBSD__)
sigvec(i, &svec, NULL) ;
#else
signal(i, exitsig) ;
@@ -173,12 +176,12 @@ char *prog ;
void wait_for_children()
{
int wret, status ;
-#ifndef ISC
+#if !defined(ISC) && !defined(__INTERIX)
struct rusage rusage ;
#endif
/* Just do a wait, forget result */
-#ifndef ISC
+#if !defined(ISC) && !defined(__INTERIX)
while ((wret = wait3(&status, WNOHANG, &rusage)) > 0) ;
#else
while ((wret = waitpid(-1, &status, WNOHANG)) > 0) ;