@@ -70,40 +70,35 @@ static struct bpf_program filter = {
70
70
static struct sockaddr_ll addr ;
71
71
#endif /* AF_LINK */
72
72
73
- static inline void set_eapol_header (unsigned char type , \
74
- unsigned short length )
75
- {
73
+ static inline void set_eapol_header (unsigned char type , unsigned short length ) {
76
74
send_pkt -> eapol_header .version = EAPOL_VERSION ;
77
75
send_pkt -> eapol_header .type = type ;
78
76
send_pkt -> eapol_header .length = length ;
79
77
}
80
78
81
- static inline void set_eap_header (unsigned char code , \
82
- unsigned char id , unsigned short length )
83
- {
79
+ static inline void set_eap_header (unsigned char code , unsigned char id ,
80
+ unsigned short length ) {
84
81
send_pkt -> eap_header .code = code ;
85
82
send_pkt -> eap_header .id = id ;
86
83
send_pkt -> eap_header .length = length ;
87
84
}
88
85
89
- static int sendout (int length )
90
- {
86
+ static int sendout (int length ) {
91
87
#ifdef AF_LINK
92
88
if (write (sockfd , send_buf , length ) == -1 )
93
89
return SEND_ERR ;
94
90
else
95
91
return SUCCESS ;
96
92
#else
97
- if (sendto (sockfd , send_buf , length , 0 , (struct sockaddr * )& addr , \
93
+ if (sendto (sockfd , send_buf , length , 0 , (struct sockaddr * ) & addr ,
98
94
sizeof (addr )) == -1 )
99
95
return SEND_ERR ;
100
96
else
101
97
return SUCCESS ;
102
98
#endif /* AF_LINK */
103
99
}
104
100
105
- static int recvin (int length )
106
- {
101
+ static int recvin (int length ) {
107
102
#ifdef AF_LINK
108
103
if (read (sockfd , recv_buf , length ) == -1 )
109
104
return RECV_ERR ;
@@ -114,19 +109,19 @@ static int recvin(int length)
114
109
socklen_t len ;
115
110
len = sizeof (addr );
116
111
117
- if (recvfrom (sockfd , recv_buf , length , 0 , \
118
- ( struct sockaddr * ) & addr , & len ) == -1 )
112
+ if (recvfrom (sockfd , recv_buf , length , 0 , ( struct sockaddr * ) & addr , & len )
113
+ == -1 )
119
114
return RECV_ERR ;
120
115
else
121
116
return SUCCESS ;
122
117
#endif /* AF_LINK */
123
118
}
124
119
125
- static int send_id (unsigned char packet_id )
126
- {
120
+ static int send_id (unsigned char packet_id ) {
127
121
int username_length = strlen (username );
128
- unsigned short len = htons ( sizeof (struct eap ) + TYPE_LEN + \
129
- sizeof (VERSION_INFO ) + username_length );
122
+ unsigned short len = htons (
123
+ sizeof (struct eap ) + TYPE_LEN + sizeof (VERSION_INFO )
124
+ + username_length );
130
125
131
126
set_eapol_header (EAPOL_EAPPACKET , len );
132
127
set_eap_header (EAP_RESPONSE , packet_id , len );
@@ -135,16 +130,16 @@ static int send_id(unsigned char packet_id)
135
130
memcpy (eap_id_info (send_pkt ), VERSION_INFO , sizeof (VERSION_INFO ));
136
131
memcpy (eap_id_username (send_pkt ), username , username_length );
137
132
138
- return sendout (sizeof (struct packet ) + TYPE_LEN + \
139
- sizeof (VERSION_INFO ) + username_length );
133
+ return sendout (
134
+ sizeof (struct packet ) + TYPE_LEN + sizeof (VERSION_INFO )
135
+ + username_length );
140
136
}
141
137
142
- static int send_md5 (unsigned char packet_id , unsigned char * md5data )
143
- {
138
+ static int send_md5 (unsigned char packet_id , unsigned char * md5data ) {
144
139
int username_length = strlen (username );
145
140
unsigned char md5 [MD5_LEN ];
146
- unsigned short len = htons (sizeof (struct eap ) + TYPE_LEN + \
147
- MD5_LEN_LEN + MD5_LEN + username_length );
141
+ unsigned short len = htons (sizeof (struct eap ) + TYPE_LEN +
142
+ MD5_LEN_LEN + MD5_LEN + username_length );
148
143
149
144
memset (md5 , 0 , MD5_LEN );
150
145
memcpy (md5 , password , MD5_LEN );
@@ -161,31 +156,30 @@ static int send_md5(unsigned char packet_id, unsigned char *md5data)
161
156
memcpy (eap_md5_data (send_pkt ), md5 , MD5_LEN );
162
157
memcpy (eap_md5_username (send_pkt ), username , username_length );
163
158
164
- return sendout (sizeof (struct packet ) + TYPE_LEN + MD5_LEN_LEN + \
165
- MD5_LEN + username_length );
159
+ return sendout (sizeof (struct packet ) + TYPE_LEN + MD5_LEN_LEN +
160
+ MD5_LEN + username_length );
166
161
}
167
162
168
- static int send_h3c (unsigned char packet_id )
169
- {
163
+ static int send_h3c (unsigned char packet_id ) {
170
164
int username_length = strlen (username );
171
165
int password_length = strlen (password );
172
- unsigned short len = htons (sizeof ( struct eap ) + 1 + 1 + \
173
- password_length + username_length );
166
+ unsigned short len = htons (
167
+ sizeof ( struct eap ) + 1 + 1 + password_length + username_length );
174
168
175
169
set_eapol_header (EAPOL_EAPPACKET , len );
176
170
set_eap_header (EAP_RESPONSE , packet_id , len );
177
171
* eap_type (send_pkt ) = EAP_TYPE_H3C ;
178
172
179
- * eap_h3c_length (send_pkt ) = (unsigned char )password_length ;
173
+ * eap_h3c_length (send_pkt ) = (unsigned char ) password_length ;
180
174
memcpy (eap_h3c_password (send_pkt ), password , password_length );
181
175
memcpy (eap_h3c_username (send_pkt ), username , username_length );
182
176
183
- return sendout (sizeof (struct packet ) + TYPE_LEN + H3C_LEN_LEN + \
184
- password_length + username_length );
177
+ return sendout (
178
+ sizeof (struct packet ) + TYPE_LEN + H3C_LEN_LEN + password_length
179
+ + username_length );
185
180
}
186
181
187
- int h3c_init (char * _interface )
188
- {
182
+ int h3c_init (char * _interface ) {
189
183
struct ifreq ifr ;
190
184
191
185
/* Set destination mac address. */
@@ -202,7 +196,7 @@ int h3c_init(char *_interface)
202
196
203
197
do {
204
198
sockfd = open (device , O_RDWR );
205
- } while ((sockfd == -1 ) && (errno == EBUSY ) && (device [8 ]++ != '9' ));
199
+ }while ((sockfd == -1 ) && (errno == EBUSY ) && (device [8 ]++ != '9' ));
206
200
207
201
if (sockfd == -1 )
208
202
return BPF_OPEN_ERR ;
@@ -239,7 +233,7 @@ int h3c_init(char *_interface)
239
233
if ((sockfd = socket (AF_PACKET , SOCK_RAW , htons (ETH_P_PAE ))) == -1 )
240
234
return SOCKET_OPEN_ERR ;
241
235
242
- if (ioctl (sockfd ,SIOCGIFINDEX ,& ifr ) == -1 )
236
+ if (ioctl (sockfd , SIOCGIFINDEX , & ifr ) == -1 )
243
237
return SOCKET_SET_IF_ERR ;
244
238
else
245
239
addr .sll_ifindex = ifr .ifr_ifindex ;
@@ -248,15 +242,13 @@ int h3c_init(char *_interface)
248
242
return SOCKET_GET_HWADDR_ERR ;
249
243
250
244
/* Set source mac address. */
251
- memcpy (send_pkt -> eth_header .ether_shost , \
252
- ifr .ifr_hwaddr .sa_data , ETH_ALEN );
245
+ memcpy (send_pkt -> eth_header .ether_shost , ifr .ifr_hwaddr .sa_data , ETH_ALEN );
253
246
#endif /* AF_LINK */
254
247
255
248
return SUCCESS ;
256
249
}
257
250
258
- int h3c_set_username (char * _username )
259
- {
251
+ int h3c_set_username (char * _username ) {
260
252
int username_length = strlen (_username );
261
253
if (username_length > USR_LEN - 1 )
262
254
return USR_TOO_LONG ;
@@ -265,8 +257,7 @@ int h3c_set_username(char *_username)
265
257
return SUCCESS ;
266
258
}
267
259
268
- int h3c_set_password (char * _password )
269
- {
260
+ int h3c_set_password (char * _password ) {
270
261
int password_length = strlen (_password );
271
262
if (password_length > PWD_LEN - 1 )
272
263
return PWD_TOO_LONG ;
@@ -275,75 +266,61 @@ int h3c_set_password(char *_password)
275
266
return SUCCESS ;
276
267
}
277
268
278
- int h3c_start ()
279
- {
269
+ int h3c_start () {
280
270
set_eapol_header (EAPOL_START , 0 );
281
- return sendout (sizeof (struct ether_header )+ sizeof (struct eapol ));
271
+ return sendout (sizeof (struct ether_header ) + sizeof (struct eapol ));
282
272
}
283
273
284
- int h3c_logoff ()
285
- {
274
+ int h3c_logoff () {
286
275
set_eapol_header (EAPOL_LOGOFF , 0 );
287
- return sendout (sizeof (struct ether_header )+ sizeof (struct eapol ));
276
+ return sendout (sizeof (struct ether_header ) + sizeof (struct eapol ));
288
277
}
289
278
290
- int h3c_response (int (* success_callback )(void ), \
291
- int (* failure_callback )(void ), \
292
- int (* unkown_eapol_callback )(void ), \
293
- int (* unkown_eap_callback )(void ), \
294
- int (* got_response_callback )(void ))
295
- {
279
+ int h3c_response (int (* success_callback )(void ), int (* failure_callback )(void ),
280
+ int (* unkown_eapol_callback )(void ), int (* unkown_eap_callback )(void ),
281
+ int (* got_response_callback )(void )) {
296
282
if (recvin (BUF_LEN ) == RECV_ERR )
297
283
return RECV_ERR ;
298
284
299
- if (recv_pkt -> eapol_header .type != EAPOL_EAPPACKET )
300
- {
285
+ if (recv_pkt -> eapol_header .type != EAPOL_EAPPACKET ) {
301
286
/* Got unknown eapol type. */
302
287
if (unkown_eapol_callback != NULL )
303
288
return unkown_eapol_callback ();
304
289
else
305
290
return EAPOL_UNHANDLED ;
306
291
}
307
- if (recv_pkt -> eap_header .code == EAP_SUCCESS )
308
- {
292
+ if (recv_pkt -> eap_header .code == EAP_SUCCESS ) {
309
293
/* Got success. */
310
294
if (success_callback != NULL )
311
295
return success_callback ();
312
296
else
313
297
return SUCCESS_UNHANDLED ;
314
- }
315
- else if (recv_pkt -> eap_header .code == EAP_FAILURE )
316
- {
298
+ } else if (recv_pkt -> eap_header .code == EAP_FAILURE ) {
317
299
/* Got failure. */
318
300
if (failure_callback != NULL )
319
301
return failure_callback ();
320
302
else
321
303
return FAILURE_UNHANDLED ;
322
- }
323
- else if (recv_pkt -> eap_header .code == EAP_REQUEST )
304
+ } else if (recv_pkt -> eap_header .code == EAP_REQUEST )
324
305
/*
325
306
* Got request.
326
307
* Response according to request type.
327
308
*/
328
309
if (* eap_type (recv_pkt ) == EAP_TYPE_ID )
329
310
return send_id (recv_pkt -> eap_header .id );
330
311
else if (* eap_type (recv_pkt ) == EAP_TYPE_MD5 )
331
- return send_md5 (recv_pkt -> eap_header .id , \
332
- eap_md5_data (recv_pkt ));
312
+ return send_md5 (recv_pkt -> eap_header .id , eap_md5_data (recv_pkt ));
333
313
else if (* eap_type (recv_pkt ) == EAP_TYPE_H3C )
334
314
return send_h3c (recv_pkt -> eap_header .id );
335
315
else
336
316
return SUCCESS ;
337
- else if (recv_pkt -> eap_header .code == EAP_RESPONSE )
338
- {
317
+ else if (recv_pkt -> eap_header .code == EAP_RESPONSE ) {
339
318
/* Got response. */
340
319
if (got_response_callback != NULL )
341
320
return got_response_callback ();
342
321
else
343
322
return RESPONSE_UNHANDLED ;
344
- }
345
- else
346
- {
323
+ } else {
347
324
/* Got unkown eap type. */
348
325
if (unkown_eap_callback != NULL )
349
326
return unkown_eap_callback ();
@@ -352,7 +329,6 @@ int h3c_response(int (*success_callback)(void), \
352
329
}
353
330
}
354
331
355
- void h3c_clean ()
356
- {
332
+ void h3c_clean () {
357
333
close (sockfd );
358
334
}
0 commit comments