10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <sys/socket.h>
300Sstevel@tonic-gate #include <netinet/in.h>
31*722Smuffin #include <errno.h>
320Sstevel@tonic-gate
330Sstevel@tonic-gate /* multicast setsockopts */
340Sstevel@tonic-gate #define SUNOS4X_IP_MULTICAST_IF 2
350Sstevel@tonic-gate #define SUNOS4X_IP_MULTICAST_TTL 3
360Sstevel@tonic-gate #define SUNOS4X_IP_MULTICAST_LOOP 4
370Sstevel@tonic-gate #define SUNOS4X_IP_ADD_MEMBERSHIP 5
380Sstevel@tonic-gate #define SUNOS4X_IP_DROP_MEMBERSHIP 6
390Sstevel@tonic-gate #define SUNOS5X_IP_MULTICAST_IF 0x10
400Sstevel@tonic-gate #define SUNOS5X_IP_MULTICAST_TTL 0x11
410Sstevel@tonic-gate #define SUNOS5X_IP_MULTICAST_LOOP 0x12
420Sstevel@tonic-gate #define SUNOS5X_IP_ADD_MEMBERSHIP 0x13
430Sstevel@tonic-gate #define SUNOS5X_IP_DROP_MEMBERSHIP 0x14
440Sstevel@tonic-gate
450Sstevel@tonic-gate
46*722Smuffin int
setsockopt(int s,int level,int optname,char * optval,int optlen)47*722Smuffin setsockopt(int s, int level, int optname, char *optval, int optlen)
480Sstevel@tonic-gate {
490Sstevel@tonic-gate int a;
500Sstevel@tonic-gate
510Sstevel@tonic-gate if (level == SOL_SOCKET)
520Sstevel@tonic-gate switch (optname) {
530Sstevel@tonic-gate case SO_DONTLINGER: {
540Sstevel@tonic-gate struct linger ling;
550Sstevel@tonic-gate ling.l_onoff = 0;
560Sstevel@tonic-gate if ((a = _setsockopt(s, level, SO_LINGER, &ling,
570Sstevel@tonic-gate sizeof (struct linger))) == -1)
580Sstevel@tonic-gate maperror(errno);
590Sstevel@tonic-gate return (a);
600Sstevel@tonic-gate }
610Sstevel@tonic-gate
620Sstevel@tonic-gate case SO_LINGER:
630Sstevel@tonic-gate if (optlen == sizeof (int)) {
640Sstevel@tonic-gate struct linger ling;
650Sstevel@tonic-gate ling.l_onoff = 1;
660Sstevel@tonic-gate ling.l_linger = (int)*optval;
670Sstevel@tonic-gate if ((a = _setsockopt(s, level, SO_LINGER, &ling,
680Sstevel@tonic-gate sizeof (struct linger))) == -1)
690Sstevel@tonic-gate maperror(errno);
700Sstevel@tonic-gate return (a);
710Sstevel@tonic-gate }
720Sstevel@tonic-gate case SO_DEBUG:
730Sstevel@tonic-gate case SO_KEEPALIVE:
740Sstevel@tonic-gate case SO_DONTROUTE:
750Sstevel@tonic-gate case SO_USELOOPBACK:
760Sstevel@tonic-gate case SO_REUSEADDR:
770Sstevel@tonic-gate if (!optval) {
780Sstevel@tonic-gate int val = 1;
790Sstevel@tonic-gate if ((a = _setsockopt(s, level, optname, &val,
800Sstevel@tonic-gate sizeof (int))) == -1)
810Sstevel@tonic-gate maperror(errno);
820Sstevel@tonic-gate return (a);
830Sstevel@tonic-gate }
840Sstevel@tonic-gate }
850Sstevel@tonic-gate if (level == IPPROTO_IP)
860Sstevel@tonic-gate switch (optname) {
870Sstevel@tonic-gate case SUNOS4X_IP_MULTICAST_IF:
880Sstevel@tonic-gate optname = SUNOS5X_IP_MULTICAST_IF;
890Sstevel@tonic-gate break;
900Sstevel@tonic-gate
910Sstevel@tonic-gate case SUNOS4X_IP_MULTICAST_TTL:
920Sstevel@tonic-gate optname = SUNOS5X_IP_MULTICAST_TTL;
930Sstevel@tonic-gate break;
940Sstevel@tonic-gate
950Sstevel@tonic-gate case SUNOS4X_IP_MULTICAST_LOOP:
960Sstevel@tonic-gate optname = SUNOS5X_IP_MULTICAST_LOOP;
970Sstevel@tonic-gate break;
980Sstevel@tonic-gate
990Sstevel@tonic-gate case SUNOS4X_IP_ADD_MEMBERSHIP:
1000Sstevel@tonic-gate optname = SUNOS5X_IP_ADD_MEMBERSHIP;
1010Sstevel@tonic-gate break;
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate case SUNOS4X_IP_DROP_MEMBERSHIP:
1040Sstevel@tonic-gate optname = SUNOS5X_IP_DROP_MEMBERSHIP;
1050Sstevel@tonic-gate break;
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate if ((a = _setsockopt(s, level, optname, optval, optlen)) == -1)
1090Sstevel@tonic-gate maperror(errno);
110*722Smuffin return (a);
1110Sstevel@tonic-gate }
112