unix.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2001 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* code for netstat's -k option
*
* NOTES:
* 1. A comment "LINTED: (note 1)" appears before certain lines where
* lint would have complained, "pointer cast may result in improper
* alignment". These are lines where lint had suspected potential
* improper alignment of a data structure; in each such situation
* we have relied on the kernel guaranteeing proper alignment.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#include <kstat.h>
#include <sys/socketvar.h>
#include <sys/sysmacros.h>
static char *typetoname(t_scalar_t);
static char *nextstr(char *);
extern void fail(int, char *, ...);
/*
* Print a summary of connections related to a unix protocol.
*/
void
{
fail(0, "unixpr: No kstat");
exit(3);
}
/* find the sockfs kstat: */
fail(0, "kstat_data_lookup failed\n");
}
fail(0, "kstat_read failed for sock_unix_list\n");
}
}
static void
{
int i;
char *pas; /* ptr to string-format addrs */
char *nullstr; /* ptr to null string */
char *conn_vp;
char *local_vp;
return; /* no AF_UNIX sockets found */
}
/*
* Having ks_data set with ks_data == NULL shouldn't happen;
* If it does, the sockfs kstat is seriously broken.
*/
fail(0, "print_kn: no kstat data\n");
}
/* set pas to the address strings which are after the sockinfo */
/* Create a string of NALEN "0"'s for NULL addresses. */
fail(0, "print_kn: out of memory\n");
}
(void) printf("\nActive UNIX domain sockets\n");
(void) printf("%-8.8s %-10.10s %8.8s %8.8s "
"Local Addr Remote Addr\n",
"Address", "Type", "Vnode", "Conn");
/* for each sockinfo structure, display what we need: */
/* display sonode's address. 1st string after sockinfo: */
/* laddr.sou_vp: 2nd string after sockinfo: */
}
/* faddr.sou_vp: 3rd string after sockinfo: */
}
/* laddr.soa_sa: */
psi->si_laddr_soa_len != 0) {
(void) printf(" (socketpair) ");
} else {
if (psi->si_laddr_soa_len >
sizeof (psi->si_laddr_family))
(void) printf("%s ",
else
(void) printf(" ");
}
} else
(void) printf(" ");
/* faddr.soa_sa: */
psi->si_faddr_soa_len != 0) {
(void) printf(" (socketpair) ");
} else {
if (psi->si_faddr_soa_len >
sizeof (psi->si_faddr_family))
(void) printf("%s ",
else
(void) printf(" ");
}
} else
(void) printf(" ");
(void) printf("\n");
/* if si_size didn't get filled in, then we're done */
break;
}
/* LINTED: (note 1) */
}
}
static char *
{
switch (type) {
case T_CLTS:
return ("dgram");
case T_COTS:
return ("stream");
case T_COTS_ORD:
return ("stream-ord");
default:
return ("");
}
}
/*
* nextstr(): find the beginning of a next string.
* The sockfs kstat left-justifies each address string, leaving
* null's between the strings. Since we don't necessarily know
* the sizes of pointers in the kernel, we need to skip over these
* nulls in order to get to the start of the next string.
*/
static char *
{
char *next;
next++;
}
return (next);
}