Add missing includes for FreeBSD compile
[bcusdk.git] / eibd / libserver / inetserver.cpp
blob8de6bbeee344996ebefc4483e73adbea9641d61f
1 /*
2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2007 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netinet/in.h>
23 #include <netinet/tcp.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include "inetserver.h"
28 InetServer::InetServer (Layer3 * la3, Trace * tr, int port):
29 Server (la3, tr)
31 struct sockaddr_in addr;
32 int reuse = 1;
33 TRACEPRINTF (tr, 8, this, "OpenInetSocket %d", port);
34 memset (&addr, 0, sizeof (addr));
35 addr.sin_family = AF_INET;
36 addr.sin_port = htons (port);
37 addr.sin_addr.s_addr = htonl (INADDR_ANY);
39 fd = socket (AF_INET, SOCK_STREAM, 0);
40 if (fd == -1)
41 throw Exception (DEV_OPEN_FAIL);
43 setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
45 if (bind (fd, (struct sockaddr *) &addr, sizeof (addr)) == -1)
46 throw Exception (DEV_OPEN_FAIL);
48 if (listen (fd, 10) == -1)
49 throw Exception (DEV_OPEN_FAIL);
51 TRACEPRINTF (tr, 8, this, "InetSocket opened");
52 Start ();
55 void
56 InetServer::setupConnection (int cfd)
58 int val = 1;
59 setsockopt (cfd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));