static char *msg_mkopt(struct nmrp_msg *msg, char *p, uint16_t type, const void *val, size_t len)
{
- struct nmrp_opt* opt = (struct nmrp_opt*)(p ? p : msg->opts);
+ struct nmrp_opt* opt = (struct nmrp_opt*)p;
len &= 0xffff;
opt->type = htons(type);
opt->len = NMRP_OPT_HDR_LEN + len;
- memcpy(opt->val, val, len);
+
+ if (val) {
+ memcpy(opt->val, val, len);
+ }
msg->len += opt->len;
p += opt->len;
};
msg_init(msg, NMRP_C_CONF_ACK);
- p = msg_mkopt(msg, NULL, NMRP_O_DEV_IP, &ip, 8);
+ p = msg_mkopt(msg, msg->opts, NMRP_O_DEV_IP, &ip, 8);
+ p = msg_mkopt(msg, p, NMRP_O_FW_UP, NULL, 0);
#ifdef NMRPFLASH_SET_REGION
if (region) {
len = ntohs(pkt->msg.len) + sizeof(pkt->eh);
- if (bytes < len) {
- fprintf(stderr, "Short packet (expected %d, got %d).\n",
+ if (bytes != len) {
+ fprintf(stderr, "Unexpected packet length (expected %d, got %d).\n",
(int)len, (int)bytes);
return 1;
}
while (!g_interrupted) {
if (expect != NMRP_C_NONE && rx.msg.code != expect) {
fprintf(stderr, "Received %s while waiting for %s!\n",
- msg_code_str(ntohs(rx.msg.code)), msg_code_str(expect));
+ msg_code_str(rx.msg.code), msg_code_str(expect));
}
msg_init(&tx.msg, NMRP_C_NONE);