00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <arpa/inet.h>
00018 #include "BundleTLV.h"
00019
00020 namespace prophet
00021 {
00022
00023 size_t BundleTLV::write_bundle_entry(u_int32_t cts, u_int32_t seq,
00024 u_int16_t sid, bool custody,
00025 bool accept, bool ack,
00026 BundleTLVEntry::bundle_entry_t type,
00027 u_char* bp, size_t len) const
00028 {
00029
00030 if (bp == NULL) return 0;
00031 if (type == BundleTLVEntry::UNDEFINED) return 0;
00032
00033
00034 if (BundleEntrySize > len) return 0;
00035
00036
00037 BundleEntry* b = (BundleEntry*) bp;
00038 memset(b, 0, BundleEntrySize);
00039 if (custody) b->b_flags |= CUSTODY;
00040 if (accept) b->b_flags |= ACCEPTED;
00041 if (ack) b->b_flags |= ACK;
00042 b->dest_string_id = htons(sid);
00043 b->creation_timestamp = htonl(cts);
00044 b->seqno = htonl(seq);
00045
00046 return BundleEntrySize;
00047 }
00048
00049 size_t BundleTLV::read_bundle_entry(u_int32_t *cts, u_int32_t *seq,
00050 u_int16_t *sid, bool *custody,
00051 bool *accept, bool *ack,
00052 BundleTLVEntry::bundle_entry_t *type,
00053 const u_char* bp, size_t len)
00054 {
00055
00056 if (bp == NULL ||
00057 cts == NULL ||
00058 seq == NULL ||
00059 sid == NULL ||
00060 custody == NULL ||
00061 accept == NULL ||
00062 ack == NULL ||
00063 type == NULL) return 0;
00064
00065
00066 if (BundleEntrySize > len) return 0;
00067
00068
00069 BundleEntry* b = (BundleEntry*) bp;
00070 u_int8_t flags = b->b_flags & 0xff;
00071 *custody = ((flags & CUSTODY) == CUSTODY);
00072 *accept = ((flags & ACCEPTED) == ACCEPTED);
00073 *ack = ((flags & ACK) == ACK);
00074
00075 *type = BundleTLVEntry::decode_flags(*custody,*accept,*ack);
00076 *sid = ntohs(b->dest_string_id);
00077 *cts = ntohl(b->creation_timestamp);
00078 *seq = ntohl(b->seqno);
00079
00080 return BundleEntrySize;
00081 }
00082
00083 };