10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51548Srshoaib * Common Development and Distribution License (the "License"). 61548Srshoaib * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211548Srshoaib 220Sstevel@tonic-gate /* 23*12643SAnders.Persson@Sun.COM * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #include <stdio.h> 270Sstevel@tonic-gate #include <stdlib.h> 280Sstevel@tonic-gate #include <unistd.h> 290Sstevel@tonic-gate #include <fcntl.h> 300Sstevel@tonic-gate #include <ctype.h> 310Sstevel@tonic-gate #include <string.h> 320Sstevel@tonic-gate #include <signal.h> 330Sstevel@tonic-gate #include <dirent.h> 340Sstevel@tonic-gate #include <limits.h> 350Sstevel@tonic-gate #include <door.h> 360Sstevel@tonic-gate #include <sys/types.h> 371095Spriyanka #include <sys/socket.h> 380Sstevel@tonic-gate #include <sys/stat.h> 390Sstevel@tonic-gate #include <sys/mkdev.h> 406583Smeem #include <sys/stropts.h> 416583Smeem #include <sys/timod.h> 420Sstevel@tonic-gate #include <sys/un.h> 430Sstevel@tonic-gate #include <libproc.h> 441095Spriyanka #include <netinet/in.h> 454987Sdanmcd #include <netinet/udp.h> 460Sstevel@tonic-gate #include <arpa/inet.h> 470Sstevel@tonic-gate 483507Svb160487 #define copyflock(dst, src) \ 493507Svb160487 (dst).l_type = (src).l_type; \ 503507Svb160487 (dst).l_whence = (src).l_whence; \ 513507Svb160487 (dst).l_start = (src).l_start; \ 523507Svb160487 (dst).l_len = (src).l_len; \ 533507Svb160487 (dst).l_sysid = (src).l_sysid; \ 543507Svb160487 (dst).l_pid = (src).l_pid; 553507Svb160487 560Sstevel@tonic-gate static char *command; 570Sstevel@tonic-gate static volatile int interrupt; 580Sstevel@tonic-gate static int Fflag; 590Sstevel@tonic-gate static boolean_t nflag = B_FALSE; 600Sstevel@tonic-gate 610Sstevel@tonic-gate static void intr(int); 620Sstevel@tonic-gate static void dofcntl(struct ps_prochandle *, int, int, int); 630Sstevel@tonic-gate static void dosocket(struct ps_prochandle *, int); 646583Smeem static void dotli(struct ps_prochandle *, int); 650Sstevel@tonic-gate static void show_files(struct ps_prochandle *); 660Sstevel@tonic-gate static void show_fileflags(int); 670Sstevel@tonic-gate static void show_door(struct ps_prochandle *, int); 683507Svb160487 static int getflock(struct ps_prochandle *, int, struct flock *); 690Sstevel@tonic-gate 700Sstevel@tonic-gate int 710Sstevel@tonic-gate main(int argc, char **argv) 720Sstevel@tonic-gate { 730Sstevel@tonic-gate int retc = 0; 740Sstevel@tonic-gate int opt; 750Sstevel@tonic-gate int errflg = 0; 760Sstevel@tonic-gate struct ps_prochandle *Pr; 770Sstevel@tonic-gate 780Sstevel@tonic-gate if ((command = strrchr(argv[0], '/')) != NULL) 790Sstevel@tonic-gate command++; 800Sstevel@tonic-gate else 810Sstevel@tonic-gate command = argv[0]; 820Sstevel@tonic-gate 830Sstevel@tonic-gate /* options */ 840Sstevel@tonic-gate while ((opt = getopt(argc, argv, "Fn")) != EOF) { 850Sstevel@tonic-gate switch (opt) { 860Sstevel@tonic-gate case 'F': /* force grabbing (no O_EXCL) */ 870Sstevel@tonic-gate Fflag = PGRAB_FORCE; 880Sstevel@tonic-gate break; 890Sstevel@tonic-gate case 'n': 900Sstevel@tonic-gate nflag = B_TRUE; 910Sstevel@tonic-gate break; 920Sstevel@tonic-gate default: 930Sstevel@tonic-gate errflg = 1; 940Sstevel@tonic-gate break; 950Sstevel@tonic-gate } 960Sstevel@tonic-gate } 970Sstevel@tonic-gate 980Sstevel@tonic-gate argc -= optind; 990Sstevel@tonic-gate argv += optind; 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate if (errflg || argc <= 0) { 1020Sstevel@tonic-gate (void) fprintf(stderr, "usage:\t%s [-F] pid ...\n", 1034987Sdanmcd command); 1040Sstevel@tonic-gate (void) fprintf(stderr, 1054987Sdanmcd " (report open files of each process)\n"); 1060Sstevel@tonic-gate (void) fprintf(stderr, 1074987Sdanmcd " -F: force grabbing of the target process\n"); 1080Sstevel@tonic-gate exit(2); 1090Sstevel@tonic-gate } 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* catch signals from terminal */ 1120Sstevel@tonic-gate if (sigset(SIGHUP, SIG_IGN) == SIG_DFL) 1130Sstevel@tonic-gate (void) sigset(SIGHUP, intr); 1140Sstevel@tonic-gate if (sigset(SIGINT, SIG_IGN) == SIG_DFL) 1150Sstevel@tonic-gate (void) sigset(SIGINT, intr); 1160Sstevel@tonic-gate if (sigset(SIGQUIT, SIG_IGN) == SIG_DFL) 1170Sstevel@tonic-gate (void) sigset(SIGQUIT, intr); 1180Sstevel@tonic-gate (void) sigset(SIGPIPE, intr); 1190Sstevel@tonic-gate (void) sigset(SIGTERM, intr); 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate (void) proc_initstdio(); 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate while (--argc >= 0 && !interrupt) { 1250Sstevel@tonic-gate char *arg; 1260Sstevel@tonic-gate psinfo_t psinfo; 1270Sstevel@tonic-gate pid_t pid; 1280Sstevel@tonic-gate int gret; 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate (void) proc_flushstdio(); 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* get the specified pid and the psinfo struct */ 1330Sstevel@tonic-gate if ((pid = proc_arg_psinfo(arg = *argv++, PR_ARG_PIDS, 1340Sstevel@tonic-gate &psinfo, &gret)) == -1) { 1350Sstevel@tonic-gate (void) fprintf(stderr, "%s: cannot examine %s: %s\n", 1364987Sdanmcd command, arg, Pgrab_error(gret)); 1370Sstevel@tonic-gate retc++; 1380Sstevel@tonic-gate } else if ((Pr = Pgrab(pid, Fflag, &gret)) != NULL) { 1390Sstevel@tonic-gate if (Pcreate_agent(Pr) == 0) { 1400Sstevel@tonic-gate proc_unctrl_psinfo(&psinfo); 1410Sstevel@tonic-gate (void) printf("%d:\t%.70s\n", 1424987Sdanmcd (int)pid, psinfo.pr_psargs); 1430Sstevel@tonic-gate show_files(Pr); 1440Sstevel@tonic-gate Pdestroy_agent(Pr); 1450Sstevel@tonic-gate } else { 1460Sstevel@tonic-gate (void) fprintf(stderr, 1474987Sdanmcd "%s: cannot control process %d\n", 1484987Sdanmcd command, (int)pid); 1490Sstevel@tonic-gate retc++; 1500Sstevel@tonic-gate } 1510Sstevel@tonic-gate Prelease(Pr, 0); 1520Sstevel@tonic-gate Pr = NULL; 1530Sstevel@tonic-gate } else { 1540Sstevel@tonic-gate switch (gret) { 1550Sstevel@tonic-gate case G_SYS: 1560Sstevel@tonic-gate case G_SELF: 1570Sstevel@tonic-gate proc_unctrl_psinfo(&psinfo); 1580Sstevel@tonic-gate (void) printf("%d:\t%.70s\n", (int)pid, 1594987Sdanmcd psinfo.pr_psargs); 1600Sstevel@tonic-gate if (gret == G_SYS) 1610Sstevel@tonic-gate (void) printf(" [system process]\n"); 1620Sstevel@tonic-gate else 1630Sstevel@tonic-gate show_files(NULL); 1640Sstevel@tonic-gate break; 1650Sstevel@tonic-gate default: 1660Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s: %d\n", 1674987Sdanmcd command, Pgrab_error(gret), (int)pid); 1680Sstevel@tonic-gate retc++; 1690Sstevel@tonic-gate break; 1700Sstevel@tonic-gate } 1710Sstevel@tonic-gate } 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate (void) proc_finistdio(); 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate if (interrupt && retc == 0) 1770Sstevel@tonic-gate retc++; 1780Sstevel@tonic-gate return (retc); 1790Sstevel@tonic-gate } 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate /* ARGSUSED */ 1820Sstevel@tonic-gate static void 1830Sstevel@tonic-gate intr(int sig) 1840Sstevel@tonic-gate { 1850Sstevel@tonic-gate interrupt = 1; 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate /* ------ begin specific code ------ */ 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate static void 1910Sstevel@tonic-gate show_files(struct ps_prochandle *Pr) 1920Sstevel@tonic-gate { 1930Sstevel@tonic-gate DIR *dirp; 1940Sstevel@tonic-gate struct dirent *dentp; 1956583Smeem const char *dev; 1960Sstevel@tonic-gate char pname[100]; 1970Sstevel@tonic-gate char fname[PATH_MAX]; 1980Sstevel@tonic-gate struct stat64 statb; 1990Sstevel@tonic-gate struct rlimit rlim; 2000Sstevel@tonic-gate pid_t pid; 2010Sstevel@tonic-gate int fd; 2020Sstevel@tonic-gate char *s; 2030Sstevel@tonic-gate int ret; 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate if (pr_getrlimit(Pr, RLIMIT_NOFILE, &rlim) == 0) { 2060Sstevel@tonic-gate ulong_t nfd = rlim.rlim_cur; 2070Sstevel@tonic-gate if (nfd == RLIM_INFINITY) 2080Sstevel@tonic-gate (void) printf( 2090Sstevel@tonic-gate " Current rlimit: unlimited file descriptors\n"); 2100Sstevel@tonic-gate else 2110Sstevel@tonic-gate (void) printf( 2120Sstevel@tonic-gate " Current rlimit: %lu file descriptors\n", nfd); 2130Sstevel@tonic-gate } 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate /* in case we are doing this to ourself */ 2160Sstevel@tonic-gate pid = (Pr == NULL)? getpid() : Pstatus(Pr)->pr_pid; 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate (void) sprintf(pname, "/proc/%d/fd", (int)pid); 2190Sstevel@tonic-gate if ((dirp = opendir(pname)) == NULL) { 2200Sstevel@tonic-gate (void) fprintf(stderr, "%s: cannot open directory %s\n", 2210Sstevel@tonic-gate command, pname); 2220Sstevel@tonic-gate return; 2230Sstevel@tonic-gate } 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /* for each open file --- */ 2260Sstevel@tonic-gate while ((dentp = readdir(dirp)) != NULL && !interrupt) { 2270Sstevel@tonic-gate char unknown[12]; 2280Sstevel@tonic-gate dev_t rdev; 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate /* skip '.' and '..' */ 2310Sstevel@tonic-gate if (!isdigit(dentp->d_name[0])) 2320Sstevel@tonic-gate continue; 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate fd = atoi(dentp->d_name); 2350Sstevel@tonic-gate if (pr_fstat64(Pr, fd, &statb) == -1) { 2360Sstevel@tonic-gate s = unknown; 2370Sstevel@tonic-gate (void) sprintf(s, "%4d", fd); 2380Sstevel@tonic-gate perror(s); 2390Sstevel@tonic-gate continue; 2400Sstevel@tonic-gate } 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate rdev = NODEV; 2430Sstevel@tonic-gate switch (statb.st_mode & S_IFMT) { 2440Sstevel@tonic-gate case S_IFCHR: s = "S_IFCHR"; rdev = statb.st_rdev; break; 2450Sstevel@tonic-gate case S_IFBLK: s = "S_IFBLK"; rdev = statb.st_rdev; break; 2460Sstevel@tonic-gate case S_IFIFO: s = "S_IFIFO"; break; 2470Sstevel@tonic-gate case S_IFDIR: s = "S_IFDIR"; break; 2480Sstevel@tonic-gate case S_IFREG: s = "S_IFREG"; break; 2490Sstevel@tonic-gate case S_IFLNK: s = "S_IFLNK"; break; 2500Sstevel@tonic-gate case S_IFSOCK: s = "S_IFSOCK"; break; 2510Sstevel@tonic-gate case S_IFDOOR: s = "S_IFDOOR"; break; 2520Sstevel@tonic-gate case S_IFPORT: s = "S_IFPORT"; break; 2530Sstevel@tonic-gate default: 2540Sstevel@tonic-gate s = unknown; 2550Sstevel@tonic-gate (void) sprintf(s, "0x%.4x ", 2564987Sdanmcd (int)statb.st_mode & S_IFMT); 2570Sstevel@tonic-gate break; 2580Sstevel@tonic-gate } 2590Sstevel@tonic-gate 2604987Sdanmcd (void) printf("%4d: %s mode:0%.3o", fd, s, 2614987Sdanmcd (int)statb.st_mode & ~S_IFMT); 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate if (major(statb.st_dev) != (major_t)NODEV && 2640Sstevel@tonic-gate minor(statb.st_dev) != (minor_t)NODEV) 2650Sstevel@tonic-gate (void) printf(" dev:%lu,%lu", 2664987Sdanmcd (ulong_t)major(statb.st_dev), 2674987Sdanmcd (ulong_t)minor(statb.st_dev)); 2680Sstevel@tonic-gate else 2690Sstevel@tonic-gate (void) printf(" dev:0x%.8lX", (long)statb.st_dev); 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate if ((statb.st_mode & S_IFMT) == S_IFPORT) { 2720Sstevel@tonic-gate (void) printf(" uid:%d gid:%d", 2730Sstevel@tonic-gate (int)statb.st_uid, 2740Sstevel@tonic-gate (int)statb.st_gid); 2750Sstevel@tonic-gate (void) printf(" size:%lld\n", 2760Sstevel@tonic-gate (longlong_t)statb.st_size); 2770Sstevel@tonic-gate continue; 2780Sstevel@tonic-gate } 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate (void) printf(" ino:%llu uid:%d gid:%d", 2814987Sdanmcd (u_longlong_t)statb.st_ino, 2824987Sdanmcd (int)statb.st_uid, (int)statb.st_gid); 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate if (rdev == NODEV) 2850Sstevel@tonic-gate (void) printf(" size:%lld\n", 2864987Sdanmcd (longlong_t)statb.st_size); 2870Sstevel@tonic-gate else if (major(rdev) != (major_t)NODEV && 2880Sstevel@tonic-gate minor(rdev) != (minor_t)NODEV) 2890Sstevel@tonic-gate (void) printf(" rdev:%lu,%lu\n", 2904987Sdanmcd (ulong_t)major(rdev), (ulong_t)minor(rdev)); 2910Sstevel@tonic-gate else 2920Sstevel@tonic-gate (void) printf(" rdev:0x%.8lX\n", (long)rdev); 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate if (!nflag) { 29511281SDan.Mick@Sun.COM off_t offset; 29611281SDan.Mick@Sun.COM 2970Sstevel@tonic-gate dofcntl(Pr, fd, 2984987Sdanmcd (statb.st_mode & (S_IFMT|S_ENFMT|S_IXGRP)) 2994987Sdanmcd == (S_IFREG|S_ENFMT), 3004987Sdanmcd (statb.st_mode & S_IFMT) == S_IFDOOR); 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate if ((statb.st_mode & S_IFMT) == S_IFSOCK) 3030Sstevel@tonic-gate dosocket(Pr, fd); 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate (void) sprintf(pname, "/proc/%d/path/%d", (int)pid, fd); 3060Sstevel@tonic-gate 3076583Smeem if ((ret = readlink(pname, fname, PATH_MAX - 1)) <= 0) 3086583Smeem continue; 3096583Smeem 3106583Smeem fname[ret] = '\0'; 3116583Smeem 3126583Smeem if ((statb.st_mode & S_IFMT) == S_IFCHR && 3136583Smeem (dev = strrchr(fname, ':')) != NULL) { 3146583Smeem /* 3156583Smeem * There's no elegant way to determine if a 3166583Smeem * character device supports TLI, so we lame 3176583Smeem * out and just check a hardcoded list of 3186583Smeem * known TLI devices. 3196583Smeem */ 3206583Smeem int i; 3216583Smeem const char *tlidevs[] = 3226583Smeem { "tcp", "tcp6", "udp", "udp6", NULL }; 3236583Smeem 3246583Smeem dev++; /* skip past the `:' */ 3256583Smeem for (i = 0; tlidevs[i] != NULL; i++) { 3266583Smeem if (strcmp(dev, tlidevs[i]) == 0) { 3276583Smeem dotli(Pr, fd); 3286583Smeem break; 3296583Smeem } 3306583Smeem } 3310Sstevel@tonic-gate } 3326583Smeem (void) printf(" %s\n", fname); 33311281SDan.Mick@Sun.COM 33411281SDan.Mick@Sun.COM offset = pr_lseek(Pr, fd, 0, SEEK_CUR); 33511281SDan.Mick@Sun.COM if (offset != -1) { 33611281SDan.Mick@Sun.COM (void) printf(" offset:%ld\n", offset); 33711281SDan.Mick@Sun.COM } 33811281SDan.Mick@Sun.COM 3390Sstevel@tonic-gate } 3400Sstevel@tonic-gate } 3410Sstevel@tonic-gate (void) closedir(dirp); 3420Sstevel@tonic-gate } 3430Sstevel@tonic-gate 3443507Svb160487 3453507Svb160487 static int 3463507Svb160487 getflock(struct ps_prochandle *Pr, int fd, struct flock *flock_native) 3473507Svb160487 { 3483507Svb160487 int ret; 3493507Svb160487 #ifdef _LP64 3503507Svb160487 struct flock64_32 flock_target; 3513507Svb160487 3523507Svb160487 if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) { 3533507Svb160487 copyflock(flock_target, *flock_native); 3543507Svb160487 ret = pr_fcntl(Pr, fd, F_GETLK, &flock_target); 3553507Svb160487 copyflock(*flock_native, flock_target); 3563507Svb160487 return (ret); 3573507Svb160487 } 3583507Svb160487 #endif /* _LP64 */ 3593507Svb160487 ret = pr_fcntl(Pr, fd, F_GETLK, flock_native); 3603507Svb160487 return (ret); 3613507Svb160487 } 3623507Svb160487 3630Sstevel@tonic-gate /* examine open file with fcntl() */ 3640Sstevel@tonic-gate static void 3654987Sdanmcd dofcntl(struct ps_prochandle *Pr, int fd, int mandatory, int isdoor) 3660Sstevel@tonic-gate { 3670Sstevel@tonic-gate struct flock flock; 3680Sstevel@tonic-gate int fileflags; 3690Sstevel@tonic-gate int fdflags; 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate fileflags = pr_fcntl(Pr, fd, F_GETXFL, 0); 3720Sstevel@tonic-gate fdflags = pr_fcntl(Pr, fd, F_GETFD, 0); 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate if (fileflags != -1 || fdflags != -1) { 3750Sstevel@tonic-gate (void) printf(" "); 3760Sstevel@tonic-gate if (fileflags != -1) 3770Sstevel@tonic-gate show_fileflags(fileflags); 3780Sstevel@tonic-gate if (fdflags != -1 && (fdflags & FD_CLOEXEC)) 3790Sstevel@tonic-gate (void) printf(" FD_CLOEXEC"); 3800Sstevel@tonic-gate if (isdoor) 3810Sstevel@tonic-gate show_door(Pr, fd); 3820Sstevel@tonic-gate (void) fputc('\n', stdout); 3830Sstevel@tonic-gate } else if (isdoor) { 3840Sstevel@tonic-gate (void) printf(" "); 3850Sstevel@tonic-gate show_door(Pr, fd); 3860Sstevel@tonic-gate (void) fputc('\n', stdout); 3870Sstevel@tonic-gate } 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate flock.l_type = F_WRLCK; 3900Sstevel@tonic-gate flock.l_whence = 0; 3910Sstevel@tonic-gate flock.l_start = 0; 3920Sstevel@tonic-gate flock.l_len = 0; 3930Sstevel@tonic-gate flock.l_sysid = 0; 3940Sstevel@tonic-gate flock.l_pid = 0; 3953507Svb160487 if (getflock(Pr, fd, &flock) != -1) { 3960Sstevel@tonic-gate if (flock.l_type != F_UNLCK && (flock.l_sysid || flock.l_pid)) { 3970Sstevel@tonic-gate unsigned long sysid = flock.l_sysid; 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate (void) printf(" %s %s lock set by", 4004987Sdanmcd mandatory ? "mandatory" : "advisory", 4014987Sdanmcd flock.l_type == F_RDLCK? "read" : "write"); 4020Sstevel@tonic-gate if (sysid) 4030Sstevel@tonic-gate (void) printf(" system 0x%lX", sysid); 4040Sstevel@tonic-gate if (flock.l_pid) 4050Sstevel@tonic-gate (void) printf(" process %d", (int)flock.l_pid); 4060Sstevel@tonic-gate (void) fputc('\n', stdout); 4070Sstevel@tonic-gate } 4080Sstevel@tonic-gate } 4090Sstevel@tonic-gate } 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate #ifdef O_PRIV 4120Sstevel@tonic-gate #define ALL_O_FLAGS O_ACCMODE | O_NDELAY | O_NONBLOCK | O_APPEND | \ 4130Sstevel@tonic-gate O_PRIV | O_SYNC | O_DSYNC | O_RSYNC | O_XATTR | \ 4140Sstevel@tonic-gate O_CREAT | O_TRUNC | O_EXCL | O_NOCTTY | O_LARGEFILE 4150Sstevel@tonic-gate #else 4160Sstevel@tonic-gate #define ALL_O_FLAGS O_ACCMODE | O_NDELAY | O_NONBLOCK | O_APPEND | \ 4170Sstevel@tonic-gate O_SYNC | O_DSYNC | O_RSYNC | O_XATTR | \ 4180Sstevel@tonic-gate O_CREAT | O_TRUNC | O_EXCL | O_NOCTTY | O_LARGEFILE 4190Sstevel@tonic-gate #endif 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate static void 4220Sstevel@tonic-gate show_fileflags(int flags) 4230Sstevel@tonic-gate { 4240Sstevel@tonic-gate char buffer[136]; 4250Sstevel@tonic-gate char *str = buffer; 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate switch (flags & O_ACCMODE) { 4280Sstevel@tonic-gate case O_RDONLY: 4290Sstevel@tonic-gate (void) strcpy(str, "O_RDONLY"); 4300Sstevel@tonic-gate break; 4310Sstevel@tonic-gate case O_WRONLY: 4320Sstevel@tonic-gate (void) strcpy(str, "O_WRONLY"); 4330Sstevel@tonic-gate break; 4340Sstevel@tonic-gate case O_RDWR: 4350Sstevel@tonic-gate (void) strcpy(str, "O_RDWR"); 4360Sstevel@tonic-gate break; 4370Sstevel@tonic-gate default: 4380Sstevel@tonic-gate (void) sprintf(str, "0x%x", flags & O_ACCMODE); 4390Sstevel@tonic-gate break; 4400Sstevel@tonic-gate } 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate if (flags & O_NDELAY) 4430Sstevel@tonic-gate (void) strcat(str, "|O_NDELAY"); 4440Sstevel@tonic-gate if (flags & O_NONBLOCK) 4450Sstevel@tonic-gate (void) strcat(str, "|O_NONBLOCK"); 4460Sstevel@tonic-gate if (flags & O_APPEND) 4470Sstevel@tonic-gate (void) strcat(str, "|O_APPEND"); 4480Sstevel@tonic-gate #ifdef O_PRIV 4490Sstevel@tonic-gate if (flags & O_PRIV) 4500Sstevel@tonic-gate (void) strcat(str, "|O_PRIV"); 4510Sstevel@tonic-gate #endif 4520Sstevel@tonic-gate if (flags & O_SYNC) 4530Sstevel@tonic-gate (void) strcat(str, "|O_SYNC"); 4540Sstevel@tonic-gate if (flags & O_DSYNC) 4550Sstevel@tonic-gate (void) strcat(str, "|O_DSYNC"); 4560Sstevel@tonic-gate if (flags & O_RSYNC) 4570Sstevel@tonic-gate (void) strcat(str, "|O_RSYNC"); 4580Sstevel@tonic-gate if (flags & O_CREAT) 4590Sstevel@tonic-gate (void) strcat(str, "|O_CREAT"); 4600Sstevel@tonic-gate if (flags & O_TRUNC) 4610Sstevel@tonic-gate (void) strcat(str, "|O_TRUNC"); 4620Sstevel@tonic-gate if (flags & O_EXCL) 4630Sstevel@tonic-gate (void) strcat(str, "|O_EXCL"); 4640Sstevel@tonic-gate if (flags & O_NOCTTY) 4650Sstevel@tonic-gate (void) strcat(str, "|O_NOCTTY"); 4660Sstevel@tonic-gate if (flags & O_LARGEFILE) 4670Sstevel@tonic-gate (void) strcat(str, "|O_LARGEFILE"); 4680Sstevel@tonic-gate if (flags & O_XATTR) 4690Sstevel@tonic-gate (void) strcat(str, "|O_XATTR"); 4700Sstevel@tonic-gate if (flags & ~(ALL_O_FLAGS)) 4710Sstevel@tonic-gate (void) sprintf(str + strlen(str), "|0x%x", 4724987Sdanmcd flags & ~(ALL_O_FLAGS)); 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate (void) printf("%s", str); 4750Sstevel@tonic-gate } 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate /* show door info */ 4780Sstevel@tonic-gate static void 4790Sstevel@tonic-gate show_door(struct ps_prochandle *Pr, int fd) 4800Sstevel@tonic-gate { 4810Sstevel@tonic-gate door_info_t door_info; 4820Sstevel@tonic-gate psinfo_t psinfo; 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate if (pr_door_info(Pr, fd, &door_info) != 0) 4850Sstevel@tonic-gate return; 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate if (proc_get_psinfo(door_info.di_target, &psinfo) != 0) 4880Sstevel@tonic-gate psinfo.pr_fname[0] = '\0'; 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate (void) printf(" door to "); 4910Sstevel@tonic-gate if (psinfo.pr_fname[0] != '\0') 4920Sstevel@tonic-gate (void) printf("%s[%d]", psinfo.pr_fname, 4934987Sdanmcd (int)door_info.di_target); 4940Sstevel@tonic-gate else 4950Sstevel@tonic-gate (void) printf("pid %d", (int)door_info.di_target); 4960Sstevel@tonic-gate } 4970Sstevel@tonic-gate 4986583Smeem /* 4996583Smeem * Print out the socket address pointed to by `sa'. `len' is only 5006583Smeem * needed for AF_UNIX sockets. 5016583Smeem */ 5020Sstevel@tonic-gate static void 5030Sstevel@tonic-gate show_sockaddr(const char *str, struct sockaddr *sa, socklen_t len) 5040Sstevel@tonic-gate { 5056583Smeem struct sockaddr_in *so_in = (struct sockaddr_in *)(void *)sa; 5066583Smeem struct sockaddr_in6 *so_in6 = (struct sockaddr_in6 *)(void *)sa; 5070Sstevel@tonic-gate struct sockaddr_un *so_un = (struct sockaddr_un *)sa; 5080Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN]; 5090Sstevel@tonic-gate const char *p; 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate switch (sa->sa_family) { 5120Sstevel@tonic-gate default: 5130Sstevel@tonic-gate return; 5140Sstevel@tonic-gate case AF_INET: 5156583Smeem (void) printf("\t%s: AF_INET %s port: %u\n", str, 5160Sstevel@tonic-gate inet_ntop(AF_INET, &so_in->sin_addr, abuf, sizeof (abuf)), 5170Sstevel@tonic-gate ntohs(so_in->sin_port)); 5180Sstevel@tonic-gate return; 5190Sstevel@tonic-gate case AF_INET6: 5206583Smeem (void) printf("\t%s: AF_INET6 %s port: %u\n", str, 5210Sstevel@tonic-gate inet_ntop(AF_INET6, &so_in6->sin6_addr, 5220Sstevel@tonic-gate abuf, sizeof (abuf)), 5230Sstevel@tonic-gate ntohs(so_in->sin_port)); 5240Sstevel@tonic-gate return; 5250Sstevel@tonic-gate case AF_UNIX: 5260Sstevel@tonic-gate if (len >= sizeof (so_un->sun_family)) { 5270Sstevel@tonic-gate /* Null terminate */ 5280Sstevel@tonic-gate len -= sizeof (so_un->sun_family); 5296583Smeem so_un->sun_path[len] = '\0'; 5300Sstevel@tonic-gate (void) printf("\t%s: AF_UNIX %s\n", 5314987Sdanmcd str, so_un->sun_path); 5320Sstevel@tonic-gate } 5330Sstevel@tonic-gate return; 5340Sstevel@tonic-gate case AF_IMPLINK: p = "AF_IMPLINK"; break; 5350Sstevel@tonic-gate case AF_PUP: p = "AF_PUP"; break; 5360Sstevel@tonic-gate case AF_CHAOS: p = "AF_CHAOS"; break; 5370Sstevel@tonic-gate case AF_NS: p = "AF_NS"; break; 5380Sstevel@tonic-gate case AF_NBS: p = "AF_NBS"; break; 5390Sstevel@tonic-gate case AF_ECMA: p = "AF_ECMA"; break; 5400Sstevel@tonic-gate case AF_DATAKIT: p = "AF_DATAKIT"; break; 5410Sstevel@tonic-gate case AF_CCITT: p = "AF_CCITT"; break; 5420Sstevel@tonic-gate case AF_SNA: p = "AF_SNA"; break; 5430Sstevel@tonic-gate case AF_DECnet: p = "AF_DECnet"; break; 5440Sstevel@tonic-gate case AF_DLI: p = "AF_DLI"; break; 5450Sstevel@tonic-gate case AF_LAT: p = "AF_LAT"; break; 5460Sstevel@tonic-gate case AF_HYLINK: p = "AF_HYLINK"; break; 5470Sstevel@tonic-gate case AF_APPLETALK: p = "AF_APPLETALK"; break; 5480Sstevel@tonic-gate case AF_NIT: p = "AF_NIT"; break; 5490Sstevel@tonic-gate case AF_802: p = "AF_802"; break; 5500Sstevel@tonic-gate case AF_OSI: p = "AF_OSI"; break; 5510Sstevel@tonic-gate case AF_X25: p = "AF_X25"; break; 5520Sstevel@tonic-gate case AF_OSINET: p = "AF_OSINET"; break; 5530Sstevel@tonic-gate case AF_GOSIP: p = "AF_GOSIP"; break; 5540Sstevel@tonic-gate case AF_IPX: p = "AF_IPX"; break; 5550Sstevel@tonic-gate case AF_ROUTE: p = "AF_ROUTE"; break; 5560Sstevel@tonic-gate case AF_LINK: p = "AF_LINK"; break; 5570Sstevel@tonic-gate } 5580Sstevel@tonic-gate 5590Sstevel@tonic-gate (void) printf("\t%s: %s\n", str, p); 5600Sstevel@tonic-gate } 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate static void 5630Sstevel@tonic-gate show_socktype(uint_t type) 5640Sstevel@tonic-gate { 5650Sstevel@tonic-gate static const char *types[] = { 5660Sstevel@tonic-gate NULL, "DGRAM", "STREAM", NULL, "RAW", "RDM", "SEQPACKET" 5670Sstevel@tonic-gate }; 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate if (type < sizeof (types) / sizeof (*types) && types[type] != NULL) 5700Sstevel@tonic-gate (void) printf("\tSOCK_%s\n", types[type]); 5710Sstevel@tonic-gate else 5720Sstevel@tonic-gate (void) printf("\tunknown socket type %u\n", type); 5730Sstevel@tonic-gate } 5740Sstevel@tonic-gate 5751095Spriyanka #define BUFSIZE 200 5760Sstevel@tonic-gate static void 5770Sstevel@tonic-gate show_sockopts(struct ps_prochandle *Pr, int fd) 5780Sstevel@tonic-gate { 5790Sstevel@tonic-gate int val, vlen; 5801095Spriyanka char buf[BUFSIZE]; 5810Sstevel@tonic-gate char buf1[32]; 5821095Spriyanka char ipaddr[INET_ADDRSTRLEN]; 5830Sstevel@tonic-gate int i; 5841095Spriyanka in_addr_t nexthop_val; 5850Sstevel@tonic-gate struct boolopt { 5864987Sdanmcd int level; 5870Sstevel@tonic-gate int opt; 5880Sstevel@tonic-gate const char *name; 5890Sstevel@tonic-gate }; 5900Sstevel@tonic-gate static struct boolopt boolopts[] = { 5914987Sdanmcd { SOL_SOCKET, SO_DEBUG, "SO_DEBUG," }, 5924987Sdanmcd { SOL_SOCKET, SO_REUSEADDR, "SO_REUSEADDR," }, 5934987Sdanmcd { SOL_SOCKET, SO_KEEPALIVE, "SO_KEEPALIVE," }, 5944987Sdanmcd { SOL_SOCKET, SO_DONTROUTE, "SO_DONTROUTE," }, 5954987Sdanmcd { SOL_SOCKET, SO_BROADCAST, "SO_BROADCAST," }, 5964987Sdanmcd { SOL_SOCKET, SO_OOBINLINE, "SO_OOBINLINE," }, 5974987Sdanmcd { SOL_SOCKET, SO_DGRAM_ERRIND, "SO_DGRAM_ERRIND,"}, 5984987Sdanmcd { SOL_SOCKET, SO_ALLZONES, "SO_ALLZONES," }, 59910934Ssommerfeld@sun.com { SOL_SOCKET, SO_MAC_EXEMPT, "SO_MAC_EXEMPT," }, 60010934Ssommerfeld@sun.com { SOL_SOCKET, SO_MAC_IMPLICIT, "SO_MAC_IMPLICIT," }, 6014987Sdanmcd { SOL_SOCKET, SO_EXCLBIND, "SO_EXCLBIND," }, 60211076SCathy.Zhou@Sun.COM { SOL_SOCKET, SO_VRRP, "SO_VRRP," }, 6034987Sdanmcd { IPPROTO_UDP, UDP_NAT_T_ENDPOINT, "UDP_NAT_T_ENDPOINT," }, 6040Sstevel@tonic-gate }; 6050Sstevel@tonic-gate struct linger l; 6060Sstevel@tonic-gate 6072263Ssommerfe buf[0] = '!'; /* sentinel value, never printed */ 6080Sstevel@tonic-gate buf[1] = '\0'; 6090Sstevel@tonic-gate 6100Sstevel@tonic-gate for (i = 0; i < sizeof (boolopts) / sizeof (boolopts[0]); i++) { 6110Sstevel@tonic-gate vlen = sizeof (val); 6124987Sdanmcd if (pr_getsockopt(Pr, fd, boolopts[i].level, boolopts[i].opt, 6134987Sdanmcd &val, &vlen) == 0 && val != 0) 6140Sstevel@tonic-gate (void) strlcat(buf, boolopts[i].name, sizeof (buf)); 6150Sstevel@tonic-gate } 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate vlen = sizeof (l); 6180Sstevel@tonic-gate if (pr_getsockopt(Pr, fd, SOL_SOCKET, SO_LINGER, &l, &vlen) == 0 && 6190Sstevel@tonic-gate l.l_onoff != 0) { 6200Sstevel@tonic-gate (void) snprintf(buf1, sizeof (buf1), "SO_LINGER(%d),", 6210Sstevel@tonic-gate l.l_linger); 6220Sstevel@tonic-gate (void) strlcat(buf, buf1, sizeof (buf)); 6230Sstevel@tonic-gate } 6240Sstevel@tonic-gate 6250Sstevel@tonic-gate vlen = sizeof (val); 6260Sstevel@tonic-gate if (pr_getsockopt(Pr, fd, SOL_SOCKET, SO_SNDBUF, &val, &vlen) == 0) { 6270Sstevel@tonic-gate (void) snprintf(buf1, sizeof (buf1), "SO_SNDBUF(%d),", val); 6280Sstevel@tonic-gate (void) strlcat(buf, buf1, sizeof (buf)); 6290Sstevel@tonic-gate } 6300Sstevel@tonic-gate vlen = sizeof (val); 6310Sstevel@tonic-gate if (pr_getsockopt(Pr, fd, SOL_SOCKET, SO_RCVBUF, &val, &vlen) == 0) { 6320Sstevel@tonic-gate (void) snprintf(buf1, sizeof (buf1), "SO_RCVBUF(%d),", val); 6330Sstevel@tonic-gate (void) strlcat(buf, buf1, sizeof (buf)); 6340Sstevel@tonic-gate } 6351095Spriyanka vlen = sizeof (nexthop_val); 6361095Spriyanka if (pr_getsockopt(Pr, fd, IPPROTO_IP, IP_NEXTHOP, &nexthop_val, 6371095Spriyanka &vlen) == 0) { 6381628Spriyanka if (vlen > 0) { 6391628Spriyanka (void) inet_ntop(AF_INET, (void *) &nexthop_val, 6401628Spriyanka ipaddr, sizeof (ipaddr)); 6411628Spriyanka (void) snprintf(buf1, sizeof (buf1), "IP_NEXTHOP(%s),", 6421628Spriyanka ipaddr); 6431628Spriyanka (void) strlcat(buf, buf1, sizeof (buf)); 6441628Spriyanka } 6451095Spriyanka } 6460Sstevel@tonic-gate 6472263Ssommerfe buf[strlen(buf) - 1] = '\0'; /* overwrites sentinel if no options */ 6480Sstevel@tonic-gate if (buf[1] != '\0') 6490Sstevel@tonic-gate (void) printf("\t%s\n", buf+1); 6500Sstevel@tonic-gate } 6510Sstevel@tonic-gate 652*12643SAnders.Persson@Sun.COM #define MAXNALLOC 32 653*12643SAnders.Persson@Sun.COM static void 654*12643SAnders.Persson@Sun.COM show_sockfilters(struct ps_prochandle *Pr, int fd) 655*12643SAnders.Persson@Sun.COM { 656*12643SAnders.Persson@Sun.COM struct fil_info *fi; 657*12643SAnders.Persson@Sun.COM int i = 0, nalloc = 2, len = nalloc * sizeof (*fi); 658*12643SAnders.Persson@Sun.COM boolean_t printhdr = B_TRUE; 659*12643SAnders.Persson@Sun.COM 660*12643SAnders.Persson@Sun.COM fi = calloc(nalloc, sizeof (*fi)); 661*12643SAnders.Persson@Sun.COM if (fi == NULL) { 662*12643SAnders.Persson@Sun.COM perror("calloc"); 663*12643SAnders.Persson@Sun.COM return; 664*12643SAnders.Persson@Sun.COM } 665*12643SAnders.Persson@Sun.COM /* CONSTCOND */ 666*12643SAnders.Persson@Sun.COM while (1) { 667*12643SAnders.Persson@Sun.COM if (pr_getsockopt(Pr, fd, SOL_FILTER, FIL_LIST, fi, &len) != 0) 668*12643SAnders.Persson@Sun.COM break; 669*12643SAnders.Persson@Sun.COM /* No filters */ 670*12643SAnders.Persson@Sun.COM if (len == 0) 671*12643SAnders.Persson@Sun.COM break; 672*12643SAnders.Persson@Sun.COM /* Make sure buffer was large enough */ 673*12643SAnders.Persson@Sun.COM if (fi->fi_pos >= nalloc) { 674*12643SAnders.Persson@Sun.COM struct fil_info *new; 675*12643SAnders.Persson@Sun.COM 676*12643SAnders.Persson@Sun.COM nalloc = fi->fi_pos + 1; 677*12643SAnders.Persson@Sun.COM if (nalloc > MAXNALLOC) 678*12643SAnders.Persson@Sun.COM break; 679*12643SAnders.Persson@Sun.COM len = nalloc * sizeof (*fi); 680*12643SAnders.Persson@Sun.COM new = realloc(fi, nalloc * sizeof (*fi)); 681*12643SAnders.Persson@Sun.COM if (new == NULL) { 682*12643SAnders.Persson@Sun.COM perror("realloc"); 683*12643SAnders.Persson@Sun.COM break; 684*12643SAnders.Persson@Sun.COM } 685*12643SAnders.Persson@Sun.COM fi = new; 686*12643SAnders.Persson@Sun.COM continue; 687*12643SAnders.Persson@Sun.COM } 688*12643SAnders.Persson@Sun.COM 689*12643SAnders.Persson@Sun.COM for (i = 0; (i + 1) * sizeof (*fi) <= len; i++) { 690*12643SAnders.Persson@Sun.COM if (fi[i].fi_flags & FILF_BYPASS) 691*12643SAnders.Persson@Sun.COM continue; 692*12643SAnders.Persson@Sun.COM if (printhdr) { 693*12643SAnders.Persson@Sun.COM (void) printf("\tfilters: "); 694*12643SAnders.Persson@Sun.COM printhdr = B_FALSE; 695*12643SAnders.Persson@Sun.COM } 696*12643SAnders.Persson@Sun.COM (void) printf("%s", fi[i].fi_name); 697*12643SAnders.Persson@Sun.COM if (fi[i].fi_flags != 0) { 698*12643SAnders.Persson@Sun.COM (void) printf("("); 699*12643SAnders.Persson@Sun.COM if (fi[i].fi_flags & FILF_AUTO) 700*12643SAnders.Persson@Sun.COM (void) printf("auto,"); 701*12643SAnders.Persson@Sun.COM if (fi[i].fi_flags & FILF_PROG) 702*12643SAnders.Persson@Sun.COM (void) printf("prog,"); 703*12643SAnders.Persson@Sun.COM (void) printf("\b)"); 704*12643SAnders.Persson@Sun.COM } 705*12643SAnders.Persson@Sun.COM if (fi[i].fi_pos == 0) /* last one */ 706*12643SAnders.Persson@Sun.COM break; 707*12643SAnders.Persson@Sun.COM (void) printf(","); 708*12643SAnders.Persson@Sun.COM } 709*12643SAnders.Persson@Sun.COM if (!printhdr) 710*12643SAnders.Persson@Sun.COM (void) printf("\n"); 711*12643SAnders.Persson@Sun.COM break; 712*12643SAnders.Persson@Sun.COM } 713*12643SAnders.Persson@Sun.COM free(fi); 714*12643SAnders.Persson@Sun.COM } 715*12643SAnders.Persson@Sun.COM 7160Sstevel@tonic-gate /* the file is a socket */ 7170Sstevel@tonic-gate static void 7180Sstevel@tonic-gate dosocket(struct ps_prochandle *Pr, int fd) 7190Sstevel@tonic-gate { 7200Sstevel@tonic-gate /* A buffer large enough for PATH_MAX size AF_UNIX address */ 7210Sstevel@tonic-gate long buf[(sizeof (short) + PATH_MAX + sizeof (long) - 1) 7224987Sdanmcd / sizeof (long)]; 7230Sstevel@tonic-gate struct sockaddr *sa = (struct sockaddr *)buf; 7240Sstevel@tonic-gate socklen_t len; 7250Sstevel@tonic-gate int type, tlen; 7260Sstevel@tonic-gate 7270Sstevel@tonic-gate tlen = sizeof (type); 7286583Smeem if (pr_getsockopt(Pr, fd, SOL_SOCKET, SO_TYPE, &type, &tlen) == 0) 7290Sstevel@tonic-gate show_socktype((uint_t)type); 7300Sstevel@tonic-gate 7310Sstevel@tonic-gate show_sockopts(Pr, fd); 732*12643SAnders.Persson@Sun.COM show_sockfilters(Pr, fd); 7330Sstevel@tonic-gate 7340Sstevel@tonic-gate len = sizeof (buf); 7350Sstevel@tonic-gate if (pr_getsockname(Pr, fd, sa, &len) == 0) 7360Sstevel@tonic-gate show_sockaddr("sockname", sa, len); 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate len = sizeof (buf); 7390Sstevel@tonic-gate if (pr_getpeername(Pr, fd, sa, &len) == 0) 7400Sstevel@tonic-gate show_sockaddr("peername", sa, len); 7410Sstevel@tonic-gate } 7426583Smeem 7436583Smeem /* the file is a TLI endpoint */ 7446583Smeem static void 7456583Smeem dotli(struct ps_prochandle *Pr, int fd) 7466583Smeem { 7476583Smeem struct strcmd strcmd; 7486583Smeem 7496583Smeem strcmd.sc_len = STRCMDBUFSIZE; 7506583Smeem strcmd.sc_timeout = 5; 7516583Smeem 7526583Smeem strcmd.sc_cmd = TI_GETMYNAME; 7536583Smeem if (pr_ioctl(Pr, fd, _I_CMD, &strcmd, sizeof (strcmd)) == 0) 7546583Smeem show_sockaddr("sockname", (void *)&strcmd.sc_buf, 0); 7556583Smeem 7566583Smeem strcmd.sc_cmd = TI_GETPEERNAME; 7576583Smeem if (pr_ioctl(Pr, fd, _I_CMD, &strcmd, sizeof (strcmd)) == 0) 7586583Smeem show_sockaddr("peername", (void *)&strcmd.sc_buf, 0); 7596583Smeem } 760