1 /* Copyright (C) 1994 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
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
21 #include <sys/socket.h>
24 #include <hurd/socket.h>
27 /* Read N bytes into BUF through socket FD from peer
28 at address ADDR (which is ADDR_LEN bytes long).
29 Returns the number read or -1 for errors. */
31 DEFUN(recvfrom
, (fd
, buf
, n
, flags
, addr
, addr_len
),
32 int fd AND PTR buf AND
size_t n AND
int flags AND
33 struct sockaddr
*addr AND
size_t *addr_len
)
38 mach_msg_type_number_t nread
= n
;
40 mach_msg_type_number_t nports
;
42 mach_msg_type_number_t clen
= 0;
44 if (err
= HURD_DPORT_USE (fd
, __socket_recv (port
, &addrport
,
50 return __hurd_dfail (fd
, err
);
52 /* Get address data for the returned address port. */
54 char *buf
= (char *) addr
;
55 mach_msg_type_number_t buflen
= *addr_len
;
58 err
= __socket_whatis_address (addrport
, &type
, &buf
, &buflen
);
59 if (err
== EOPNOTSUPP
)
60 /* If the protocol server can't tell us the address, just return a
67 __mach_port_deallocate (__mach_task_self (), addrport
);
69 return __hurd_dfail (fd
, err
);
71 if (buf
!= (char *) addr
)
73 if (*addr_len
< buflen
)
75 memcpy (addr
, buf
, *addr_len
);
76 __vm_deallocate (__mach_task_self (), (vm_address_t
) buf
, buflen
);
80 addr
->sa_family
= type
;
83 /* Toss control data; we don't care. */
84 __vm_deallocate (__mach_task_self (), (vm_address_t
) cdata
, clen
);
88 memcpy (buf
, bufp
, nread
);
89 __vm_deallocate (__mach_task_self (), (vm_address_t
) bufp
, nread
);