头文件
#include "get_mac.h" #include#include #include #include #include #include #include #include #include #include #include #include #include
int func(char* source, char* buf)
{
int i = 0, j = 0, flag = 0;
while (source[i] != '\0')
{
if (flag == 0 && source[i] == '\"')
{
flag = 1;
}
else if (flag == 1 && source[i] == '\"')
{
buf[j] = '\0';
return 1;
}
else if (flag == 1 && source[i] != '\"')
{
buf[j++] = source[i];
}
i++;
}
return 0;
}
int get_ssid(char *ssid)
{
FILE *fstream = NULL;
char buff[1024];
memset(buff, 0, sizeof(buff));
if (NULL == (fstream = popen("iwconfig apcli0", "r")))
{
fprintf(stderr, "execute command failed: %s", strerror(errno));
return -1;
}
while (NULL != fgets(buff, sizeof(buff), fstream)) {
break;
}
func(buff, ssid);
pclose(fstream);
return 0;
return 0;
}
不错学习了!