Skip to content

Commit a277247

Browse files
committed
make some funtions static
1 parent 4ab91c2 commit a277247

File tree

4 files changed

+74
-82
lines changed

4 files changed

+74
-82
lines changed

h3c.c

Lines changed: 64 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static unsigned char recv_buf[BUF_LEN];
1818

1919
static struct sockaddr_ll addr;
2020

21-
void h3c_set_eapol_header(unsigned char type, unsigned short p_len)
21+
static void h3c_set_eapol_header(unsigned char type, unsigned short p_len)
2222
{
2323
struct packet *pkt;
2424
pkt = (struct packet *)send_buf;
@@ -28,7 +28,7 @@ void h3c_set_eapol_header(unsigned char type, unsigned short p_len)
2828
pkt->eapol_header.p_len = p_len;
2929
}
3030

31-
void h3c_set_eap_header(unsigned char code, unsigned char id, \
31+
static void h3c_set_eap_header(unsigned char code, unsigned char id, \
3232
unsigned short d_len, unsigned char type)
3333
{
3434
struct packet *pkt;
@@ -40,60 +40,7 @@ void h3c_set_eap_header(unsigned char code, unsigned char id, \
4040
pkt->eap_header.type = type;
4141
}
4242

43-
int h3c_init(char *_interface, char *_username, char *_password)
44-
{
45-
struct ifreq ifr;
46-
struct packet *pkt;
47-
pkt = (struct packet *)send_buf;
48-
49-
interface = _interface;
50-
username = _username;
51-
password = _password;
52-
53-
sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_PAE));
54-
if (-1 == sockfd)
55-
return -1;
56-
57-
memcpy(pkt->eth_header.ether_dhost,PAE_GROUP_ADDR,ETH_ALEN);
58-
59-
strcpy(ifr.ifr_name, interface);
60-
if (-1 == ioctl(sockfd, SIOCGIFHWADDR, &ifr))
61-
return -1;
62-
63-
memcpy(pkt->eth_header.ether_shost,ifr.ifr_hwaddr.sa_data,ETH_ALEN);
64-
65-
if(-1 == ioctl(sockfd,SIOCGIFINDEX,&ifr))
66-
return -1;
67-
68-
addr.sll_ifindex = ifr.ifr_ifindex;
69-
70-
/*
71-
* use htons when the data is more than 1 byte
72-
*/
73-
pkt->eth_header.ether_type = htons(ETH_P_PAE);
74-
75-
return 0;
76-
}
77-
78-
int h3c_start()
79-
{
80-
h3c_set_eapol_header(EAPOL_START, 0);
81-
82-
return sendto(sockfd, (void *)send_buf, \
83-
sizeof(struct ether_header)+ sizeof(struct eapol), 0, \
84-
(struct sockaddr*)&addr, sizeof(addr));
85-
}
86-
87-
int h3c_logoff()
88-
{
89-
h3c_set_eapol_header(EAPOL_LOGOFF, 0);
90-
91-
return sendto(sockfd, (void *)send_buf, \
92-
sizeof(struct ether_header) + sizeof(struct eapol), 0, \
93-
(struct sockaddr*)&addr, sizeof(addr));
94-
}
95-
96-
int h3c_send_id(unsigned char packet_id)
43+
static int h3c_send_id(unsigned char packet_id)
9744
{
9845
unsigned short len = htons(sizeof(struct eap) + \
9946
sizeof(VERSION_INFO) + strlen(username));
@@ -113,7 +60,7 @@ int h3c_send_id(unsigned char packet_id)
11360
(struct sockaddr*)&addr, sizeof(addr));
11461
}
11562

116-
int h3c_send_md5(unsigned char packet_id, unsigned char *md5data)
63+
static int h3c_send_md5(unsigned char packet_id, unsigned char *md5data)
11764
{
11865
unsigned char md5[MD5_LEN];
11966
unsigned short len = htons(sizeof(struct eap) + 1 + \
@@ -143,8 +90,11 @@ int h3c_send_md5(unsigned char packet_id, unsigned char *md5data)
14390
(struct sockaddr*)&addr, sizeof(addr));
14491
}
14592

146-
int h3c_send_h3c(unsigned char packet_id)
93+
static int h3c_send_h3c(unsigned char packet_id)
14794
{
95+
/*
96+
* not called so far
97+
*/
14898
size_t password_size = strlen(password);
14999
size_t username_size = strlen(username);
150100

@@ -169,6 +119,59 @@ int h3c_send_h3c(unsigned char packet_id)
169119
(struct sockaddr*)&addr, sizeof(addr));
170120
}
171121

