GNUnet  0.20.0
gnunet-transport-wlan-receiver.c File Reference

program to send via WLAN as much as possible (to test physical/theoretical throughput) More...

#include "platform.h"
#include "gnunet_protocols.h"
#include "plugin_transport_wlan.h"
Include dependency graph for gnunet-transport-wlan-receiver.c:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

program to send via WLAN as much as possible (to test physical/theoretical throughput)

Author
David Brodski

Definition in file gnunet-transport-wlan-receiver.c.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 31 of file gnunet-transport-wlan-receiver.c.

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 ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.

References pid, ret, and start.