mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-12-17 21:44:20 +01:00
If the received data is smaller than the device information size, then something is wrong.
19 lines
838 B
C
19 lines
838 B
C
#include "device.h"
|
|
#include "log.h"
|
|
|
|
SDL_bool device_read_info(socket_t device_socket, char *device_name, struct size *size) {
|
|
unsigned char buf[DEVICE_NAME_FIELD_LENGTH + 4];
|
|
int r = net_recv(device_socket, buf, sizeof(buf));
|
|
if (r < DEVICE_NAME_FIELD_LENGTH + 4) {
|
|
LOGE("Could not retrieve device information");
|
|
return SDL_FALSE;
|
|
}
|
|
buf[DEVICE_NAME_FIELD_LENGTH - 1] = '\0'; // in case the client sends garbage
|
|
// strcpy is safe here, since name contains at least DEVICE_NAME_FIELD_LENGTH bytes
|
|
// and strlen(buf) < DEVICE_NAME_FIELD_LENGTH
|
|
strcpy(device_name, (char *) buf);
|
|
size->width = (buf[DEVICE_NAME_FIELD_LENGTH] << 8) | buf[DEVICE_NAME_FIELD_LENGTH + 1];
|
|
size->height = (buf[DEVICE_NAME_FIELD_LENGTH + 2] << 8) | buf[DEVICE_NAME_FIELD_LENGTH + 3];
|
|
return SDL_TRUE;
|
|
}
|