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 adp
++; /* version argument */
70 adp
->arg_value
= SOV_DEFAULT
;
71 adp
->arg_object
= NULL
;
72 adp
->arg_type
= AT_BYVAL
;
73 adp
->arg_inout
= AI_INPUT
;
76 error
= Psyscall(Pr
, &rval
, syscall
, 4, &argd
[0]);
79 errno
= (error
> 0)? error
: ENOSYS
;
85 /* libc system call interface */
86 extern int _so_getsockname(int, struct sockaddr
*, socklen_t
*, int);
87 extern int _so_getpeername(int, struct sockaddr
*, socklen_t
*, int);
88 extern int _so_getsockopt(int, int, int, void *, int *);
91 * getsockname() system call -- executed by subject process
94 pr_getsockname(struct ps_prochandle
*Pr
,
95 int sock
, struct sockaddr
*name
, socklen_t
*namelen
)
97 if (Pr
== NULL
) /* no subject process */
98 return (_so_getsockname(sock
, name
, namelen
, SOV_DEFAULT
));
100 return (get_sock_peer_name(Pr
, SYS_getsockname
, sock
, name
, namelen
));
104 * getpeername() system call -- executed by subject process
107 pr_getpeername(struct ps_prochandle
*Pr
,
108 int sock
, struct sockaddr
*name
, socklen_t
*namelen
)
110 if (Pr
== NULL
) /* no subject process */
111 return (_so_getpeername(sock
, name
, namelen
, SOV_DEFAULT
));
113 return (get_sock_peer_name(Pr
, SYS_getpeername
, sock
, name
, namelen
));
117 pr_getsockopt(struct ps_prochandle
*Pr
,
118 int sock
, int level
, int optname
, void *optval
, int *optlen
)
120 sysret_t rval
; /* return value from getsockopt() */
121 argdes_t argd
[5]; /* arg descriptors for getsockopt() */
125 if (Pr
== NULL
) /* no subject process */
126 return (_so_getsockopt(sock
, level
, optname
, optval
, optlen
));
128 adp
= &argd
[0]; /* sock argument */
129 adp
->arg_value
= sock
;
130 adp
->arg_object
= NULL
;
131 adp
->arg_type
= AT_BYVAL
;
132 adp
->arg_inout
= AI_INPUT
;
135 adp
++; /* level argument */
136 adp
->arg_value
= level
;
137 adp
->arg_object
= NULL
;
138 adp
->arg_type
= AT_BYVAL
;
139 adp
->arg_inout
= AI_INPUT
;
142 adp
++; /* optname argument */
143 adp
->arg_value
= optname
;
144 adp
->arg_object
= NULL
;
145 adp
->arg_type
= AT_BYVAL
;
146 adp
->arg_inout
= AI_INPUT
;
149 adp
++; /* optval argument */
151 adp
->arg_object
= optval
;
152 adp
->arg_type
= AT_BYREF
;
153 adp
->arg_inout
= AI_OUTPUT
;
154 adp
->arg_size
= optlen
== NULL
? 0 : *optlen
;
156 adp
++; /* optlen argument */
158 adp
->arg_object
= optlen
;
159 adp
->arg_type
= AT_BYREF
;
160 adp
->arg_inout
= AI_INOUT
;
161 adp
->arg_size
= sizeof (*optlen
);
163 error
= Psyscall(Pr
, &rval
, SYS_getsockopt
, 5, &argd
[0]);
166 errno
= (error
> 0)? error
: ENOSYS
;
173 * getpeerucred() system call -- executed by subject process
176 pr_getpeerucred(struct ps_prochandle
*Pr
, int fd
, ucred_t
**ucp
)
178 sysret_t rval
; /* return value from getpeerucred() */
179 argdes_t argd
[3]; /* arg descriptors for getpeerucred() */
184 if (Pr
== NULL
) /* no subject process */
185 return (getpeerucred(fd
, ucp
));
193 adp
= &argd
[0]; /* code argument */
194 adp
->arg_value
= UCREDSYS_GETPEERUCRED
;
195 adp
->arg_object
= NULL
;
196 adp
->arg_type
= AT_BYVAL
;
197 adp
->arg_inout
= AI_INPUT
;
200 adp
++; /* fd argument */
202 adp
->arg_object
= NULL
;
203 adp
->arg_type
= AT_BYVAL
;
204 adp
->arg_inout
= AI_INPUT
;
207 adp
++; /* ucred argument */
209 adp
->arg_object
= uc
;
210 adp
->arg_type
= AT_BYREF
;
211 adp
->arg_inout
= AI_OUTPUT
;
212 adp
->arg_size
= ucred_size();
214 error
= Psyscall(Pr
, &rval
, SYS_ucredsys
, 3, &argd
[0]);
217 errno
= (error
> 0)? error
: ENOSYS
;