1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
| #include <stdio .h>
#include <stdlib .h>
#include <sys /socket.h>
#include <string .h>
#include "wireless_copy.h"
int get_essid(int sock, struct iwreq* wrq,char* ssid);
int set_essid(int sock, struct iwreq* wrq,char* value);
int main(){
struct iwreq wrq;
int i,sock;
char gInterfaceName[16];
char *ssid=(char *)malloc(sizeof(char)*(32+1));
char *set_ssid="testssid";
memset(ssid,0,sizeof(ssid));
memset(gInterfaceName, 0, sizeof(gInterfaceName));
strcat(gInterfaceName,"ath0");
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0)
{
printf("Error Creating Socket for ioctl\n");
return 0;
}
memset(&wrq, 0, sizeof(wrq));
strncpy(wrq.ifr_name, gInterfaceName, IFNAMSIZ);
//get ssid
get_essid(sock, &wrq,ssid);
printf("old ssid:%s\n",wrq.u.essid.pointer);
free(ssid);
//reset struct
memset(&wrq, 0, sizeof(wrq));
strncpy(wrq.ifr_name, gInterfaceName, IFNAMSIZ);
//set ssid
set_essid(sock, &wrq,set_ssid);
printf("new ssid:%s\n",wrq.u.essid.pointer);
}
int get_essid(int sock, struct iwreq* wrq,char* ssid)
{
wrq->u.essid.length=32;
wrq->u.essid.pointer=(caddr_t) ssid;
if(ioctl(sock, SIOCGIWESSID, wrq) < 0)
{
perror("Ioctl error");
free(ssid);
return(0);
}
printf("\nssid from function get_ssid: %s\n", wrq->u.essid.pointer);
return 1;
}
int set_essid(int sock, struct iwreq* wrq,char* value)
{
wrq->u.essid.pointer=value;
wrq->u.essid.length=strlen(value);
wrq->u.essid.flags=1;
if(ioctl(sock, SIOCSIWESSID, wrq) < 0)
{
perror("Ioctl error");
return(0);
}
printf("\nessid from function set_essid: %s\n", wrq->u.essid.pointer);
return 1;
}
</string></sys></stdlib></stdio> |
COMMENTS