in src/main/c/Posix/PosixHelperFunctions.c [971:1064]
void searchForComPorts(serialPortVector* comPorts)
{
// Open the Solaris callout dev directory
DIR *directoryIterator = opendir("/dev/cua/");
if (directoryIterator)
{
// Read all files in the current directory
struct dirent *directoryEntry = readdir(directoryIterator);
while (directoryEntry)
{
// See if the file names a potential serial port
if ((strlen(directoryEntry->d_name) >= 1) && (directoryEntry->d_name[0] != '.'))
{
// Determine system name of port
char* systemName = (char*)malloc(256);
strcpy(systemName, "/dev/cua/");
strcat(systemName, directoryEntry->d_name);
// Check if port is already enumerated
serialPort *port = fetchPort(comPorts, systemName);
if (port)
port->enumerated = 1;
else
{
// Set static friendly name
char* friendlyName = (char*)malloc(256);
strcpy(friendlyName, "Serial Port");
// Add the port to the list if it is not a directory
struct stat fileStats;
stat(systemName, &fileStats);
if (!S_ISDIR(fileStats.st_mode))
pushBack(comPorts, systemName, friendlyName, friendlyName, "0-0", "Unknown", "Unknown", "Unknown", -1, -1, S_ISLNK(fileStats.st_mode));
// Clean up memory
free(friendlyName);
}
// Clean up memory
free(systemName);
}
directoryEntry = readdir(directoryIterator);
}
// Close the directory
closedir(directoryIterator);
}
// Open the Solaris dial-in dev directory
directoryIterator = opendir("/dev/term/");
if (directoryIterator)
{
// Read all files in the current directory
struct dirent *directoryEntry = readdir(directoryIterator);
while (directoryEntry)
{
// See if the file names a potential serial port
if ((strlen(directoryEntry->d_name) >= 1) && (directoryEntry->d_name[0] != '.'))
{
// Determine system name of port
char* systemName = (char*)malloc(256);
strcpy(systemName, "/dev/term/");
strcat(systemName, directoryEntry->d_name);
// Check if port is already enumerated
serialPort *port = fetchPort(comPorts, systemName);
if (port)
port->enumerated = 1;
else
{
// Set static friendly name
char* friendlyName = (char*)malloc(256);
strcpy(friendlyName, "Serial Port (Dial-In)");
// Add the port to the list if the file is not a directory
struct stat fileStats;
stat(systemName, &fileStats);
if (!S_ISDIR(fileStats.st_mode))
pushBack(comPorts, systemName, friendlyName, friendlyName, "0-0", "Unknown", "Unknown", "Unknown", -1, -1, S_ISLNK(fileStats.st_mode));
// Clean up memory
free(friendlyName);
}
// Clean up memory
free(systemName);
}
directoryEntry = readdir(directoryIterator);
}
// Close the directory
closedir(directoryIterator);
}
}