Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
GH-38: Fix adb-putty to support multi-devices
Browse files Browse the repository at this point in the history
To connect a specific device, input device ID in host name
To connect the default device, input a colon(:) in host name
  • Loading branch information
yumeyao authored and FauxFaux committed May 8, 2013
1 parent d67c5ae commit 94932c4
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions adb.c
Expand Up @@ -191,23 +191,25 @@ static const char *adb_init(void *frontend_handle, void **backend_handle,
}
}

/* send initial data to adb server */
#if _MSC_VER
sprintf_s
#else
snprintf
#endif
(sendhost, 512,
#if _MSC_VER
"%04xhost:%s"
#else
"%04zxhost:%s"
#endif
, strlen(host)+5, host);

sk_write(adb->s,sendhost,strlen(host)+9);
sk_flush(adb->s);
adb->state = 1;
/* send initial data to adb server */
#define ADB_SHELL_DEFAULT_STR "0012" "host:transport-usb"
#define ADB_SHELL_DEFAULT_STR_LEN (sizeof(ADB_SHELL_DEFAULT_STR)-1)
#define ADB_SHELL_SERIAL_PREFIX "host:transport:"
#define ADB_SHELL_SERIAL_PREFIX_LEN (sizeof(ADB_SHELL_SERIAL_PREFIX)-1)
do {
size_t len = strlen(host);
if (len == 0) {
sk_write(adb->s, ADB_SHELL_DEFAULT_STR, ADB_SHELL_DEFAULT_STR_LEN);
} else {
char sendbuf[512];
#define ADB_SHELL_HOST_MAX_LEN (sizeof(sendbuf)-4-ADB_SHELL_SERIAL_PREFIX_LEN)
if (len > ADB_SHELL_HOST_MAX_LEN)
len = ADB_SHELL_HOST_MAX_LEN;
sprintf(sendbuf,"%04x" ADB_SHELL_SERIAL_PREFIX, len+ADB_SHELL_SERIAL_PREFIX_LEN);
memcpy(sendbuf+4+ADB_SHELL_SERIAL_PREFIX_LEN, host, len);
sk_write(adb->s,sendbuf,len+4+ADB_SHELL_SERIAL_PREFIX_LEN);
}
} while (0);
return NULL;
}

Expand Down

0 comments on commit 94932c4

Please sign in to comment.