From 7da00ec0894048070cc2f437fcbe1aebde01ff70 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Wed, 22 Aug 2012 07:28:34 +0200 Subject: [PATCH] Convert the current data set TLV to and from host byte order. Signed-off-by: Richard Cochran --- ds.h | 2 +- tlv.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ds.h b/ds.h index a6de2b4..13bec96 100644 --- a/ds.h +++ b/ds.h @@ -51,7 +51,7 @@ struct currentDS { UInteger16 stepsRemoved; TimeInterval offsetFromMaster; TimeInterval meanPathDelay; -}; +} PACKED; struct parentDS { struct PortIdentity parentPortIdentity; diff --git a/tlv.c b/tlv.c index 3e84184..c2e827c 100644 --- a/tlv.c +++ b/tlv.c @@ -37,6 +37,32 @@ static void scaled_ns_h2n(ScaledNs *sns) sns->fractional_nanoseconds = htons(sns->fractional_nanoseconds); } +static void mgt_post_recv(struct management_tlv *m) +{ + struct currentDS *cds; + switch (m->id) { + case CURRENT_DATA_SET: + cds = (struct currentDS *) m->data; + cds->stepsRemoved = ntohs(cds->stepsRemoved); + cds->offsetFromMaster = net2host64(cds->offsetFromMaster); + cds->meanPathDelay = net2host64(cds->meanPathDelay); + break; + } +} + +static void mgt_pre_send(struct management_tlv *m) +{ + struct currentDS *cds; + switch (m->id) { + case CURRENT_DATA_SET: + cds = (struct currentDS *) m->data; + cds->stepsRemoved = htons(cds->stepsRemoved); + cds->offsetFromMaster = host2net64(cds->offsetFromMaster); + cds->meanPathDelay = host2net64(cds->meanPathDelay); + break; + } +} + static void org_post_recv(struct organization_tlv *org) { struct follow_up_info_tlv *f; @@ -87,6 +113,7 @@ void tlv_post_recv(struct TLV *tlv) case TLV_MANAGEMENT: mgt = (struct management_tlv *) tlv; mgt->id = ntohs(mgt->id); + mgt_post_recv(mgt); break; case TLV_MANAGEMENT_ERROR_STATUS: mes = (struct management_error_status *) tlv; @@ -125,6 +152,7 @@ void tlv_pre_send(struct TLV *tlv) switch (tlv->type) { case TLV_MANAGEMENT: mgt = (struct management_tlv *) tlv; + mgt_pre_send(mgt); mgt->id = htons(mgt->id); break; case TLV_MANAGEMENT_ERROR_STATUS: