Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type support #29

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions src/mctp-req.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static const size_t DEFAULT_LEN = 1;
/* lladdrlen != -1 to ignore ifindex/lladdr */
static int mctp_req(unsigned int net, mctp_eid_t eid,
unsigned int ifindex, uint8_t *lladdr, int lladdrlen,
uint8_t *data, size_t len)
uint8_t *data, size_t len, int type)
{
struct sockaddr_mctp_ext addr;
unsigned char *buf, *rxbuf;
Expand All @@ -42,7 +42,7 @@ static int mctp_req(unsigned int net, mctp_eid_t eid,
addr.smctp_base.smctp_family = AF_MCTP;
addr.smctp_base.smctp_network = net;
addr.smctp_base.smctp_addr.s_addr = eid;
addr.smctp_base.smctp_type = 1;
addr.smctp_base.smctp_type = type;
addr.smctp_base.smctp_tag = MCTP_TAG_OWNER;
printf("req: sending to (net %d, eid %d), type %d\n",
net, eid, addr.smctp_base.smctp_type);
Expand Down Expand Up @@ -87,7 +87,10 @@ static int mctp_req(unsigned int net, mctp_eid_t eid,
(struct sockaddr *)&addr, &addrlen);
if (rc < 0)
err(EXIT_FAILURE, "recvfrom");
else if ((size_t)rc != len)

//For a real query, the reponse will likely be longer than
//The request.
else if ((size_t)rc < len)
errx(EXIT_FAILURE, "unexpected length: got %d, exp %zd",
rc, len);

Expand All @@ -109,21 +112,24 @@ static int mctp_req(unsigned int net, mctp_eid_t eid,
addr.smctp_haddr[0], addr.smctp_halen);
}

for (i = 0; i < len; i++) {
uint8_t exp = data ? data[i] : i & 0xff;
if (rxbuf[i] != exp)
errx(EXIT_FAILURE,
"payload mismatch at byte 0x%zx; "
"sent 0x%02x, received 0x%02x",
i, exp, rxbuf[i]);
for (int j = 0; j < rc; j++) {
//uint8_t exp = data ? data[i] : i & 0xff;

printf("0x%02x ", rxbuf[j]);
//if (rxbuf[i] != exp)
// errx(EXIT_FAILURE,
// "payload mismatch at byte 0x%zx; "
// "sent 0x%02x, received 0x%02x",
// i, exp, rxbuf[i]);
}
printf("\n");

return 0;
}

static void usage(void)
{
fprintf(stderr, "mctp-req [eid <eid>] [net <net>] [ifindex <ifindex> lladdr <hwaddr>] [len <len>]\n");
fprintf(stderr, "mctp-req [eid <eid>] [net <net>] [ifindex <ifindex> lladdr <hwaddr>] [len <len>] [type <type>]\n");
fprintf(stderr, "default eid %d net %d len %zd\n",
DEFAULT_EID, DEFAULT_NET, DEFAULT_LEN);
}
Expand All @@ -138,6 +144,7 @@ int main(int argc, char ** argv)
char *endp, *optname, *optval;
unsigned int tmp, ifindex;
bool valid_parse;
int type = 1;
int i;

if (!(argc % 2)) {
Expand Down Expand Up @@ -165,7 +172,9 @@ int main(int argc, char ** argv)
net = tmp;
} else if (!strcmp(optname, "ifindex")) {
ifindex = tmp;
} else if (!strcmp(optname, "len")) {
} else if (!strcmp(optname, "type")) {
type = tmp;
} else if (!strcmp(optname, "len")) {
if (tmp > 64 * 1024)
errx(EXIT_FAILURE, "Bad len");
len = tmp;
Expand Down Expand Up @@ -199,5 +208,5 @@ int main(int argc, char ** argv)
if (data)
len = datalen;

return mctp_req(net, eid, ifindex, lladdr, lladdrlen, data, len);
return mctp_req(net, eid, ifindex, lladdr, lladdrlen, data, len, type);
}