Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/hunt/huntd Make the code for issuing talk requests to ...
details: https://anonhg.NetBSD.org/src/rev/44f82c609dc9
branches: trunk
changeset: 328233:44f82c609dc9
user: dholland <dholland%NetBSD.org@localhost>
date: Sat Mar 29 20:10:10 2014 +0000
description:
Make the code for issuing talk requests to find players actually build.
diffstat:
games/hunt/huntd/ctl.c | 14 +++++++-----
games/hunt/huntd/ctl_transact.c | 16 ++++++++------
games/hunt/huntd/driver.c | 8 +++---
games/hunt/huntd/faketalk.c | 14 +++++++-----
games/hunt/huntd/get_names.c | 44 ++++++++++++++++++++++------------------
games/hunt/huntd/hunt.h | 4 +-
6 files changed, 55 insertions(+), 45 deletions(-)
diffs (284 lines):
diff -r 0ccb0b402b37 -r 44f82c609dc9 games/hunt/huntd/ctl.c
--- a/games/hunt/huntd/ctl.c Sat Mar 29 19:54:46 2014 +0000
+++ b/games/hunt/huntd/ctl.c Sat Mar 29 20:10:10 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ctl.c,v 1.5 2009/07/04 04:29:54 dholland Exp $ */
+/* $NetBSD: ctl.c,v 1.6 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)ctl.c 5.2 (Berkeley) 3/13/86";
#else
-__RCSID("$NetBSD: ctl.c,v 1.5 2009/07/04 04:29:54 dholland Exp $");
+__RCSID("$NetBSD: ctl.c,v 1.6 2014/03/29 20:10:10 dholland Exp $");
#endif
#endif /* not lint */
@@ -52,8 +52,8 @@
#include "hunt.h"
#include "talk_ctl.h"
-struct sockaddr_in daemon_addr = { AF_INET };
-struct sockaddr_in ctl_addr = { AF_INET };
+struct sockaddr_in daemon_addr;
+struct sockaddr_in ctl_addr;
/* inet addresses of the two machines */
struct in_addr my_machine_addr;
@@ -69,14 +69,16 @@
void
open_ctl(void)
{
- int length;
+ socklen_t length;
+ ctl_addr.sin_family = AF_INET;
ctl_addr.sin_port = 0;
ctl_addr.sin_addr = my_machine_addr;
ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0);
if (ctl_sockt <= 0)
p_error("Bad socket");
- if (bind(ctl_sockt, &ctl_addr, sizeof(ctl_addr)) != 0)
+ if (bind(ctl_sockt, (struct sockaddr *)&ctl_addr,
+ sizeof(ctl_addr)) != 0)
p_error("Couldn't bind to control socket");
length = sizeof(ctl_addr);
if (getsockname(ctl_sockt, (struct sockaddr *) &ctl_addr, &length) < 0)
diff -r 0ccb0b402b37 -r 44f82c609dc9 games/hunt/huntd/ctl_transact.c
--- a/games/hunt/huntd/ctl_transact.c Sat Mar 29 19:54:46 2014 +0000
+++ b/games/hunt/huntd/ctl_transact.c Sat Mar 29 20:10:10 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ctl_transact.c,v 1.9 2009/07/04 04:29:54 dholland Exp $ */
+/* $NetBSD: ctl_transact.c,v 1.10 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)ctl_transact.c 5.2 (Berkeley) 3/13/86";
#else
-__RCSID("$NetBSD: ctl_transact.c,v 1.9 2009/07/04 04:29:54 dholland Exp $");
+__RCSID("$NetBSD: ctl_transact.c,v 1.10 2014/03/29 20:10:10 dholland Exp $");
#endif
#endif /* not lint */
@@ -57,13 +57,14 @@
* of time
*/
void
-ctl_transact(struct in_addr target, CTL_MSG msg, int type, CTL_RESPONSE *rp)
+ctl_transact(struct in_addr target, CTL_MSG tmsg, int type, CTL_RESPONSE *rp)
{
struct pollfd set[1];
int nready, cc, retries;
nready = 0;
- msg.type = type;
+ tmsg.type = type;
+ daemon_addr.sin_family = AF_INET;
daemon_addr.sin_addr = target;
daemon_addr.sin_port = daemon_port;
set[0].fd = ctl_sockt;
@@ -76,9 +77,10 @@
do {
/* resend message until a response is obtained */
for (retries = MAX_RETRY; retries > 0; retries -= 1) {
- cc = sendto(ctl_sockt, &msg, sizeof (msg), 0,
- &daemon_addr, sizeof (daemon_addr));
- if (cc != sizeof (msg)) {
+ cc = sendto(ctl_sockt, &tmsg, sizeof (tmsg), 0,
+ (struct sockaddr *) &daemon_addr,
+ sizeof(daemon_addr));
+ if (cc != sizeof (tmsg)) {
if (errno == EINTR)
continue;
p_error("Error on write to talk daemon");
diff -r 0ccb0b402b37 -r 44f82c609dc9 games/hunt/huntd/driver.c
--- a/games/hunt/huntd/driver.c Sat Mar 29 19:54:46 2014 +0000
+++ b/games/hunt/huntd/driver.c Sat Mar 29 20:10:10 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: driver.c,v 1.24 2014/03/29 19:41:10 dholland Exp $ */
+/* $NetBSD: driver.c,v 1.25 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: driver.c,v 1.24 2014/03/29 19:41:10 dholland Exp $");
+__RCSID("$NetBSD: driver.c,v 1.25 2014/03/29 20:10:10 dholland Exp $");
#endif /* not lint */
#include <sys/ioctl.h>
@@ -47,8 +47,8 @@
static SOCKET Daemon;
-static char *First_arg; /* pointer to argv[0] */
-static char *Last_arg; /* pointer to end of argv/environ */
+char *First_arg; /* pointer to argv[0] */
+char *Last_arg; /* pointer to end of argv/environ */
#ifdef INTERNET
static int Test_socket; /* test socket to answer datagrams */
diff -r 0ccb0b402b37 -r 44f82c609dc9 games/hunt/huntd/faketalk.c
--- a/games/hunt/huntd/faketalk.c Sat Mar 29 19:54:46 2014 +0000
+++ b/games/hunt/huntd/faketalk.c Sat Mar 29 20:10:10 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: faketalk.c,v 1.20 2014/03/29 19:41:10 dholland Exp $ */
+/* $NetBSD: faketalk.c,v 1.21 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: faketalk.c,v 1.20 2014/03/29 19:41:10 dholland Exp $");
+__RCSID("$NetBSD: faketalk.c,v 1.21 2014/03/29 20:10:10 dholland Exp $");
#endif /* not lint */
#include "bsd.h"
@@ -89,7 +89,8 @@
FILE *f;
int service; /* socket of service */
struct sockaddr_in des; /* address of destination */
- char *a, *b;
+ char *a;
+ const char *b;
(void) signal(SIGCHLD, exorcise);
@@ -182,11 +183,11 @@
else
t -= 1;
}
- while (isspace(*s))
+ while (isspace((unsigned char)*s))
s += 1;
if (*s == '\\')
s += 1;
- while (isspace(*t))
+ while (isspace((unsigned char)*t))
t -= 1;
*(t + 1) = '\0';
do_announce(s); /* construct and send talk request */
@@ -211,7 +212,8 @@
get_remote_name(s); /* setup his_machine_addr, msg.r_name */
#ifdef TALK_43
- msg.ctl_addr = *(struct osockaddr *) &ctl_addr;
+ /* XXX this is nothing like a safe cast */
+ msg.ctl_addr = *(struct talkd_sockaddr *) &ctl_addr;
msg.ctl_addr.sa_family = htons(msg.ctl_addr.sa_family);
#else
msg.ctl_addr = ctl_addr;
diff -r 0ccb0b402b37 -r 44f82c609dc9 games/hunt/huntd/get_names.c
--- a/games/hunt/huntd/get_names.c Sat Mar 29 19:54:46 2014 +0000
+++ b/games/hunt/huntd/get_names.c Sat Mar 29 20:10:10 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: get_names.c,v 1.14 2014/03/29 19:26:28 dholland Exp $ */
+/* $NetBSD: get_names.c,v 1.15 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: get_names.c,v 1.14 2014/03/29 19:26:28 dholland Exp $");
+__RCSID("$NetBSD: get_names.c,v 1.15 2014/03/29 20:10:10 dholland Exp $");
#endif /* not lint */
#include "bsd.h"
@@ -45,6 +45,8 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <assert.h>
+
#include "hunt.h"
#include "talk_ctl.h"
@@ -55,7 +57,7 @@
* Determine the local user and machine
*/
void
-get_local_name(char *my_name)
+get_local_name(const char *my_name)
{
struct hostent *hp;
struct servent *sp;
@@ -116,7 +118,8 @@
const char *his_name;
const char *his_machine_name;
char *ptr;
- struct hostent *hp;
+ struct addrinfo ai0, *ai;
+ struct sockaddr_in *sin;
/* check for, and strip out, the machine name of the target */
for (ptr = his_address; *ptr != '\0' && *ptr != '@' && *ptr != ':'
@@ -144,24 +147,25 @@
* Since this is used for sending udp talk packets,
* it has to be AF_INET.
*/
- ai.ai_flags = 0;
- ai.family = AF_INET;
- ai.socktype = SOCK_DGRAM;
- ai.protocol = IPPROTO_UDP;
- ai.ai_addrlen = 0;
- ai.ai_addr = NULL;
- ai.ai_canonname = NULL;
- ai.ai_neext = NULL;
- aierror = getaddrinfo(his_machine_name, NULL, ai, &ai);
- if (aierror != 0) {
+ ai0.ai_flags = 0;
+ ai0.ai_family = AF_INET;
+ ai0.ai_socktype = SOCK_DGRAM;
+ ai0.ai_protocol = IPPROTO_UDP;
+ ai0.ai_addrlen = 0;
+ ai0.ai_addr = NULL;
+ ai0.ai_canonname = NULL;
+ ai0.ai_next = NULL;
+ if (getaddrinfo(his_machine_name, NULL, &ai0, &ai) != 0) {
return 0;
}
- assert(ai.family == AF_INET);
- assert(ai.socktype == SOCK_DGRAM);
- assert(ai.protocol == IPPROTO_UDP);
- assert(ai.ai_addrln == sizeof(his_machine_addr));
- assert(ai.ai_addr != NULL);
- his_machine_addr = *ai->ai_addr;
+ assert(ai->ai_family == AF_INET);
+ assert(ai->ai_socktype == SOCK_DGRAM);
+ assert(ai->ai_protocol == IPPROTO_UDP);
+ assert(ai->ai_addrlen == sizeof(his_machine_addr));
+ assert(ai->ai_addr != NULL);
+ sin = (struct sockaddr_in *)ai->ai_addr;
+ his_machine_addr = sin->sin_addr;
+ freeaddrinfo(ai);
}
/* Load these useful values into the standard message header */
(void) strncpy(msg.r_name, his_name, NAME_SIZE);
diff -r 0ccb0b402b37 -r 44f82c609dc9 games/hunt/huntd/hunt.h
--- a/games/hunt/huntd/hunt.h Sat Mar 29 19:54:46 2014 +0000
+++ b/games/hunt/huntd/hunt.h Sat Mar 29 20:10:10 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hunt.h,v 1.20 2014/03/29 19:41:10 dholland Exp $ */
+/* $NetBSD: hunt.h,v 1.21 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
@@ -424,7 +424,7 @@
void execute(PLAYER *);
void faketalk(void);
void fixshots(int, int, char);
-void get_local_name(char *);
+void get_local_name(const char *);
int get_remote_name(char *);
BULLET *is_bullet(int, int);
void look(PLAYER *);
Home |
Main Index |
Thread Index |
Old Index