home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume26 / mcast / part01 / libmcast / mc_getpeername.c < prev    next >
C/C++ Source or Header  |  1993-04-06  |  3KB  |  86 lines

  1. /*
  2.  * $Header: /u0/casey/src/mcast/libmcast/RCS/mc_getpeername.c,v 1.3 93/01/16 19:43:25 casey Exp $
  3.  */
  4.  
  5. /*
  6.  * Copyright (c) 1992 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in the
  16.  *    documentation and/or other materials provided with the distribution.
  17.  * 3. All advertising materials mentioning features or use of this software
  18.  *    must display the following acknowledgement:
  19.  *    This product includes software developed by the University of
  20.  *    California, Lawrence Livermore National Laboratory and its
  21.  *    contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  */
  38.  
  39. #ifndef lint
  40. static char rcsid[] = "$Header: /u0/casey/src/mcast/libmcast/RCS/mc_getpeername.c,v 1.3 93/01/16 19:43:25 casey Exp $";
  41. static char copyright[] =
  42.     "Copyright (c) 1992 The Regents of the University of California.\n"
  43.     "All rights reserved.\n";
  44. static char classification[] =
  45.     "Unclassified\n";
  46. #endif
  47.  
  48.  
  49. /*
  50.  * MCAST SYSLIB PUBLIC: mc_getpeername: getpeername(2) system call emulation
  51.  * routine.
  52.  */
  53.  
  54.  
  55. #include "mc_lib.h"
  56.  
  57.  
  58. int
  59. mc_getpeername(int s, struct sockaddr *name, int *namelen)
  60.     /*
  61.      * Get remote name of a connected multicast socket.
  62.      */
  63. {
  64.     mc_state *sp = &_mc_state[s];
  65.     struct sockaddr_mcast *np = (struct sockaddr_mcast *)name;
  66.     int len = min(*namelen, sizeof(struct sockaddr_mcast));
  67.     struct sockaddr_mcast tmp;
  68.  
  69.     if (s < 0 || s >= MC_MAX_CONNECTIONS
  70.         || !(sp->state & MC_VALID)) {
  71.         /* return(recvfrom(s, buf, len, flags)); */
  72.         errno = EBADF;
  73.         return(-1);
  74.     }
  75.     if (sp->state & MC_CORRUPTED) {
  76.         errno = EIO;
  77.         return(-1);
  78.     }
  79.     tmp.family = sp->family;
  80.     tmp.group = sp->group;
  81.     tmp.member = sp->remote;
  82.     (void)memcpy(np, &tmp, len);
  83.     *namelen = len;
  84.     return(0);
  85. }
  86.