#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include "rpcclt_openapi.h"
#include "proc_util.h"
{
switch (result)
{
printf("Tech support file created successfully.\n");
break;
printf("Feature not supported on this platform.\n");
break;
printf("Error: Invalid parameter specified.\n");
break;
default:
printf("Error: Failed to create tech support file.\n");
break;
}
return result;
}
char *outfile_name,
int display_max)
{
FILE *fp = NULL;
char line[256];
memset(line, 0, sizeof(line));
fp = fopen(outfile_name, "r");
if (fp == NULL)
{
printf("\nError opening support file: %s\n", outfile_name);
}
while (fgets(line, sizeof(line), fp) != NULL)
{
printf("%s", line);
if (display_max > 1)
{
display_max--;
}
if (display_max == 1)
{
break;
}
}
fclose(fp);
}
int main(int argc, char **argv)
{
int ret = 2;
bool parm_err = false;
int display_max = 100;
char *outfile_name = NULL;
char tmp_buf[100];
uint32_t max_filename_len;
l7proc_crashlog_register();
if (argc > 2)
{
parm_err = true;
}
else if (argc == 2)
{
display_max = atoi(argv[1]);
if (display_max < 0)
{
parm_err = true;
}
}
if (parm_err == true)
{
printf("\nThe specified input parameter value must be 0 or greater.\n");
exit(1);
}
{
printf("\nFailed to initialize RPC to OpEN. Exiting (result = %d).\n", result);
exit(2);
}
{
sleep(1);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Starting Support File API example application");
buf_desc.
pstart = tmp_buf;
buf_desc.
size =
sizeof(tmp_buf);
{
printf("\nNetwork OS version = %s\n", tmp_buf);
}
else
{
printf("\nNetwork OS version retrieve error.\n");
}
{
printf(
"\nOpEN version = %u.%u.%u.%u\n", version.
release, version.
version, version.
maint_level, version.
build_num);
}
else
{
printf("\nOpEN version retrieve error.\n");
}
do
{
{
printf("\nError obtaining maximum file name length.\n");
break;
}
if ((outfile_name = (char *)malloc(max_filename_len + 1)) == NULL)
{
printf("Could not allocate memory.\n");
break;
}
buf_desc.pstart = outfile_name;
buf_desc.size = max_filename_len + 1;
printf("\nCreating Tech Support file (this may take a while)...\n");
if (suppfileCreate(&client_handle, &buf_desc) !=
OPEN_E_NONE)
{
printf("\nFile generation error occurred.\n");
break;
}
if (display_max >= 0)
{
if (display_max == 0)
{
snprintf(tmp_buf, sizeof(tmp_buf), "%s", "all lines");
}
else if (display_max == 1)
{
snprintf(tmp_buf, sizeof(tmp_buf), "%s", "first line");
}
else
{
snprintf(tmp_buf, sizeof(tmp_buf), "first %d lines", display_max);
}
printf("\nDisplaying %s of file %s:\n\n", tmp_buf, outfile_name);
if (suppfileDisplay(&client_handle, outfile_name, display_max) !=
OPEN_E_NONE)
{
printf("\nError displaying support file contents.\n");
break;
}
}
ret = 0;
} while (0);
if (outfile_name != NULL)
{
free(outfile_name);
}
L7PROC_LOGF(L7PROC_LOG_SEVERITY_INFO, 0, "Stopping Support File API example application");
return ret;
}