Community discussions

MikroTik App
 
hel
Member Candidate
Member Candidate
Topic Author
Posts: 199
Joined: Sun Jun 12, 2011 6:31 am
Location: Kirov, Russia

API in C for windows

Mon Jan 22, 2024 8:22 pm

Old wiki page "API in C" from an unknown author was removed, because this API wasn't updated and had its problems.
However, API in C using Winsock that I have posted long time ago is still on the wiki. But without original sources (that was posted on the "API in C" page) it is useless.

I'm posting an updated working (used in production for years) API in C (winsock version) sources updated for a new authentication (post-6.43). The version on the wiki is only working with legacy authentication.

Remember, that if your compiler does not support "#pragma comment", add ws2_32.lib to your linker manually.
/********************************************************************
 * Some definitions
 * Word = piece of API code
 * Sentence = multiple words
 * Block = multiple sentences (usually in response to a sentence request)
 * 

	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);
	
 ********************************************************************/
You do not have the required permissions to view the files attached to this post.
Last edited by hel on Mon Jan 22, 2024 9:36 pm, edited 1 time in total.
 
optio
Long time Member
Long time Member
Posts: 675
Joined: Mon Dec 26, 2022 2:57 pm

Re: API in C for windows

Mon Jan 22, 2024 8:36 pm

Great to have that, I'm personally more in favor using libcurl and some JSON C library with ROS REST API.
 
hel
Member Candidate
Member Candidate
Topic Author
Posts: 199
Joined: Sun Jun 12, 2011 6:31 am
Location: Kirov, Russia

Re: API in C for windows

Mon Jan 22, 2024 9:14 pm

I'm personally more in favor using libcurl and some JSON C library with ROS REST API.
It depends on the task.
App that I have made using this API for our ISP is running "per user state change" on the billing software. So it should run as fast as it can and consume less resources.
Just imagine if the billing server goes reboot and all users starts to update its state. The processing queue will be long.
 
optio
Long time Member
Long time Member
Posts: 675
Joined: Mon Dec 26, 2022 2:57 pm

Re: API in C for windows

Mon Jan 22, 2024 9:26 pm

Yes, http and json processing for such bulk requests is not much applicable.

Who is online

Users browsing this forum: No registered users and 6 guests