GNUnet  0.11.x
gnunet-transport-wlan-receiver.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2012 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
26 #include "platform.h"
27 #include "gnunet_protocols.h"
28 #include "plugin_transport_wlan.h"
29 
30 int
31 main (int argc, char *argv[])
32 {
33  char msg_buf[65536];
34  unsigned long long count;
35  double bytes_per_s;
36  time_t start;
37  time_t akt;
38  ssize_t ret;
39  pid_t pid;
40  int commpipe[2]; /* This holds the fd for the input & output of the pipe */
41 
42  if (2 != argc)
43  {
44  fprintf (stderr,
45  "This program must be started with the interface name as argument.\n");
46  fprintf (stderr,
47  "Usage: %s interface-name\n"
48  "e.g. %s mon0\n",
49  argv[0],
50  argv[0]);
51  return 1;
52  }
53 
54  /* Setup communication pipeline first */
55  if (pipe (commpipe))
56  {
57  fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
58  exit (1);
59  }
60 
61  /* Attempt to fork and check for errors */
62  if ((pid = fork ()) == -1)
63  {
64  fprintf (stderr, "Failed to fork: %s\n", strerror (errno));
65  exit (1);
66  }
67 
68  if (pid)
69  {
70  /* A positive (non-negative) PID indicates the parent process */
71  if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */
72  fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
73  start = time (NULL);
74  count = 0;
75  while (1)
76  {
77  ret = read (commpipe[0], msg_buf, sizeof(msg_buf));
78  if (0 > ret)
79  {
80  fprintf (stderr, "read failed: %s\n", strerror (errno));
81  break;
82  }
83  count += ret;
84  akt = time (NULL);
85  if (akt - start > 30)
86  {
87  bytes_per_s = count / (akt - start);
88  bytes_per_s /= 1024;
89  printf ("recv %f kb/s\n", bytes_per_s);
90  start = akt;
91  count = 0;
92  }
93  }
94  }
95  else
96  {
97  /* A zero PID indicates that this is the child process */
98  (void) close (1);
99  if (-1 ==
100  dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */
101  fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
102  (void) close (commpipe[0]); /* Close unused side of pipe (in side) */
103  /* Replace the child fork with a new process */
104  if (execlp ("gnunet-helper-transport-wlan",
105  "gnunet-helper-transport-wlan",
106  argv[1],
107  NULL) == -1)
108  {
109  fprintf (stderr, "Could not start gnunet-helper-transport-wlan!");
110  _exit (1);
111  }
112  }
113  return 0;
114 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
header for transport plugin and the helper for wlan
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
int main(int argc, char *argv[])