122+
int h3c_init(char *_interface, char *_username, char *_password)
123+
{
124+
struct ifreq ifr;
125+
struct packet *pkt;
126+
pkt = (struct packet *)send_buf;
127+
128+
interface = _interface;
129+
username = _username;
130+
password = _password;
131+
132+
sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_PAE));
133+
if (-1 == sockfd)
134+
return -1;
135+
136+
memcpy(pkt->eth_header.ether_dhost,PAE_GROUP_ADDR,ETH_ALEN);
137+
138+
strcpy(ifr.ifr_name, interface);
139+
if (-1 == ioctl(sockfd, SIOCGIFHWADDR, &ifr))
140+
return -1;
141+
142+
memcpy(pkt->eth_header.ether_shost,ifr.ifr_hwaddr.sa_data,ETH_ALEN);
143+
144+
if(-1 == ioctl(sockfd,SIOCGIFINDEX,&ifr))
145+
return -1;
146+
147+
addr.sll_ifindex = ifr.ifr_ifindex;
148+
149+
/*
150+
* use htons when the data is more than 1 byte
151+
*/
152+
pkt->eth_header.ether_type = htons(ETH_P_PAE);
153+
154+
return 0;
155+
}
156+
157+
int h3c_start()
158+
{
159+
h3c_set_eapol_header(EAPOL_START, 0);
160+
161+
return sendto(sockfd, (void *)send_buf, \
162+
sizeof(struct ether_header)+ sizeof(struct eapol), 0, \
163+
(struct sockaddr*)&addr, sizeof(addr));
164+
}
165+
166+
int h3c_logoff()
167+
{
168+
h3c_set_eapol_header(EAPOL_LOGOFF, 0);
169+
170+
return sendto(sockfd, (void *)send_buf, \
171+
sizeof(struct ether_header) + sizeof(struct eapol), 0, \
172+
(struct sockaddr*)&addr, sizeof(addr));
173+
}
174+
172175
int h3c_response(int (*success_callback)(), int (*failure_callback)())
173176
{
174177
struct packet *pkt;
@@ -182,12 +185,10 @@ int h3c_response(int (*success_callback)(), int (*failure_callback)())
182185
return -1;
183186

184187
if (pkt->eapol_header.type != EAPOL_EAPPACKET)
185-
{
186188
/*
187189
* Got unknown eapol type
188190
*/
189191
return 0;
190-
}
191192

192193
if (pkt->eap_header.code == EAP_SUCCESS)
193194
{
@@ -216,25 +217,21 @@ int h3c_response(int (*success_callback)(), int (*failure_callback)())
216217
* Response according to request type
217218
*/
218219
if (pkt->eap_header.type == EAP_TYPE_ID)
219-
{
220220
return h3c_send_id(pkt->eap_header.id);
221-
}
222221
else if (pkt->eap_header.type == EAP_TYPE_MD5)
223222
{
224223
unsigned char *md5;
225224
md5 = (unsigned char *)(recv_buf + sizeof(struct packet) + 1);
226225
return h3c_send_md5(pkt->eap_header.id, md5);
227226
}
228227
else if (pkt->eap_header.type == EAP_TYPE_H3C)
229-
{
230228
return h3c_send_h3c(pkt->eap_header.id);
231-
}
232229
}
233230
else if (pkt->eap_header.code == EAP_RESPONSE)
234-
{
235231
/*
236232
* Got response
237233
*/
238-
return 0;
239-
}
234+
return 0;
235+
236+
return 0;
240237
}

h3c.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ const static char PAE_GROUP_ADDR[] = \
4545
{0x01, 0x80, 0xc2, 0x00, 0x00, 0x03};
4646

4747
const static char VERSION_INFO[] = \
48-
{0x06, 0x07, 'b', 'j', 'Q', '7', 'S', 'E', '8', 'B', 'Z', '3', 'M', \
49-
'q', 'H', 'h', 's', '3', 'c', 'l', 'M', 'r', 'e', 'g', 'c', 'D', 'Y', \
50-
'3', 'Y', '=',0x20,0x20};
48+
{0x06, 0x07, 'b', 'j', 'Q', '7', 'S', 'E', '8', 'B', 'Z', '3', \
49+
'M', 'q', 'H', 'h', 's', '3', 'c', 'l', 'M', 'r', 'e', 'g', \
50+
'c', 'D', 'Y', '3', 'Y', '=',0x20,0x20};
5151

5252
struct eapol{
5353
unsigned char version;
@@ -68,23 +68,17 @@ struct packet{
6868
struct eap eap_header;
6969
}__attribute__ ((packed)) packet;
7070

71-
void h3c_set_eapol_header(unsigned char type, unsigned short p_len);
72-
73-
void h3c_set_eap_header(unsigned char code, unsigned char id, \
71+
static void h3c_set_eapol_header(unsigned char type, unsigned short p_len);
72+
static void h3c_set_eap_header(unsigned char code, unsigned char id, \
7473
unsigned short d_len, unsigned char type);
7574

76-
int h3c_init(char *_interface, char *_username, char *_password);
75+
static int h3c_send_id(unsigned char packet_id);
76+
static int h3c_send_md5(unsigned char packet_id, unsigned char *md5data);
77+
static int h3c_send_h3c(unsigned char packet_id);
7778

79+
int h3c_init(char *_interface, char *_username, char *_password);
7880
int h3c_start();
79-
8081
int h3c_logoff();
81-
8282
int h3c_response(int (*success_callback)(), int (*failure_callback)());
8383

84-
int h3c_send_id(unsigned char packet_id);
85-
86-
int h3c_send_md5(unsigned char packet_id, unsigned char *md5data);
87-
88-
int h3c_send_h3c(unsigned char packet_id);
89-
9084
#endif /* H3C_H_ */

h3c64

0 Bytes
Binary file not shown.

main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int success_handler()
1616
int failure_hander()
1717
{
1818
printf("failed\n");
19+
return 0;
1920
}
2021

2122
int main(int argc, char **argv)

0 commit comments

Comments
 (0)