source: roaraudio/roard/network.c @ 668:71ac426690da

Last change on this file since 668:71ac426690da was 668:71ac426690da, checked in by phi, 16 years ago

added license statements

File size: 2.1 KB
Line 
1//network.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27int net_check_listen  (void) {
28 int r;
29 fd_set sl;
30 struct timeval tv;
31
32 FD_ZERO(&sl);
33 FD_SET(g_listen_socket, &sl);
34
35 tv.tv_sec  = 0;
36 tv.tv_usec = 1;
37
38 if ((r = select(g_listen_socket + 1, &sl, NULL, NULL, &tv)) > 0) {
39  ROAR_DBG("net_check_listen(void): We have a connection!");
40  return net_get_new_client();
41 }
42
43 return r;
44}
45
46int net_get_new_client (void) {
47 int fh;
48 int client;
49#ifdef SO_PEERCRED
50 struct roar_client * c;
51 struct ucred cred;
52 socklen_t cred_len = sizeof(cred);
53#endif
54
55 fh = accept(g_listen_socket, NULL, NULL);
56
57 ROAR_DBG("net_get_new_client(void): fh = %i", fh);
58
59 client = clients_new();
60
61 if ( clients_set_fh(client, fh) == -1 ) {
62  ROAR_ERR("net_get_new_client(void): Can not set client's fh");
63
64  clients_delete(client);
65  close(fh);
66
67  ROAR_DBG("net_get_new_client(void) = -1");
68  return -1;
69 }
70
71#ifdef SO_PEERCRED
72 if ( clients_get(client, &c) != -1 ) {
73  if (getsockopt(fh, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len) != -1) {
74   if ( cred.pid != 0 ) {
75    c->pid = cred.pid;
76    c->uid = cred.uid;
77    c->gid = cred.gid;
78   }
79  } else {
80   ROAR_DBG("req_on_identify(): Can't get creds via SO_PEERCRED: %s", strerror(errno));
81  }
82 }
83#endif
84
85// close(fh);
86
87 return 0;
88}
89
90//ll
Note: See TracBrowser for help on using the repository browser.