Back to index

glibc  2.9
socket.c
Go to the documentation of this file.
00001 /* Copyright (C) 1992, 93, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 #include <sys/socket.h>
00021 #include <hurd.h>
00022 #include <hurd/socket.h>
00023 #include <hurd/fd.h>
00024 #include <fcntl.h>
00025 
00026 /* Create a new socket of type TYPE in domain DOMAIN, using
00027    protocol PROTOCOL.  If PROTOCOL is zero, one is chosen automatically.
00028    Returns a file descriptor for the new socket, or -1 for errors.  */
00029 int
00030 __socket (domain, type, protocol)
00031      int domain;
00032      int type;
00033      int protocol;
00034 {
00035   error_t err;
00036   socket_t sock, server;
00037 
00038   /* Find the socket server for DOMAIN.  */
00039   server = _hurd_socket_server (domain, 0);
00040   if (server == MACH_PORT_NULL)
00041     return -1;
00042 
00043   err = __socket_create (server, type, protocol, &sock);
00044   if (err == MACH_SEND_INVALID_DEST || err == MIG_SERVER_DIED
00045       || err == MIG_BAD_ID || err == EOPNOTSUPP)
00046     {
00047       /* On the first use of the socket server during the operation,
00048         allow for the old server port dying.  */
00049       server = _hurd_socket_server (domain, 1);
00050       if (server == MACH_PORT_NULL)
00051        return -1;
00052       err = __socket_create (server, type, protocol, &sock);
00053     }
00054 
00055   /* These errors all mean that the server node doesn't support the
00056      socket.defs protocol, which we'll take to mean that the protocol
00057      isn't supported.  */
00058   if (err == MACH_SEND_INVALID_DEST || err == MIG_SERVER_DIED
00059       || err == MIG_BAD_ID || err == EOPNOTSUPP)
00060     err = EPFNOSUPPORT;
00061 
00062   if (err)
00063     return __hurd_fail (err);
00064 
00065   return _hurd_intern_fd (sock, O_IGNORE_CTTY, 1);
00066 }
00067 
00068 weak_alias (__socket, socket)