Windows LLDP Driver Responds With No Data

Joined
Mar 17, 2023
Messages
1
Reaction score
0
Hello fellow programmers;

I'm have written a small program as part of my feasibility study and research.
The program is suppose to read data from the LLDP driver for a duration of
one minute (60 seconds). The only problem is that no data is being read. The
code is as follows;

//File includes.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <io.h>
#include <windows.h>
#include "ttime.h"

DWORD WINAPI MainTimer(void *inobj){

//Variable declarations
unsigned long tmplong = 0;
int *tmpn = 0;
int tmpn2 = 0;
int ret = 0;

//Argument checks
if(inobj == NULL){
return TPTRISNULL;
}

//Initializations
tmpn = (int*)inobj;

//Main logic

//Wait for 60 seconds.
ret = WaitNSeconds(60000);

//Update the argument.
*tmpn = 1;

//Returns

}

int main(int argc, char *argv[]){

//Variable declarations
HANDLE tmphnd = 0;
HANDLE tmpthrd = 0;
COMMTIMEOUTS *tmptimeouts = 0;
void *tmpvoid = 0;
int *tmpn = 0;
char *tmpstr = 0;
char tmpchar = 0;
int tmpn2 = 0;
int ret = 0;

//Argument checks

//Initializations

//Main logic

//Create a file object to the LLDP
//driver.
tmphnd = CreateFileA("\\\\.\\LLDPCTRL", \
GENERIC_READ, \
FILE_SHARE_READ, \
NULL, \
OPEN_EXISTING, \
FILE_ATTRIBUTE_READONLY, \
NULL);
if(tmphnd == INVALID_HANDLE_VALUE){
printf("\nError: Could not open device.\n");
goto _lblfreeandexit;
}

//Allocate memory to tmpn.
tmpn = (int*)calloc(2, sizeof(int));
if(tmpn == NULL){
printf("\nError: Could not allocate memory to tmpn.\n");
goto _lblfreeandexit;
}

//Initialize tmpn to zero.
*tmpn = 0;

//Allocate memory to the buffer that
//will store the data from the LLDP
//driver.
tmpvoid = (void*)calloc(513, sizeof(char));
if(tmpvoid == NULL){
printf("\nError: Could not allocate memory to the buffer.\n");
goto _lblfreeandexit;
}

//Prepare variables.
tmpstr = (char*)tmpvoid;

//Create a new thread.
tmpthrd = CreateThread(NULL, \
0, \
MainTimer, \
tmpn,
0, \
NULL);
if(tmpthrd == NULL){
printf("\nError: Could not create the thread.\n");
goto _lblfreeandexit;
}

//Loop while tmpn is zero.
while(*tmpn == 0){

//Read from the LLDP driver.
ret = ReadFile(tmphnd, \
tmpvoid, \
513, \
&tmpn2, \
NULL);

//Show the data read.

//Get the third byte from the data.
tmpchar = tmpstr[2];

//Check if it is a MAC address subtype.
if(tmpchar == '\x04'){

//Display the MAC address located at
//the fourth byte.

//Append a NULL character at the
//fifteenth byte.
tmpstr[14] = '\0';

//Show the MAC address.
printf("%s\n", (tmpstr + 3));

} //EndIf

} //End while loop

_lblfreeandexit:

//Close the handles.
if(tmphnd != NULL){
CloseHandle(tmphnd);
}
if(tmpthrd != NULL){
CloseHandle(tmpthrd);
}

//Free variables
if(tmpvoid != NULL){
free(tmpvoid);
}
if(tmpn != NULL){
free(tmpn);
}

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top