2018-02-08 22:42:49 +08:00
|
|
|
#include "device.h"
|
2019-09-30 04:36:56 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
2019-11-24 18:53:00 +08:00
|
|
|
#include "util/log.h"
|
2018-02-08 22:42:49 +08:00
|
|
|
|
2019-03-03 06:52:22 +08:00
|
|
|
bool
|
2019-03-03 03:09:56 +08:00
|
|
|
device_read_info(socket_t device_socket, char *device_name, struct size *size) {
|
2018-02-08 22:42:49 +08:00
|
|
|
unsigned char buf[DEVICE_NAME_FIELD_LENGTH + 4];
|
2018-02-16 06:55:52 +08:00
|
|
|
int r = net_recv_all(device_socket, buf, sizeof(buf));
|
2018-02-16 06:47:07 +08:00
|
|
|
if (r < DEVICE_NAME_FIELD_LENGTH + 4) {
|
2018-02-13 17:10:18 +08:00
|
|
|
LOGE("Could not retrieve device information");
|
2019-03-03 06:52:22 +08:00
|
|
|
return false;
|
2018-02-08 22:42:49 +08:00
|
|
|
}
|
2019-03-03 03:09:56 +08:00
|
|
|
// in case the client sends garbage
|
|
|
|
buf[DEVICE_NAME_FIELD_LENGTH - 1] = '\0';
|
|
|
|
// strcpy is safe here, since name contains at least
|
|
|
|
// DEVICE_NAME_FIELD_LENGTH bytes and strlen(buf) < DEVICE_NAME_FIELD_LENGTH
|
2018-02-08 22:42:49 +08:00
|
|
|
strcpy(device_name, (char *) buf);
|
2019-03-03 03:09:56 +08:00
|
|
|
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];
|
2019-03-03 06:52:22 +08:00
|
|
|
return true;
|
2018-02-08 22:42:49 +08:00
|
|
|
}
|