]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/sendmsg.c
1 /* Copyright (C) 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <sys/socket.h>
23 #include <asm/posix_types.h>
25 /* The kernel expects this structure in SCM_CREDS messages.
26 * Note: sizeof(struct __kernel_ucred) <= sizeof(struct cmsgcred) must hold.
35 extern int __sendmsg (int, const struct msghdr
*, int);
37 /* Send a message described by MESSAGE on socket FD.
38 Returns the number of bytes sent, or -1 for errors. */
40 sendmsg (fd
, message
, flags
)
42 const struct msghdr
*message
;
47 struct __kernel_ucred
*u
;
50 /* Preprocess the message control block for SCM_CREDS. */
51 cm
= CMSG_FIRSTHDR (message
);
54 if (cm
->cmsg_type
== SCM_CREDS
)
56 if (cm
->cmsg_len
< CMSG_SPACE (sizeof (struct cmsgcred
)))
62 u
= (struct __kernel_ucred
*) CMSG_DATA (cm
);
63 cc
= (struct cmsgcred
*) CMSG_DATA (cm
);
64 /* Linux expects the calling process to pass in
65 its credentials, and sanity checks them.
66 You can send real, effective, or set- uid and gid.
67 If the user hasn't filled in the buffer, we default to
70 if (cc
->cmcred_pid
!= pid
)
78 struct __kernel_ucred v
;
79 v
.pid
= cc
->cmcred_pid
;
80 v
.uid
= cc
->cmcred_uid
;
81 v
.gid
= cc
->cmcred_gid
;
87 cm
= CMSG_NXTHDR ((struct msghdr
*) message
, cm
);
90 return __sendmsg (fd
, message
, flags
);