MCPcopy Create free account
hub / github.com/PolySync/oscc / construct_interfaces_list

Function construct_interfaces_list

api/src/oscc.c:941–1014  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

939
940
941oscc_result_t construct_interfaces_list( device_names_s * const names_ptr )
942{
943 FILE *file_handler;
944 char buffer[512];
945 oscc_result_t result = OSCC_OK;
946
947 file_handler = fopen( "/proc/net/dev", "r" );
948 if (!file_handler) {
949 perror( "Cannot read: /proc/net/dev" );
950
951 result = OSCC_ERROR;
952 }
953
954 if( result == OSCC_OK && names_ptr == NULL )
955 {
956 result = OSCC_ERROR;
957 }
958
959 int lines = 0;
960
961 if( result == OSCC_OK )
962 {
963 while ( fgets( buffer, sizeof( buffer ), file_handler ) ) {
964 ++lines;
965 }
966
967 names_ptr->name = (char**) malloc(lines * sizeof(char*));
968
969 uint i;
970
971 for ( i = 0; i < lines; i++ )
972 {
973 names_ptr->name[i] = (char*) malloc(IFNAMSIZ * sizeof(char));
974 }
975
976 rewind( file_handler );
977
978 //Consume the first two lines since they are headers
979 fgets( buffer, sizeof( buffer ), file_handler );
980 fgets( buffer, sizeof( buffer ), file_handler );
981 }
982
983 char* socket_name = calloc( IFNAMSIZ, sizeof(char) );
984
985 if( !socket_name )
986 {
987 result = OSCC_ERROR;
988 }
989
990 if( result == OSCC_OK )
991 {
992 uint size = 0;
993
994 while ( size < lines && fgets( buffer, sizeof( buffer ), file_handler ) ) {
995
996 result = get_device_name( buffer, socket_name );
997
998 if( result == OSCC_OK )

Callers 1

oscc_search_canFunction · 0.85

Calls 1

get_device_nameFunction · 0.85

Tested by

no test coverage detected