summaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport-wlan-receiver.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-transport-wlan-receiver.c')
-rw-r--r--src/transport/gnunet-transport-wlan-receiver.c42
1 files changed, 20 insertions, 22 deletions
diff --git a/src/transport/gnunet-transport-wlan-receiver.c b/src/transport/gnunet-transport-wlan-receiver.c
index 04f30a683..9b31377e7 100644
--- a/src/transport/gnunet-transport-wlan-receiver.c
+++ b/src/transport/gnunet-transport-wlan-receiver.c
@@ -37,7 +37,7 @@ main (int argc, char *argv[])
37 time_t akt; 37 time_t akt;
38 ssize_t ret; 38 ssize_t ret;
39 pid_t pid; 39 pid_t pid;
40 int commpipe[2]; /* This holds the fd for the input & output of the pipe */ 40 int commpipe[2]; /* This holds the fd for the input & output of the pipe */
41 41
42 if (2 != argc) 42 if (2 != argc)
43 { 43 {
@@ -46,34 +46,30 @@ main (int argc, char *argv[])
46 fprintf (stderr, 46 fprintf (stderr,
47 "Usage: %s interface-name\n" 47 "Usage: %s interface-name\n"
48 "e.g. %s mon0\n", 48 "e.g. %s mon0\n",
49 argv[0], argv[0]); 49 argv[0],
50 argv[0]);
50 return 1; 51 return 1;
51 } 52 }
52 53
53 /* Setup communication pipeline first */ 54 /* Setup communication pipeline first */
54 if (pipe (commpipe)) 55 if (pipe (commpipe))
55 { 56 {
56 fprintf (stderr, 57 fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno));
57 "Failed to create pipe: %s\n",
58 STRERROR (errno));
59 exit (1); 58 exit (1);
60 } 59 }
61 60
62 /* Attempt to fork and check for errors */ 61 /* Attempt to fork and check for errors */
63 if ((pid = fork ()) == -1) 62 if ((pid = fork ()) == -1)
64 { 63 {
65 fprintf (stderr, "Failed to fork: %s\n", 64 fprintf (stderr, "Failed to fork: %s\n", strerror (errno));
66 STRERROR (errno));
67 exit (1); 65 exit (1);
68 } 66 }
69 67
70 if (pid) 68 if (pid)
71 { 69 {
72 /* A positive (non-negative) PID indicates the parent process */ 70 /* A positive (non-negative) PID indicates the parent process */
73 if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */ 71 if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */
74 fprintf (stderr, 72 fprintf (stderr, "Failed to close fd: %s\n", strerror (errno));
75 "Failed to close fd: %s\n",
76 strerror (errno));
77 start = time (NULL); 73 start = time (NULL);
78 count = 0; 74 count = 0;
79 while (1) 75 while (1)
@@ -81,18 +77,18 @@ main (int argc, char *argv[])
81 ret = read (commpipe[0], msg_buf, sizeof (msg_buf)); 77 ret = read (commpipe[0], msg_buf, sizeof (msg_buf));
82 if (0 > ret) 78 if (0 > ret)
83 { 79 {
84 fprintf (stderr, "read failed: %s\n", strerror (errno)); 80 fprintf (stderr, "read failed: %s\n", strerror (errno));
85 break; 81 break;
86 } 82 }
87 count += ret; 83 count += ret;
88 akt = time (NULL); 84 akt = time (NULL);
89 if (akt - start > 30) 85 if (akt - start > 30)
90 { 86 {
91 bytes_per_s = count / (akt - start); 87 bytes_per_s = count / (akt - start);
92 bytes_per_s /= 1024; 88 bytes_per_s /= 1024;
93 printf ("recv %f kb/s\n", bytes_per_s); 89 printf ("recv %f kb/s\n", bytes_per_s);
94 start = akt; 90 start = akt;
95 count = 0; 91 count = 0;
96 } 92 }
97 } 93 }
98 } 94 }
@@ -100,13 +96,15 @@ main (int argc, char *argv[])
100 { 96 {
101 /* A zero PID indicates that this is the child process */ 97 /* A zero PID indicates that this is the child process */
102 (void) close (1); 98 (void) close (1);
103 if (-1 == dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */ 99 if (-1 ==
100 dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */
104 fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); 101 fprintf (stderr, "dup2 failed: %s\n", strerror (errno));
105 (void) close (commpipe[0]); /* Close unused side of pipe (in side) */ 102 (void) close (commpipe[0]); /* Close unused side of pipe (in side) */
106 /* Replace the child fork with a new process */ 103 /* Replace the child fork with a new process */
107 if (execlp 104 if (execlp ("gnunet-helper-transport-wlan",
108 ("gnunet-helper-transport-wlan", "gnunet-helper-transport-wlan", 105 "gnunet-helper-transport-wlan",
109 argv[1], NULL) == -1) 106 argv[1],
107 NULL) == -1)
110 { 108 {
111 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); 109 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!");
112 _exit (1); 110 _exit (1);