Update of /cvsroot/netrek/server/Vanilla/newstartd
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6880/newstartd
Modified Files:
newaccess.c newstartd.c
Log Message:
Index: newstartd.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/newstartd/newstartd.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- newstartd.c 10 Apr 2006 04:24:51 -0000 1.7
+++ newstartd.c 22 Apr 2006 02:16:46 -0000 1.8
@@ -377,10 +377,11 @@
}
}
-int get_connection ()
+int get_connection()
{
struct sockaddr_in addr;
struct sockaddr_in naddr;
+ socklen_t addrlen;
fd_set accept_fds;
int len, i, st, newsock;
@@ -393,23 +394,23 @@
sock = prog[i].sock;
if (sock < 0) {
- fprintf (stderr, "netrekd: port %d, %s, ", prog[i].port, prog[i].prog);
- if ((sock = socket (AF_INET, prog[i].type, 0)) < 0) {
- perror ("socket");
- sleep (1);
+ fprintf(stderr, "netrekd: port %d, %s, ", prog[i].port, prog[i].prog);
+ if ((sock = socket(AF_INET, prog[i].type, 0)) < 0) {
+ perror("socket");
+ sleep(1);
return -1;
}
/* we can't cope with having socket zero for a listening socket */
if (sock == 0) {
- if (debug) fprintf (stderr, "gack: don't want socket zero\n");
- if ((sock = socket (AF_INET, prog[i].type, 0)) < 0) {
- perror ("socket");
- sleep (1);
- close (0);
+ if (debug) fprintf(stderr, "gack: don't want socket zero\n");
+ if ((sock = socket(AF_INET, prog[i].type, 0)) < 0) {
+ perror("socket");
+ sleep(1);
+ close(0);
return -1;
}
- close (0);
+ close(0);
}
/* set the listening socket to close on exec so that children
@@ -417,9 +418,9 @@
restarting netrekd. */
if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
- perror ("fcntl F_SETFD FD_CLOEXEC");
- close (sock);
- sleep (1);
+ perror("fcntl F_SETFD FD_CLOEXEC");
+ close(sock);
+ sleep(1);
return -1;
}
@@ -427,39 +428,39 @@
so that we don't have to pay the CLOSE_WAIT penalty if we need
to close and re-open the socket on restart. */
- if (setsockopt (sock, SOL_SOCKET, SO_REUSEADDR,
- (char *) &foo, sizeof (int)) < 0) {
- perror ("setsockopt SOL_SOCKET SO_REUSEADDR");
- close (sock);
- sleep (1);
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ (char *) &foo, sizeof(int)) < 0) {
+ perror("setsockopt SOL_SOCKET SO_REUSEADDR");
+ close(sock);
+ sleep(1);
return -1;
}
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = prog[i].addr;
- addr.sin_port = htons (prog[i].port);
+ addr.sin_port = htons(prog[i].port);
- if (bind (sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
- perror ("bind");
- close (sock);
- sleep (1);
+ if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ perror("bind");
+ close(sock);
+ sleep(1);
continue;
}
if (prog[i].type == SOCK_STREAM) {
- if (listen (sock, 1) < 0) {
- perror ("listen");
- close (sock);
- sleep (1);
+ if (listen(sock, 1) < 0) {
+ perror("listen");
+ close(sock);
+ sleep(1);
continue;
}
}
prog[i].sock = sock;
- fprintf (stderr, "listening fd %d, to do \"%s\" %s %s %s %s\n",
- prog[i].sock, prog[i].progname, prog[i].arg[0],
- prog[i].arg[1], prog[i].arg[2], prog[i].arg[3]);
- fflush (stderr);
+ fprintf(stderr, "listening fd %d, to do \"%s\" %s %s %s %s\n",
+ prog[i].sock, prog[i].progname, prog[i].arg[0],
+ prog[i].arg[1], prog[i].arg[2], prog[i].arg[3]);
+ fflush(stderr);
}
}
@@ -468,15 +469,15 @@
for (;;) { /* wait for a connection */
st = 0;
- FD_ZERO (&accept_fds); /* clear the file descriptor mask */
+ FD_ZERO(&accept_fds); /* clear the file descriptor mask */
for (i = 0; i < num_progs; i++) { /* set bits in mask for each sock */
sock = prog[i].sock;
if (sock < 0) continue;
if (prog[i].type == SOCK_STREAM)
- FD_SET (sock, &accept_fds);
+ FD_SET(sock, &accept_fds);
if (prog[i].type == SOCK_DGRAM)
if (prog[i].child == 0)
- FD_SET (sock, &accept_fds);
+ FD_SET(sock, &accept_fds);
st++;
}
@@ -488,7 +489,7 @@
}
/* block until select() indicates accept() will complete */
- st = select (32, &accept_fds, 0, 0, 0);
+ st = select(32, &accept_fds, 0, 0, 0);
if (st > 0) break;
if (restart) return -1;
if (errno == EINTR) continue;
@@ -500,30 +501,30 @@
for (i = 0; i < num_progs; i++) {
sock = prog[i].sock;
if (sock < 0) continue;
- if (FD_ISSET (sock, &accept_fds)) break;
+ if (FD_ISSET(sock, &accept_fds)) break;
}
/* none of the sockets showed activity? erk */
if (i >= num_progs) return -1;
- len = sizeof(naddr);
+ addrlen = sizeof(naddr);
if (prog[i].type == SOCK_STREAM) {
/* accept stream connections as new socket */
for (;;) {
- newsock = accept (sock, (struct sockaddr*)&naddr, &len);
+ newsock = accept(sock, (struct sockaddr *) &naddr, &addrlen);
if (newsock >= 0) break;
if (errno == EINTR) continue;
- fprintf (stderr, "netrekd: port %d, %s, ", prog[i].port, prog[i].prog);
- perror ("accept");
- sleep (1);
+ fprintf(stderr, "netrekd: port %d, %s, ", prog[i].port, prog[i].prog);
+ perror("accept");
+ sleep(1);
return -1;
}
if (newsock != 0) {
- if (dup2 (newsock, 0) == -1) {
- perror ("dup2");
+ if (dup2(newsock, 0) == -1) {
+ perror("dup2");
}
- close (newsock);
+ close(newsock);
}
} else {
/* datagrams will be read by child on duplicated socket */
Index: newaccess.c
===================================================================
RCS file: /cvsroot/netrek/server/Vanilla/newstartd/newaccess.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- newaccess.c 30 Sep 2005 05:46:19 -0000 1.2
+++ newaccess.c 22 Apr 2006 02:16:46 -0000 1.3
@@ -55,10 +55,11 @@
int canplay;
int ncanplay;
int netmatch;
- int count, sockt, length;
+ int count, sockt;
unsigned LONG net_addr;
struct netent *np;
- struct sockaddr_in sin;
+ struct sockaddr_in addr;
+ socklen_t addrlen;
struct hostent *hp;
FILE *acs_fp;
#ifdef SUBNET
@@ -90,13 +91,13 @@
#endif
sockt = fileno(stdin);
- length = sizeof (struct sockaddr_in);
+ addrlen = sizeof (struct sockaddr_in);
#ifdef DEBUG
return 1;
#endif
- if (getpeername(sockt, (struct sockaddr *) &sin, &length) < 0) {
+ if (getpeername(sockt, (struct sockaddr *) &addr, &addrlen) < 0) {
if (isatty(sockt)) {
#ifdef LOG
(void) strcpy(peerhostname, "stdin");
@@ -111,12 +112,12 @@
return (canplay);
}
- hp = gethostbyaddr((char *) &sin.sin_addr.s_addr, sizeof(U_LONG),
+ hp = gethostbyaddr((char *) &addr.sin_addr.s_addr, sizeof(U_LONG),
AF_INET);
if (hp != NULL)
(void) strcpy(host_name, hp->h_name);
else
- (void) strcpy(host_name, inet_ntoa(sin.sin_addr));
+ (void) strcpy(host_name, inet_ntoa(addr.sin_addr));
#ifdef LOG
#ifdef notdef
@@ -128,7 +129,7 @@
if (host) {
hp = gethostbyname(host);
if (hp) {
- MCOPY(hp->h_addr, &sin.sin_addr, sizeof (hp->h_length));
+ MCOPY(hp->h_addr, &addr.sin_addr, sizeof (hp->h_length));
(void) strcpy(host_name, host);
}
}
@@ -138,11 +139,11 @@
*cp = tolower(*cp);
/*
- * At this point, sin.sin_addr.s_addr is the address of
+ * At this point, addr.sin_addr.s_addr is the address of
* the host in network order.
*/
- net_addr = inet_netof(sin.sin_addr); /* net_addr in host order */
+ net_addr = inet_netof(addr.sin_addr); /* net_addr in host order */
np = getnetbyaddr(net_addr, AF_INET);
if (np != NULL)
@@ -151,7 +152,7 @@
(void) strcpy(net_name,inet_ntoa(*(struct in_addr *)&net_addr));
#ifdef SUBNET
- snet_addr = inet_snetof(sin.sin_addr.s_addr);
+ snet_addr = inet_snetof(addr.sin_addr.s_addr);
if (snet_addr == 0)
snet_name[0] = '\0';
else {