
API In CPP
121
address.sin_port = htons(port);
addressSize = sizeof(address);
DEBUG ? printf("Connecting to %s\n", strIpAddress.c_str()) : 0;
connectResult = connect(fdSock, (struct sockaddr *)&address, addressSize);
if(connectResult==-1) {
perror ("Connection problem");
Disconnect();
fdSock = -1;
} else {
DEBUG ? printf("Successfully connected to %s\n", strIpAddress.c_str()) : 0;
}
// determine endianness of this machine
// iLittleEndian will be set to 1 if we are
// on a little endian machine...otherwise
// we are assumed to be on a big endian processor
littleEndian = IsLittleEndian();
}
/********************************************************************
* Disconnect from API
* Close the API socket
********************************************************************/
void MikrotikAPI::Disconnect()
{
if(fdSock != -1) {
DEBUG ? printf("Closing socket\n") : 0;
close(fdSock);
}
}
/********************************************************************
* Login to the API
* 1 is returned on successful login
* 0 is returned on unsuccessful login
********************************************************************/
int MikrotikAPI::Login(const string &strUsername, const string &strPassword)
{
Sentence readSentence;
Sentence writeSentence;
md5_state_t state;
md5_byte_t digest[16];
Komentarze do niniejszej Instrukcji