diff options
author | ng0 <ng0@n0.is> | 2019-09-06 23:01:06 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-06 23:01:06 +0000 |
commit | d0051cb6683c712cce3473d6b667208e4f61b75a (patch) | |
tree | 99f642c0e8f8c888a2bb3daa5280325dd8707d6d /src/transport/gnunet-transport-wlan-sender.c | |
parent | 6e599264ad13e8fc105493d74d7c11d46f8739ed (diff) | |
download | gnunet-d0051cb6683c712cce3473d6b667208e4f61b75a.tar.gz gnunet-d0051cb6683c712cce3473d6b667208e4f61b75a.zip |
plibc, commit 2
Diffstat (limited to 'src/transport/gnunet-transport-wlan-sender.c')
-rw-r--r-- | src/transport/gnunet-transport-wlan-sender.c | 127 |
1 files changed, 69 insertions, 58 deletions
diff --git a/src/transport/gnunet-transport-wlan-sender.c b/src/transport/gnunet-transport-wlan-sender.c index 36d26f8dc..36273f765 100644 --- a/src/transport/gnunet-transport-wlan-sender.c +++ b/src/transport/gnunet-transport-wlan-sender.c | |||
@@ -35,16 +35,16 @@ | |||
35 | #define WLAN_LLC_DSAP_FIELD 0x1f | 35 | #define WLAN_LLC_DSAP_FIELD 0x1f |
36 | #define WLAN_LLC_SSAP_FIELD 0x1f | 36 | #define WLAN_LLC_SSAP_FIELD 0x1f |
37 | 37 | ||
38 | #define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ | 38 | #define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ |
39 | 39 | ||
40 | #define IEEE80211_FC0_VERSION_MASK 0x03 | 40 | #define IEEE80211_FC0_VERSION_MASK 0x03 |
41 | #define IEEE80211_FC0_VERSION_SHIFT 0 | 41 | #define IEEE80211_FC0_VERSION_SHIFT 0 |
42 | #define IEEE80211_FC0_VERSION_0 0x00 | 42 | #define IEEE80211_FC0_VERSION_0 0x00 |
43 | #define IEEE80211_FC0_TYPE_MASK 0x0c | 43 | #define IEEE80211_FC0_TYPE_MASK 0x0c |
44 | #define IEEE80211_FC0_TYPE_SHIFT 2 | 44 | #define IEEE80211_FC0_TYPE_SHIFT 2 |
45 | #define IEEE80211_FC0_TYPE_MGT 0x00 | 45 | #define IEEE80211_FC0_TYPE_MGT 0x00 |
46 | #define IEEE80211_FC0_TYPE_CTL 0x04 | 46 | #define IEEE80211_FC0_TYPE_CTL 0x04 |
47 | #define IEEE80211_FC0_TYPE_DATA 0x08 | 47 | #define IEEE80211_FC0_TYPE_DATA 0x08 |
48 | 48 | ||
49 | 49 | ||
50 | /** | 50 | /** |
@@ -55,7 +55,7 @@ | |||
55 | */ | 55 | */ |
56 | static int | 56 | static int |
57 | getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, | 57 | getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, |
58 | uint16_t size) | 58 | uint16_t size) |
59 | { | 59 | { |
60 | header->header.size = htons (size); | 60 | header->header.size = htons (size); |
61 | header->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); | 61 | header->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); |
@@ -75,8 +75,9 @@ getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, | |||
75 | */ | 75 | */ |
76 | static int | 76 | static int |
77 | getWlanHeader (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header, | 77 | getWlanHeader (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header, |
78 | const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, | 78 | const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, |
79 | const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac, unsigned int size) | 79 | const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac, |
80 | unsigned int size) | ||
80 | { | 81 | { |
81 | const int rate = 11000000; | 82 | const int rate = 11000000; |
82 | 83 | ||
@@ -109,21 +110,27 @@ main (int argc, char *argv[]) | |||
109 | int i; | 110 | int i; |
110 | ssize_t ret; | 111 | ssize_t ret; |
111 | pid_t pid; | 112 | pid_t pid; |
112 | int commpipe[2]; /* This holds the fd for the input & output of the pipe */ | 113 | int commpipe[2]; /* This holds the fd for the input & output of the pipe */ |
113 | int macpipe[2]; /* This holds the fd for the input & output of the pipe */ | 114 | int macpipe[2]; /* This holds the fd for the input & output of the pipe */ |
114 | 115 | ||
115 | if (4 != argc) | 116 | if (4 != argc) |
116 | { | 117 | { |
117 | fprintf (stderr, | 118 | fprintf ( |
118 | "This program must be started with the interface and the targets and source mac as argument.\n"); | 119 | stderr, |
120 | "This program must be started with the interface and the targets and source mac as argument.\n"); | ||
119 | fprintf (stderr, | 121 | fprintf (stderr, |
120 | "Usage: interface-name mac-DST mac-SRC\n" | 122 | "Usage: interface-name mac-DST mac-SRC\n" |
121 | "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); | 123 | "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); |
122 | return 1; | 124 | return 1; |
123 | } | 125 | } |
124 | if (6 != | 126 | if (6 != SSCANF (argv[2], |
125 | SSCANF (argv[2], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], | 127 | "%x-%x-%x-%x-%x-%x", |
126 | &temp[3], &temp[4], &temp[5])) | 128 | &temp[0], |
129 | &temp[1], | ||
130 | &temp[2], | ||
131 | &temp[3], | ||
132 | &temp[4], | ||
133 | &temp[5])) | ||
127 | { | 134 | { |
128 | fprintf (stderr, | 135 | fprintf (stderr, |
129 | "Usage: interface-name mac-DST mac-SRC\n" | 136 | "Usage: interface-name mac-DST mac-SRC\n" |
@@ -132,9 +139,14 @@ main (int argc, char *argv[]) | |||
132 | } | 139 | } |
133 | for (i = 0; i < 6; i++) | 140 | for (i = 0; i < 6; i++) |
134 | outmac.mac[i] = temp[i]; | 141 | outmac.mac[i] = temp[i]; |
135 | if (6 != | 142 | if (6 != SSCANF (argv[3], |
136 | SSCANF (argv[3], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], | 143 | "%x-%x-%x-%x-%x-%x", |
137 | &temp[3], &temp[4], &temp[5])) | 144 | &temp[0], |
145 | &temp[1], | ||
146 | &temp[2], | ||
147 | &temp[3], | ||
148 | &temp[4], | ||
149 | &temp[5])) | ||
138 | { | 150 | { |
139 | fprintf (stderr, | 151 | fprintf (stderr, |
140 | "Usage: interface-name mac-DST mac-SRC\n" | 152 | "Usage: interface-name mac-DST mac-SRC\n" |
@@ -148,51 +160,47 @@ main (int argc, char *argv[]) | |||
148 | /* Setup communication pipeline first */ | 160 | /* Setup communication pipeline first */ |
149 | if (pipe (commpipe)) | 161 | if (pipe (commpipe)) |
150 | { | 162 | { |
151 | fprintf (stderr, | 163 | fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno)); |
152 | "Failed to create pipe: %s\n", | ||
153 | STRERROR (errno)); | ||
154 | exit (1); | 164 | exit (1); |
155 | } | 165 | } |
156 | if (pipe (macpipe)) | 166 | if (pipe (macpipe)) |
157 | { | 167 | { |
158 | fprintf (stderr, | 168 | fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno)); |
159 | "Failed to create pipe: %s\n", | ||
160 | STRERROR (errno)); | ||
161 | exit (1); | 169 | exit (1); |
162 | } | 170 | } |
163 | 171 | ||
164 | /* Attempt to fork and check for errors */ | 172 | /* Attempt to fork and check for errors */ |
165 | if ((pid = fork ()) == -1) | 173 | if ((pid = fork ()) == -1) |
166 | { | 174 | { |
167 | fprintf (stderr, "Failed to fork: %s\n", | 175 | fprintf (stderr, "Failed to fork: %s\n", strerror (errno)); |
168 | STRERROR (errno)); | ||
169 | exit (1); | 176 | exit (1); |
170 | } | 177 | } |
171 | memset (msg_buf, 0x42, sizeof (msg_buf)); | 178 | memset (msg_buf, 0x42, sizeof (msg_buf)); |
172 | if (pid) | 179 | if (pid) |
173 | { | 180 | { |
174 | /* A positive (non-negative) PID indicates the parent process */ | 181 | /* A positive (non-negative) PID indicates the parent process */ |
175 | if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */ | 182 | if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */ |
176 | fprintf (stderr, | 183 | fprintf (stderr, "Failed to close fd: %s\n", strerror (errno)); |
177 | "Failed to close fd: %s\n", | 184 | setvbuf (stdout, |
178 | strerror (errno)); | 185 | (char *) NULL, |
179 | setvbuf (stdout, (char *) NULL, _IONBF, 0); /* Set non-buffered output on stdout */ | 186 | _IONBF, |
187 | 0); /* Set non-buffered output on stdout */ | ||
180 | 188 | ||
181 | if (0 != close (macpipe[1])) | 189 | if (0 != close (macpipe[1])) |
182 | fprintf (stderr, | 190 | fprintf (stderr, "Failed to close fd: %s\n", strerror (errno)); |
183 | "Failed to close fd: %s\n", | ||
184 | strerror (errno)); | ||
185 | if (sizeof (hcm) != read (macpipe[0], &hcm, sizeof (hcm))) | 191 | if (sizeof (hcm) != read (macpipe[0], &hcm, sizeof (hcm))) |
186 | fprintf (stderr, | 192 | fprintf (stderr, "Failed to read hcm...\n"); |
187 | "Failed to read hcm...\n"); | ||
188 | fprintf (stderr, | 193 | fprintf (stderr, |
189 | "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", | 194 | "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", |
190 | hcm.mac.mac[0], hcm.mac.mac[1], | 195 | hcm.mac.mac[0], |
191 | hcm.mac.mac[2], hcm.mac.mac[3], hcm.mac.mac[4], hcm.mac.mac[5]); | 196 | hcm.mac.mac[1], |
197 | hcm.mac.mac[2], | ||
198 | hcm.mac.mac[3], | ||
199 | hcm.mac.mac[4], | ||
200 | hcm.mac.mac[5]); | ||
192 | radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) msg_buf; | 201 | radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) msg_buf; |
193 | getRadiotapHeader (radiotap, WLAN_MTU); | 202 | getRadiotapHeader (radiotap, WLAN_MTU); |
194 | getWlanHeader (&radiotap->frame, &outmac, &inmac, | 203 | getWlanHeader (&radiotap->frame, &outmac, &inmac, WLAN_MTU); |
195 | WLAN_MTU); | ||
196 | start = time (NULL); | 204 | start = time (NULL); |
197 | count = 0; | 205 | count = 0; |
198 | while (1) | 206 | while (1) |
@@ -200,18 +208,18 @@ main (int argc, char *argv[]) | |||
200 | ret = write (commpipe[1], msg_buf, WLAN_MTU); | 208 | ret = write (commpipe[1], msg_buf, WLAN_MTU); |
201 | if (0 > ret) | 209 | if (0 > ret) |
202 | { | 210 | { |
203 | fprintf (stderr, "write failed: %s\n", strerror (errno)); | 211 | fprintf (stderr, "write failed: %s\n", strerror (errno)); |
204 | break; | 212 | break; |
205 | } | 213 | } |
206 | count += ret; | 214 | count += ret; |
207 | akt = time (NULL); | 215 | akt = time (NULL); |
208 | if (akt - start > 30) | 216 | if (akt - start > 30) |
209 | { | 217 | { |
210 | bytes_per_s = count / (akt - start); | 218 | bytes_per_s = count / (akt - start); |
211 | bytes_per_s /= 1024; | 219 | bytes_per_s /= 1024; |
212 | printf ("send %f kbytes/s\n", bytes_per_s); | 220 | printf ("send %f kbytes/s\n", bytes_per_s); |
213 | start = akt; | 221 | start = akt; |
214 | count = 0; | 222 | count = 0; |
215 | } | 223 | } |
216 | } | 224 | } |
217 | } | 225 | } |
@@ -220,16 +228,19 @@ main (int argc, char *argv[]) | |||
220 | /* A zero PID indicates that this is the child process */ | 228 | /* A zero PID indicates that this is the child process */ |
221 | (void) close (0); | 229 | (void) close (0); |
222 | (void) close (1); | 230 | (void) close (1); |
223 | if (-1 == dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */ | 231 | if (-1 == |
232 | dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */ | ||
224 | fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); | 233 | fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); |
225 | if (-1 == dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */ | 234 | if (-1 == |
235 | dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */ | ||
226 | fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); | 236 | fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); |
227 | (void) close (commpipe[1]); /* Close unused side of pipe (out side) */ | 237 | (void) close (commpipe[1]); /* Close unused side of pipe (out side) */ |
228 | (void) close (macpipe[0]); /* Close unused side of pipe (in side) */ | 238 | (void) close (macpipe[0]); /* Close unused side of pipe (in side) */ |
229 | /* Replace the child fork with a new process */ | 239 | /* Replace the child fork with a new process */ |
230 | if (execlp | 240 | if (execlp ("gnunet-helper-transport-wlan", |
231 | ("gnunet-helper-transport-wlan", "gnunet-helper-transport-wlan", | 241 | "gnunet-helper-transport-wlan", |
232 | argv[1], NULL) == -1) | 242 | argv[1], |
243 | NULL) == -1) | ||
233 | { | 244 | { |
234 | fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); | 245 | fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); |
235 | _exit (1); | 246 | _exit (1); |