]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/mach/hurd/connect.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / mach / hurd / connect.c
CommitLineData
d614a753 1/* Copyright (C) 1992-2020 Free Software Foundation, Inc.
ebbad4cc 2 This file is part of the GNU C Library.
28f540f4 3
ebbad4cc 4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
28f540f4 8
ebbad4cc
UD
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
41bdb6e2 12 Lesser General Public License for more details.
28f540f4 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
28f540f4 17
28f540f4
RM
18#include <errno.h>
19#include <hurd.h>
20#include <hurd/fd.h>
21#include <sys/socket.h>
22#include <hurd/socket.h>
23#include <sys/un.h>
24#include <hurd/ifsock.h>
a5eb23de 25#include "hurd/hurdsocket.h"
28f540f4
RM
26
27/* Open a connection on socket FD to peer at ADDR (which LEN bytes long).
28 For connectionless socket types, just set the default address to send to
29 and the only address from which to accept transmissions.
30 Return 0 on success, -1 for errors. */
31int
7ce93726 32__connect (int fd, __CONST_SOCKADDR_ARG addrarg, socklen_t len)
28f540f4
RM
33{
34 error_t err;
35 addr_port_t aport;
ae1025be 36 const struct sockaddr_un *addr = addrarg.__sockaddr_un__;
be7e3b7e
RM
37
38 if (addr->sun_family == AF_LOCAL)
28f540f4 39 {
a5eb23de 40 char *name = _hurd_sun_path_dupa (addr, len);
28f540f4
RM
41 /* For the local domain, we must look up the name as a file and talk
42 to it with the ifsock protocol. */
a5eb23de 43 file_t file = __file_name_lookup (name, 0, 0);
28f540f4
RM
44 if (file == MACH_PORT_NULL)
45 return -1;
46 err = __ifsock_getsockaddr (file, &aport);
47 __mach_port_deallocate (__mach_task_self (), file);
48 if (err == MIG_BAD_ID || err == EOPNOTSUPP)
49 /* The file did not grok the ifsock protocol. */
50 err = ENOTSOCK;
51 if (err)
52 return __hurd_fail (err);
53 }
54 else
55 err = EIEIO;
be7e3b7e 56
28f540f4
RM
57 err = HURD_DPORT_USE (fd,
58 ({
59 if (err)
60 err = __socket_create_address (port,
be7e3b7e 61 addr->sun_family,
28f540f4 62 (char *) addr, len,
853f0eea 63 &aport);
28f540f4
RM
64 if (! err)
65 {
66 err = __socket_connect (port, aport);
67 __mach_port_deallocate (__mach_task_self (),
68 aport);
69 }
70 err;
71 }));
72
73 return err ? __hurd_dfail (fd, err) : 0;
74}
ebbad4cc 75
03277f8f 76libc_hidden_def (__connect)
07a4742f 77weak_alias (__connect, connect)