Imported Upstream version 1.0.10
[platform/upstream/lksctp-tools.git] / src / withsctp / sctp_sockopt.c
1 /* Wrap socket() to force the protocol to SCTP for STREAM connections.
2  * 
3  * Thanks to Midgard Security Services for
4  * http://www.securiteam.com/tools/3D5PTR5QAE.html
5  * from whence I cribbed the code to find the old socket().
6  * 
7  * Copyright 2003 La Monte HP Yarroll <piggy@acm.org>
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  *
13  *    1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer. 
15  *    2. Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided with
18  * the distribution.
19  *    3. The name of the author may not be used to endorse or promote
20  * products derived from this software without specific prior written
21  * permission.
22  * 
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
27  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
34  */
35 #include <string.h> /* for strncmp() */
36 #include <stdio.h>
37 #include "sctp_socket.h"
38
39 /* IPPROTO_SCTP SHOULD be defined in
40  * /usr/include/linux/in.h but probably isn't.
41  * It is an enum element, not a #define, so we can't easily check.
42  */
43 #define SHOULD_IPPROTO_SCTP 132
44
45 int 
46 setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
47 {
48     _sctp_load_libs();
49
50     if ((IPPROTO_TCP == level) && (TCP_NODELAY == optname)) {
51         level = SHOULD_IPPROTO_SCTP;
52         optname = SCTP_NODELAY;
53     }
54
55     return (real_setsockopt)(s, level, optname, optval, optlen);
56 }