1331722Seadler/* 21592Srgrimes * Copyright (c) 1983, 1993 31592Srgrimes * The Regents of the University of California. All rights reserved. 41592Srgrimes * 51592Srgrimes * Redistribution and use in source and binary forms, with or without 61592Srgrimes * modification, are permitted provided that the following conditions 71592Srgrimes * are met: 81592Srgrimes * 1. Redistributions of source code must retain the above copyright 91592Srgrimes * notice, this list of conditions and the following disclaimer. 101592Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111592Srgrimes * notice, this list of conditions and the following disclaimer in the 121592Srgrimes * documentation and/or other materials provided with the distribution. 13262136Sbrueffer * 3. Neither the name of the University nor the names of its contributors 141592Srgrimes * may be used to endorse or promote products derived from this software 151592Srgrimes * without specific prior written permission. 161592Srgrimes * 171592Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181592Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191592Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201592Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211592Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221592Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231592Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241592Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251592Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261592Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271592Srgrimes * SUCH DAMAGE. 281592Srgrimes */ 291592Srgrimes 301592Srgrimes#ifndef lint 3131491Scharnier#if 0 321592Srgrimesstatic char sccsid[] = "@(#)print.c 8.1 (Berkeley) 6/4/93"; 3331491Scharnier#endif 3431491Scharnierstatic const char rcsid[] = 3550476Speter "$FreeBSD$"; 361592Srgrimes#endif /* not lint */ 371592Srgrimes 381592Srgrimes/* debug print routines */ 391592Srgrimes 401592Srgrimes#include <sys/types.h> 411592Srgrimes#include <sys/socket.h> 4290868Smike#include <arpa/inet.h> 431592Srgrimes#include <protocols/talkd.h> 4431491Scharnier#include <stdio.h> 451592Srgrimes#include <syslog.h> 461592Srgrimes 4790261Simp#include "extern.h" 4890261Simp 49112998Sjmallettstatic const char *types[] = 501592Srgrimes { "leave_invite", "look_up", "delete", "announce" }; 511592Srgrimes#define NTYPES (sizeof (types) / sizeof (types[0])) 52112998Sjmallettstatic const char *answers[] = 531592Srgrimes { "success", "not_here", "failed", "machine_unknown", "permission_denied", 541592Srgrimes "unknown_request", "badversion", "badaddr", "badctladdr" }; 551592Srgrimes#define NANSWERS (sizeof (answers) / sizeof (answers[0])) 561592Srgrimes 5731491Scharniervoid 5890261Simpprint_request(const char *cp, CTL_MSG *mp) 591592Srgrimes{ 60112998Sjmallett const char *tp; 61112998Sjmallett char tbuf[80]; 628870Srgrimes 631592Srgrimes if (mp->type > NTYPES) { 6431978Simp (void)snprintf(tbuf, sizeof(tbuf), "type %d", mp->type); 651592Srgrimes tp = tbuf; 661592Srgrimes } else 671592Srgrimes tp = types[mp->type]; 6838024Sbde syslog(LOG_DEBUG, "%s: %s: id %lu, l_user %s, r_user %s, r_tty %s", 69112998Sjmallett cp, tp, (long)mp->id_num, mp->l_name, mp->r_name, mp->r_tty); 701592Srgrimes} 711592Srgrimes 7231491Scharniervoid 7390261Simpprint_response(const char *cp, CTL_RESPONSE *rp) 741592Srgrimes{ 75112998Sjmallett const char *tp, *ap; 76112998Sjmallett char tbuf[80], abuf[80]; 778870Srgrimes 781592Srgrimes if (rp->type > NTYPES) { 7931978Simp (void)snprintf(tbuf, sizeof(tbuf), "type %d", rp->type); 801592Srgrimes tp = tbuf; 811592Srgrimes } else 821592Srgrimes tp = types[rp->type]; 831592Srgrimes if (rp->answer > NANSWERS) { 8431978Simp (void)snprintf(abuf, sizeof(abuf), "answer %d", rp->answer); 851592Srgrimes ap = abuf; 861592Srgrimes } else 871592Srgrimes ap = answers[rp->answer]; 881592Srgrimes syslog(LOG_DEBUG, "%s: %s: %s, id %d", cp, tp, ap, ntohl(rp->id_num)); 891592Srgrimes} 90