#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
-
+#define MACSTR_LEN 18
#define MAX_PEER_NUM 10
static const char *test_wfd_convert_error_to_string(wifi_direct_error_e err_type)
printf("input peer index:\n");
if (scanf(" %3d", &target) < 1)
- return -1;
+ return 0;
if (target < 0 || target > ad->peer_count) {
printf("Wrong contact index [%d]\n", target);
- return -1;
+ return 0;
} else
ad->selected_peer_index = target;
event_printf("event - WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
if (error_code == WIFI_DIRECT_ERROR_NONE) {
- char _peer_mac[18] = {0, };
+ char _peer_mac[MACSTR_LEN+1] = {0,};
if (NULL != mac_address)
- strncpy(_peer_mac, mac_address, strlen(mac_address));
+ g_strlcpy(_peer_mac, mac_address, sizeof(_peer_mac));
printf("Connection start with [%s] \n", _peer_mac);
event_printf("Error None\n");
event_printf("event - WIFI_DIRECT_CONNECTION_RSP\n");
if (error_code == WIFI_DIRECT_ERROR_NONE) {
- char incomming_peer_mac[18] = {0, };
+ char incomming_peer_mac[MACSTR_LEN+1] = {0,};
char status[100] = {0,};
if (NULL != mac_address)
- strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+ g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
printf("Connection response with [%s] \n", incomming_peer_mac);
event_printf("Error None\n");
if (owner) {
wifi_direct_get_ip_address(&ip_addr);
if (NULL != ip_addr) {
- sprintf(status, "<color=#FFFFFF>GO - IP : %s", ip_addr);
+ snprintf(status, sizeof(status), "<color=#FFFFFF>GO - IP : %s", ip_addr);
free(ip_addr);
}
} else {
wifi_direct_get_ip_address(&ip_addr);
if (NULL != ip_addr) {
- sprintf(status, "<color=#FFFFFF>STA - IP : %s", ip_addr);
+ snprintf(status, sizeof(status), "<color=#FFFFFF>STA - IP : %s", ip_addr);
free(ip_addr);
}
}
case WIFI_DIRECT_CONNECTION_REQ:
{
event_printf("event - WIFI_DIRECT_CONNECTION_REQ\n");
- char incomming_peer_mac[18];
+ char incomming_peer_mac[MACSTR_LEN+1];
wifi_direct_wps_type_e wps_mode;
bool auto_connection_mode;
bool allow_connection = FALSE;
memset(incomming_peer_mac, 0, sizeof(incomming_peer_mac));
if (NULL != mac_address)
- strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+ g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
printf("Connection Request from [%s] \n", incomming_peer_mac);
event_printf("event - WIFI_DIRECT_DISCONNECTION_IND\n");
if (error_code == WIFI_DIRECT_ERROR_NONE) {
- char incomming_peer_mac[18] = {0, };
+ char incomming_peer_mac[MACSTR_LEN+1] = {0,};
if (NULL != mac_address)
- strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+ g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
printf("Disconnection IND from [%s] \n", incomming_peer_mac);
event_printf("event - WIFI_DIRECT_DISCONNECTION_RSP\n");
if (error_code == WIFI_DIRECT_ERROR_NONE) {
- char incomming_peer_mac[18] = {0, };
+ char incomming_peer_mac[MACSTR_LEN+1] = {0,};
if (NULL != mac_address)
- strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+ g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
printf("Disconnection RSP with [%s] \n", incomming_peer_mac);
event_printf("event - WIFI_DIRECT_DISASSOCIATION_IND\n");
if (error_code == WIFI_DIRECT_ERROR_NONE) {
- char incomming_peer_mac[18] = {0, };
+ char incomming_peer_mac[MACSTR_LEN+1] = {0,};
if (NULL != mac_address)
- strncpy(incomming_peer_mac, mac_address, strlen(mac_address));
+ g_strlcpy(incomming_peer_mac, mac_address, sizeof(incomming_peer_mac));
printf("Disassociation IND from [%s] \n", incomming_peer_mac);
result = wifi_direct_get_mac_address(&device_mac);
printf("wifi_direct_get_mac_addr() result=[%d]\n", result);
- if (NULL != device_mac)
+ if (NULL != device_mac) {
printf("MAC [%s] \n", device_mac);
- else
+ free(device_mac);
+ } else
printf("device_mac is NULL !! \n");
}
break;
errno = 0;
n = read(fd, buf, 1024);
- buf[n - 1] = '\0'; /* remove new line... */
if (n == 0) {
printf("Error: read() from stdin returns 0.\n");
} else if (n < 0) {
- printf("input: read, err=%s\n", strerror(errno));
+ char error_buf[100] = {0, };
+ strerror_r(errno, error_buf, sizeof(error_buf));
+ printf("input: read, err=%s\n", error_buf);
} else {
+ buf[n - 1] = '\0'; /* remove new line... */
printf("\n\n");
/* printf("Read [%d]bytes data: [%s]\n", n, buf); */
/* printf("Processing it ---------------------\n", n, buf); */
main_loop = g_main_loop_new(NULL, FALSE);
- ad = (struct appdata*)malloc(sizeof(struct appdata));
+ ad = (struct appdata*)g_try_malloc0(sizeof(struct appdata));
+ if (!ad)
+ return -1;
ad->main_loop = main_loop;
g_main_loop_run(main_loop);
+ g_free(ad);
return 0;
}