GNUnet  0.10.x
Functions
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.

References pid, ret, start, and STRERROR.

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], argv[0]);
50  return 1;
51  }
52 
53  /* Setup communication pipeline first */
54  if (pipe (commpipe))
55  {
56  fprintf (stderr,
57  "Failed to create pipe: %s\n",
58  STRERROR (errno));
59  exit (1);
60  }
61 
62  /* Attempt to fork and check for errors */
63  if ((pid = fork ()) == -1)
64  {
65  fprintf (stderr, "Failed to fork: %s\n",
66  STRERROR (errno));
67  exit (1);
68  }
69 
70  if (pid)
71  {
72  /* A positive (non-negative) PID indicates the parent process */
73  if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */
74  fprintf (stderr,
75  "Failed to close fd: %s\n",
76  strerror (errno));
77  start = time (NULL);
78  count = 0;
79  while (1)
80  {
81  ret = read (commpipe[0], msg_buf, sizeof (msg_buf));
82  if (0 > ret)
83  {
84  fprintf (stderr, "read failed: %s\n", strerror (errno));
85  break;
86  }
87  count += ret;
88  akt = time (NULL);
89  if (akt - start > 30)
90  {
91  bytes_per_s = count / (akt - start);
92  bytes_per_s /= 1024;
93  printf ("recv %f kb/s\n", bytes_per_s);
94  start = akt;
95  count = 0;
96  }
97  }
98  }
99  else
100  {
101  /* A zero PID indicates that this is the child process */
102  (void) close (1);
103  if (-1 == dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */
104  fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
105  (void) close (commpipe[0]); /* Close unused side of pipe (in side) */
106  /* Replace the child fork with a new process */
107  if (execlp
108  ("gnunet-helper-transport-wlan", "gnunet-helper-transport-wlan",
109  argv[1], NULL) == -1)
110  {
111  fprintf (stderr, "Could not start gnunet-helper-transport-wlan!");
112  _exit (1);
113  }
114  }
115  return 0;
116 }
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
#define STRERROR(i)
Definition: plibc.h:676
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.