
API in C
214
{
static const md5_byte_t pad[64] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
md5_byte_t data[8];
int i;
/* Save the length before padding. */
for (i = 0; i < 8; ++i)
data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
/* Pad to 56 bytes mod 64. */
md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
/* Append the length. */
md5_append(pms, data, 8);
for (i = 0; i < 16; ++i)
digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
}
RouterOS API Header file (mikrotik-api.h)
This is the API header file.
Notes:
•• DEBUG flag is defined for debugging purposes...generates alot of internal data via printf
•• DONE, TRAP and FATAL constants are defined
•• Sentence and Block structs are defined.
•• Each word in a sentence is stored as a string. Sentence structs contain individual API words (stored as an array
of strings).
•• Block structs represent the full API response...an array of sentences. Blocks are not defined in the Mikrotik
API specs, but are a convenient way to represent a full API response in the context of this implementation.
#include "md5.h"
#define DEBUG 0
#define DONE 1
#define TRAP 2
#define FATAL 3
struct Sentence {
char **szSentence; // array of strings representing individual words
int iLength; // length of szSentence (number of array elements)
int iReturnValue; // return value of sentence reads from API
};
struct Block {
Komentarze do niniejszej Instrukcji