Datasheet

API in C
216
*
int fdSock;
int iLoginResult;
struct Sentence stSentence;
struct Block stBlock;
fdSock = apiConnect("10.0.0.1", 8728);
// attempt login
iLoginResult = login(fdSock, "admin", "adminPassword");
if (!iLoginResult)
{
apiDisconnect(fdSock);
printf("Invalid username or password.\n");
exit(1);
}
// initialize, fill and send sentence to the API
initializeSentence(&stSentence);
addWordToSentence(&stSentence, "/interface/getall");
writeSentence(fdSock, &stSentence);
// receive and print block from the API
stBlock = readBlock(fdSock);
printBlock(&stBlock);
apiDisconnect(fdSock);
********************************************************************/
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
#include "md5.h"
#include "mikrotik-api.h"
/********************************************************************
* Connect to API