Fix permissions
[bcusdk.git] / eibd / libserver / inetserver.cpp
blob7cd17e8c5c5476fb3e136b9082425bdb3b4f919c
1 /*
2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2007 Martin Kögler <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/socket.h>
21 #include <netinet/in.h>
22 #include <unistd.h>
23 #include <string.h>
24 #include "inetserver.h"
26 InetServer::InetServer (Layer3 * la3, Trace * tr, int port):
27 Server (la3, tr)
29 struct sockaddr_in addr;
30 int reuse = 1;
31 TRACEPRINTF (tr, 8, this, "OpenInetSocket %d", port);
32 memset (&addr, 0, sizeof (addr));
33 addr.sin_family = AF_INET;
34 addr.sin_port = htons (port);
35 addr.sin_addr.s_addr = htonl (INADDR_ANY);
37 fd = socket (AF_INET, SOCK_STREAM, 0);
38 if (fd == -1)
39 throw Exception (DEV_OPEN_FAIL);
41 setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
43 if (bind (fd, (struct sockaddr *) &addr, sizeof (addr)) == -1)
44 throw Exception (DEV_OPEN_FAIL);
46 if (listen (fd, 10) == -1)
47 throw Exception (DEV_OPEN_FAIL);
49 TRACEPRINTF (tr, 8, this, "InetSocket opened");
50 Start ();