com_next() fix.
[paraslash.git] / dccp.c
1 /*
2  * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
3  *
4  *     This program is free software; you can redistribute it and/or modify
5  *     it under the terms of the GNU General Public License as published by
6  *     the Free Software Foundation; either version 2 of the License, or
7  *     (at your option) any later version.
8  *
9  *     This program is distributed in the hope that it will be useful,
10  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *     GNU General Public License for more details.
13  *
14  *     You should have received a copy of the GNU General Public License
15  *     along with this program; if not, write to the Free Software
16  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
17  */
18
19 /*
20  * based on common.c of dccp-cs-0.01.tar.bz2,
21  * (C) 2005 Ian McDonald <imcdnzl@gmail.com>
22  */
23
24 #include "para.h"
25 #include "error.h"
26 #include "dccp.h"
27
28 int dccp_get_socket(void)
29 {
30         int s = socket(AF_INET, SOCK_DCCP, IPPROTO_DCCP);
31
32         if (s < 0)
33                 return -E_DCCP_SOCKET;
34         return s;
35 }
36
37 int dccp_set_socket(int fd)
38 {
39         int pkt_size = 256, ret;
40
41         /* hack to get a service code */
42         ret = setsockopt(fd, SOL_DCCP, DCCP_SOCKOPT_PACKET_SIZE,
43                 (char*)&pkt_size, sizeof(pkt_size));
44         if (ret < 0)
45                 return -E_DCCP_PACKET_SIZE;
46         ret = setsockopt(fd, SOL_DCCP, DCCP_SOCKOPT_SERVICE,
47                 (char*)&pkt_size, sizeof(pkt_size));
48         if (ret < 0)
49                 return -E_DCCP_SERVICE;
50         return 1;
51 }