diff --git a/pmc.c b/pmc.c index 3097917..59e087b 100644 --- a/pmc.c +++ b/pmc.c @@ -596,6 +596,19 @@ static int parse_id(char *s) return index; } +static int parse_target(const char *str) +{ + struct PortIdentity pid; + + if (str[0] == '*') { + memset(&pid, 0xff, sizeof(pid)); + } else if (str2pid(str, &pid)) { + return -1; + } + + return pmc_target(pmc, &pid); +} + static void print_help(FILE *fp) { int i; @@ -608,6 +621,9 @@ static void print_help(FILE *fp) fprintf(fp, "\tThe [action] can be GET, SET, CMD, or COMMAND\n"); fprintf(fp, "\tCommands are case insensitive and may be abbreviated.\n"); fprintf(fp, "\n"); + fprintf(fp, "\tTARGET [portIdentity]\n"); + fprintf(fp, "\tTARGET *\n"); + fprintf(fp, "\n"); } static int do_command(char *str) @@ -623,6 +639,9 @@ static int do_command(char *str) if (2 != sscanf(str, " %10s %64s", action_str, id_str)) return -1; + if (0 == strncasecmp(action_str, "TARGET", strlen(action_str))) + return parse_target(id_str); + action = parse_action(action_str); id = parse_id(id_str); diff --git a/util.c b/util.c index 30bd8a1..4b0ef6b 100644 --- a/util.c +++ b/util.c @@ -82,6 +82,22 @@ char *pid2str(struct PortIdentity *id) return buf; } +int str2pid(const char *s, struct PortIdentity *result) +{ + struct PortIdentity pid; + unsigned char *ptr = pid.clockIdentity.id; + int c; + c = sscanf(s, " %02hhx%02hhx%02hhx.%02hhx%02hhx.%02hhx%02hhx%02hhx-%hu", + &ptr[0], &ptr[1], &ptr[2], &ptr[3], + &ptr[4], &ptr[5], &ptr[6], &ptr[7], + &pid.portNumber); + if (c == 9) { + *result = pid; + return 0; + } + return -1; +} + int generate_clock_identity(struct ClockIdentity *ci, char *name) { unsigned char mac[6]; diff --git a/util.h b/util.h index 52c4bcb..8cf3890 100644 --- a/util.h +++ b/util.h @@ -55,6 +55,15 @@ char *cid2str(struct ClockIdentity *id); */ char *pid2str(struct PortIdentity *id); +/** + * Scan a string containing a port identity and convert it into binary form. + * + * @param s String in human readable form. + * @param result Pointer to a buffer to hold the result. + * @return Zero on success, or -1 if the string is incorrectly formatted. + */ +int str2pid(const char *s, struct PortIdentity *result); + int generate_clock_identity(struct ClockIdentity *ci, char *name); /**