1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 1989 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <sys/types.h> 29 #include <sys/socket.h> 30 #include <netinet/in.h> 31 32 /* multicast setsockopts */ 33 #define SUNOS4X_IP_MULTICAST_IF 2 34 #define SUNOS4X_IP_MULTICAST_TTL 3 35 #define SUNOS4X_IP_MULTICAST_LOOP 4 36 #define SUNOS4X_IP_ADD_MEMBERSHIP 5 37 #define SUNOS4X_IP_DROP_MEMBERSHIP 6 38 #define SUNOS5X_IP_MULTICAST_IF 0x10 39 #define SUNOS5X_IP_MULTICAST_TTL 0x11 40 #define SUNOS5X_IP_MULTICAST_LOOP 0x12 41 #define SUNOS5X_IP_ADD_MEMBERSHIP 0x13 42 #define SUNOS5X_IP_DROP_MEMBERSHIP 0x14 43 44 extern int errno; 45 46 setsockopt(s, level, optname, optval, optlen) 47 register int s; 48 register int level; 49 register int optname; 50 register char *optval; 51 register int optlen; 52 { 53 int a; 54 55 if (level == SOL_SOCKET) 56 switch (optname) { 57 case SO_DONTLINGER: { 58 struct linger ling; 59 ling.l_onoff = 0; 60 if ((a = _setsockopt(s, level, SO_LINGER, &ling, 61 sizeof (struct linger))) == -1) 62 maperror(errno); 63 return (a); 64 } 65 66 case SO_LINGER: 67 if (optlen == sizeof (int)) { 68 struct linger ling; 69 ling.l_onoff = 1; 70 ling.l_linger = (int)*optval; 71 if ((a = _setsockopt(s, level, SO_LINGER, &ling, 72 sizeof (struct linger))) == -1) 73 maperror(errno); 74 return (a); 75 } 76 case SO_DEBUG: 77 case SO_KEEPALIVE: 78 case SO_DONTROUTE: 79 case SO_USELOOPBACK: 80 case SO_REUSEADDR: 81 if (!optval) { 82 int val = 1; 83 if ((a = _setsockopt(s, level, optname, &val, 84 sizeof (int))) == -1) 85 maperror(errno); 86 return (a); 87 } 88 } 89 if (level == IPPROTO_IP) 90 switch (optname) { 91 case SUNOS4X_IP_MULTICAST_IF: 92 optname = SUNOS5X_IP_MULTICAST_IF; 93 break; 94 95 case SUNOS4X_IP_MULTICAST_TTL: 96 optname = SUNOS5X_IP_MULTICAST_TTL; 97 break; 98 99 case SUNOS4X_IP_MULTICAST_LOOP: 100 optname = SUNOS5X_IP_MULTICAST_LOOP; 101 break; 102 103 case SUNOS4X_IP_ADD_MEMBERSHIP: 104 optname = SUNOS5X_IP_ADD_MEMBERSHIP; 105 break; 106 107 case SUNOS4X_IP_DROP_MEMBERSHIP: 108 optname = SUNOS5X_IP_DROP_MEMBERSHIP; 109 break; 110 } 111 112 if ((a = _setsockopt(s, level, optname, optval, optlen)) == -1) 113 maperror(errno); 114 return(a); 115 } 116