23 #define BUFFER_LENGTH 100
28 if( strncmp(buffer,
"ipn:", 4) != 0 ) {
29 LOG(LOGD_DTN, LOG_AGENT, LOGL_WRN,
"Unknown EID format %s", &buffer[4]);
34 *node_id = atoi(&buffer[4]);
36 return strlen(buffer);
46 sdnv_length =
sdnv_decode(buffer, length, &eid_length);
47 if (sdnv_length < 0) {
48 LOG(LOGD_DTN, LOG_AGENT, LOGL_WRN,
"Unknown EID format %s", &buffer[4]);
53 ret =
eid_parse_host((
char *) &buffer[sdnv_length], length - sdnv_length, node_id);
55 LOG(LOGD_DTN, LOG_AGENT, LOGL_WRN,
"Unknown EID format %s", &buffer[4]);
59 return sdnv_length + ret;
62 int eid_parse_full(
char * buffer, uint8_t length, uint32_t * node_id, uint32_t * service_id)
64 char * delimeter =
NULL;
68 if( strncmp(buffer,
"ipn:", 4) != 0 ) {
69 LOG(LOGD_DTN, LOG_AGENT, LOGL_WRN,
"Unknown EID format %s", &buffer[4]);
74 delimeter = strchr(buffer,
'.');
75 if( delimeter ==
NULL ) {
76 LOG(LOGD_DTN, LOG_AGENT, LOGL_WRN,
"Unknown EID format %s", &buffer[4]);
85 *node_id = atoi(&buffer[4]);
88 *service_id = atoi(delimeter);
90 result = strlen(buffer) + strlen(delimeter) + 1;
106 sdnv_length =
sdnv_decode(buffer, length, &eid_length);
107 if (sdnv_length < 0) {
108 LOG(LOGD_DTN, LOG_AGENT, LOGL_WRN,
"Unknown EID format %s", &buffer[4]);
112 ret =
eid_parse_full((
char *) &buffer[sdnv_length], length - sdnv_length, node_id, service_id);
114 LOG(LOGD_DTN, LOG_AGENT, LOGL_WRN,
"Unknown EID format %s", &buffer[4]);
118 return sdnv_length + ret;
123 return sprintf(buffer,
"ipn:%lu", node_id);
128 char string_buffer[BUFFER_LENGTH];
134 if( eid_length < 0 ) {
139 ret =
sdnv_encode(eid_length, (uint8_t *) buffer, length);
145 if( length - ret < eid_length ) {
150 memcpy(buffer + ret, string_buffer, eid_length);
152 return ret + eid_length;
155 int eid_create_full(uint32_t node_id, uint32_t service_id,
char * buffer, uint8_t length)
157 return sprintf(buffer,
"ipn:%lu.%lu", node_id, service_id);
162 char string_buffer[BUFFER_LENGTH];
167 eid_length =
eid_create_full(node_id, service_id, string_buffer, BUFFER_LENGTH);
168 if( eid_length < 0 ) {
173 ret =
sdnv_encode(eid_length, (uint8_t *) buffer, length);
179 if( length - ret < eid_length ) {
184 memcpy(buffer + ret, string_buffer, eid_length);
186 return ret + eid_length;