4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1998-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #include <sys/types.h>
31 #include <sys/stream.h>
32 #include <sys/socket.h>
33 #include <sys/socketvar.h>
36 #include <sys/ucred.h>
40 get_sock_peer_name(struct ps_prochandle
*Pr
,
41 int syscall
, int sock
, struct sockaddr
*name
, socklen_t
*namelen
)
43 sysret_t rval
; /* return value from get{sock|peer}name() */
44 argdes_t argd
[4]; /* arg descriptors for get{sock|peer}name() */
48 adp
= &argd
[0]; /* sock argument */
49 adp
->arg_value
= sock
;
50 adp
->arg_object
= NULL
;
51 adp
->arg_type
= AT_BYVAL
;
52 adp
->arg_inout
= AI_INPUT
;
55 adp
++; /* name argument */
57 adp
->arg_object
= name
;
58 adp
->arg_type
= AT_BYREF
;
59 adp
->arg_inout
= AI_OUTPUT
;
60 adp
->arg_size
= *namelen
;
62 adp
++; /* namelen argument */
64 adp
->arg_object
= namelen
;
65 adp
->arg_type
= AT_BYREF
;
66 adp
->arg_inout
= AI_INOUT
;
67 adp
->arg_size
= sizeof (*namelen
);
69 error
= Psyscall(Pr
, &rval
, syscall
, 4, &argd
[0]);
72 errno
= (error
> 0)? error
: ENOSYS
;
78 /* libc system call interface */
79 extern int _so_getsockname(int, struct sockaddr
*, socklen_t
*);
80 extern int _so_getpeername(int, struct sockaddr
*, socklen_t
*);
81 extern int _so_getsockopt(int, int, int, void *, int *);
84 * getsockname() system call -- executed by subject process
87 pr_getsockname(struct ps_prochandle
*Pr
,
88 int sock
, struct sockaddr
*name
, socklen_t
*namelen
)
90 if (Pr
== NULL
) /* no subject process */
91 return (_so_getsockname(sock
, name
, namelen
));
93 return (get_sock_peer_name(Pr
, SYS_getsockname
, sock
, name
, namelen
));
97 * getpeername() system call -- executed by subject process
100 pr_getpeername(struct ps_prochandle
*Pr
,
101 int sock
, struct sockaddr
*name
, socklen_t
*namelen
)
103 if (Pr
== NULL
) /* no subject process */
104 return (_so_getpeername(sock
, name
, namelen
));
106 return (get_sock_peer_name(Pr
, SYS_getpeername
, sock
, name
, namelen
));
110 pr_getsockopt(struct ps_prochandle
*Pr
,
111 int sock
, int level
, int optname
, void *optval
, int *optlen
)
113 sysret_t rval
; /* return value from getsockopt() */
114 argdes_t argd
[5]; /* arg descriptors for getsockopt() */
118 if (Pr
== NULL
) /* no subject process */
119 return (_so_getsockopt(sock
, level
, optname
, optval
, optlen
));
121 adp
= &argd
[0]; /* sock argument */
122 adp
->arg_value
= sock
;
123 adp
->arg_object
= NULL
;
124 adp
->arg_type
= AT_BYVAL
;
125 adp
->arg_inout
= AI_INPUT
;
128 adp
++; /* level argument */
129 adp
->arg_value
= level
;
130 adp
->arg_object
= NULL
;
131 adp
->arg_type
= AT_BYVAL
;
132 adp
->arg_inout
= AI_INPUT
;
135 adp
++; /* optname argument */
136 adp
->arg_value
= optname
;
137 adp
->arg_object
= NULL
;
138 adp
->arg_type
= AT_BYVAL
;
139 adp
->arg_inout
= AI_INPUT
;
142 adp
++; /* optval argument */
144 adp
->arg_object
= optval
;
145 adp
->arg_type
= AT_BYREF
;
146 adp
->arg_inout
= AI_OUTPUT
;
147 adp
->arg_size
= optlen
== NULL
? 0 : *optlen
;
149 adp
++; /* optlen argument */
151 adp
->arg_object
= optlen
;
152 adp
->arg_type
= AT_BYREF
;
153 adp
->arg_inout
= AI_INOUT
;
154 adp
->arg_size
= sizeof (*optlen
);
156 error
= Psyscall(Pr
, &rval
, SYS_getsockopt
, 5, &argd
[0]);
159 errno
= (error
> 0)? error
: ENOSYS
;
166 * getpeerucred() system call -- executed by subject process
169 pr_getpeerucred(struct ps_prochandle
*Pr
, int fd
, ucred_t
**ucp
)
171 sysret_t rval
; /* return value from getpeerucred() */
172 argdes_t argd
[3]; /* arg descriptors for getpeerucred() */
177 if (Pr
== NULL
) /* no subject process */
178 return (getpeerucred(fd
, ucp
));
186 adp
= &argd
[0]; /* code argument */
187 adp
->arg_value
= UCREDSYS_GETPEERUCRED
;
188 adp
->arg_object
= NULL
;
189 adp
->arg_type
= AT_BYVAL
;
190 adp
->arg_inout
= AI_INPUT
;
193 adp
++; /* fd argument */
195 adp
->arg_object
= NULL
;
196 adp
->arg_type
= AT_BYVAL
;
197 adp
->arg_inout
= AI_INPUT
;
200 adp
++; /* ucred argument */
202 adp
->arg_object
= uc
;
203 adp
->arg_type
= AT_BYREF
;
204 adp
->arg_inout
= AI_OUTPUT
;
205 adp
->arg_size
= ucred_size();
207 error
= Psyscall(Pr
, &rval
, SYS_ucredsys
, 3, &argd
[0]);
210 errno
= (error
> 0)? error
: ENOSYS
;