Home | History | Annotate | Line # | Download | only in hunt
      1 /*	$NetBSD: connect.c,v 1.11 2014/03/30 05:30:28 dholland Exp $	*/
      2 /*
      3  * Copyright (c) 1983-2003, Regents of the University of California.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions are
      8  * met:
      9  *
     10  * + Redistributions of source code must retain the above copyright
     11  *   notice, this list of conditions and the following disclaimer.
     12  * + Redistributions in binary form must reproduce the above copyright
     13  *   notice, this list of conditions and the following disclaimer in the
     14  *   documentation and/or other materials provided with the distribution.
     15  * + Neither the name of the University of California, San Francisco nor
     16  *   the names of its contributors may be used to endorse or promote
     17  *   products derived from this software without specific prior written
     18  *   permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     21  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     23  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 #ifndef lint
     35 __RCSID("$NetBSD: connect.c,v 1.11 2014/03/30 05:30:28 dholland Exp $");
     36 #endif /* not lint */
     37 
     38 #include <string.h>
     39 #include <signal.h>
     40 #include <unistd.h>
     41 #include <assert.h>
     42 
     43 #include "hunt_common.h"
     44 #include "hunt_private.h"
     45 
     46 void
     47 do_connect(const char *name, size_t namelen, char team, int enter_status)
     48 {
     49 	static int32_t uid;
     50 	int32_t mode;
     51 	int32_t wire_status = htonl(enter_status);
     52 
     53 	if (uid == 0)
     54 		uid = htonl(getuid());
     55 	(void) write(huntsocket, &uid, sizeof(uid));
     56 	assert(namelen == WIRE_NAMELEN);
     57 	(void) write(huntsocket, name, namelen);
     58 	(void) write(huntsocket, &team, 1);
     59 	(void) write(huntsocket, &wire_status, sizeof(wire_status));
     60 	(void) strcpy(Buf, ttyname(fileno(stderr)));
     61 	(void) write(huntsocket, Buf, WIRE_NAMELEN);
     62 #ifdef INTERNET
     63 	if (Send_message != NULL)
     64 		mode = C_MESSAGE;
     65 	else
     66 #endif
     67 #ifdef MONITOR
     68 	if (Am_monitor)
     69 		mode = C_MONITOR;
     70 	else
     71 #endif
     72 		mode = C_PLAYER;
     73 	mode = htonl(mode);
     74 	(void) write(huntsocket, &mode, sizeof mode);
     75 }
     76