Any one has an idea how to develop Header of GPRS tunneling protocol using C language or even has interest in something like that
I am a professional C/C++ programmers living in jordan

/*
*Name : Omar Adnan Isaid
*ID : 200530158
*Course : Wireless & Distributed Computing
*Semester 1
*The following represent a part of the solution of second HW
*I wrote the program in C language once it is called Platform 
*programming language using 
*MS-visual studio 2005 Development edition as IDE
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef unsigned int  _flag_Unit; 
/*I defined flags as integer since At read from system module
I need to use for comparison*/
void read_From_File();
void system_Start();
void read_From_System();

struct GTP_Header
{//Size of GTP fields not defined presicely at the struct of the header.
//Since,in fprintf/fscanf I defined the number of units to be write/read 
	_flag_Unit _NPDU_Flag;
	_flag_Unit _SN_Flag;
	_flag_Unit _Extension_Header_Flag;
    unsigned :1;//padding that represents the spare bits
    unsigned _PT;
    unsigned _Version;
	unsigned _MessageType;
    unsigned  _length;
    unsigned _Sequence_Number;
    unsigned FlowLabel;
	unsigned N_PDU_No;
	////following data members belongs of extension headerfields  
	//that their reside depends on the state of"_Extension_Header_Flag" 
	//as field in the struct
	unsigned :24;//padding that represent the spare bits
    unsigned _MCC;
    unsigned _MNC;
    unsigned _MSIN;
	unsigned _NSAPI;
}GTP_P;
void read_From_File()
{
	FILE *file_To_Load_From;
	FILE *file_To_Store_IN;
	char _field_Name[30];
	int field_Value;
	
	
    file_To_Load_From=fopen("hw20799823668IN.txt","r");
	if(file_To_Load_From==NULL)
	{
		printf("Where is your FILE to read from !\n\n");
		
		system_Start();
	}else file_To_Store_IN=fopen("hw20799823668OUT.txt","w");
	//Loading file ready .And So, Let us open or creation storing file
	printf("%s\t%s\n","Field Name","Field Value");
    printf("%s\t%s\n","___________","___________");
    fscanf(file_To_Load_From,"%s%d",_field_Name,&field_Value);
	while(!feof(file_To_Load_From))
	{
		printf("%s\t%d\n", _field_Name, field_Value);
		fprintf(file_To_Store_IN,"%s\t%d\n", _field_Name, field_Value);
		fscanf(file_To_Load_From,"%s%d",_field_Name,&field_Value);
	}
	printf("Congratulation !!!!!\nPrevious Values ,that at your Input files\nstored successfully");
	printf(" at the output file .\n\n");
	fclose(file_To_Load_From);
	fclose(file_To_Store_IN);
    system_Start();
}
void read_From_System()
{
	int _SET=1;
	int _OFF=0;
	bool _IS_SET=true;
    bool _CLEARED=false;
	bool _state_of_NPDU_Flag;
    bool _state_of_SN_Flag;
    bool _state_of_Extension_Header_Flag;
	
    FILE* file_To_Store_IN=fopen("hw20799823668OUT.txt","w");
	printf("Enter the value of \"N-PDU Number Flag\" field\n");
	scanf_s("%1u",&GTP_P._NPDU_Flag );
    fprintf(file_To_Store_IN,"%s\t%1u\n", "NPDU_Flag", GTP_P._NPDU_Flag);
    if (GTP_P._NPDU_Flag==1)
		_state_of_NPDU_Flag=_IS_SET;
	else _state_of_NPDU_Flag=_CLEARED;
	
    printf("Enter the value of \"Sequence Number Flag\" field\n");
	scanf_s("%1u",&GTP_P._SN_Flag);
    fprintf(file_To_Store_IN,"%s\t%1u\n", "Sequence_Num_Flag", GTP_P._NPDU_Flag);
	if (GTP_P._SN_Flag==1)
		_state_of_SN_Flag=_IS_SET;
	else _state_of_SN_Flag=_CLEARED;

    printf("Enter the value of \"Extension Header Flag\" field\n");
    scanf_s("%1u",&GTP_P._Extension_Header_Flag);
	fprintf(file_To_Store_IN,"%s\t%1u\n", "E_H_Flag", GTP_P._Extension_Header_Flag);
	if(GTP_P._Extension_Header_Flag==1)
		_state_of_Extension_Header_Flag =_IS_SET;
	else _state_of_Extension_Header_Flag=_CLEARED;

	printf("Enter the value of \"Protocol type\" field\n");
	scanf_s("%1u",&GTP_P._PT);
	fprintf(file_To_Store_IN,"%s\t%1u\n", "protocol_Type", GTP_P._PT);

	printf("Enter the value of \"Version\" field\n");
    scanf_s("%3u",&GTP_P._Version );
	fprintf(file_To_Store_IN,"%s\t%1u\n", "Version", GTP_P._PT);
	
	printf("Enter the value of \"length\" field\n");
    scanf_s("%8u",&GTP_P._length);
    fprintf(file_To_Store_IN,"%s\t%8u\n", "length", GTP_P._length);
	if(_state_of_SN_Flag ==_IS_SET)
	{
		printf("Enter the value of \"sequence number\" field\n");
        scanf_s("%16u",&GTP_P._Sequence_Number );
		fprintf(file_To_Store_IN,"%s\t%16u\n", "Sequence_Number", GTP_P._Sequence_Number);
	}
	
	printf("Enter the value of \"flow label\" field\n");
    scanf_s("%8u",&GTP_P.FlowLabel);
	fprintf(file_To_Store_IN,"%s\t%8u\n", "FlowLabel", GTP_P.FlowLabel);
    
	if (_state_of_NPDU_Flag == _IS_SET )
    {
		//NPDU_flag indicated the field to be filled or not
		printf("Enter the value of \"N-PDU field\" field\n");
		scanf_s("%8u",&GTP_P.N_PDU_No);
		fprintf(file_To_Store_IN,"%s\t%8u\n", "N_PDU_No", GTP_P.N_PDU_No);
	}
	if(_state_of_Extension_Header_Flag ==_IS_SET )
	{
		//flag indicated the field to be filled or not
		printf("Enter the value of \"MCC\" field\n");
	    scanf_s("%12u",&GTP_P._MCC );
	    fprintf(file_To_Store_IN,"%s\t%12u\n", "MCC", GTP_P._MCC);
        printf("Enter the value of \"MNC\" field\n");
        scanf_s("%8u",&GTP_P._MNC);
		fprintf(file_To_Store_IN,"%s\t%8u\n", "MNC", GTP_P._MNC);
	    printf("Enter the value of \"MSIN\" field\n");
        scanf_s("%36u",&GTP_P._MSIN );
	    fprintf(file_To_Store_IN,"%s\t%36u\n", "MSIN", GTP_P._MSIN);
        printf("Enter the value of \"NAPSI\" field\n");
        scanf_s("%4u",&GTP_P._NSAPI);
		fprintf(file_To_Store_IN,"%s\t%4u\n", "NAPSI", GTP_P._NSAPI);
	}
	printf("Congratulation !!!!!\nYour previous enteries is stored at the output file .\n\n");
    fclose(file_To_Store_IN);
	system_Start();
}
void system_Start()
{
    int _my_Choose_IS;
    int _load_And_Store=1;
	int _read_And_store=2;
	int _exit=3;
	do
	{
		printf("Welcome ! you are at the Main Menue of GTP's header\nPlease Select your choose\n");
		printf("(1) I previously entered Values & I want to store in the output file\n");
        printf("(2) I want to enter NEW Values & I want to store in the output file\n");
        printf("(3) Let me leave please\n");
        scanf_s("%d",&_my_Choose_IS);
		if(_my_Choose_IS==_load_And_Store)
		{
			read_From_File();
		}
		else if(_my_Choose_IS==_read_And_store)
		{
			read_From_System();
		}
		else if(_my_Choose_IS==_exit)
			exit(0);
		else printf("Invalid Input\n");
	}while(true);
}
void main()
{
	system_Start();
}

Edited 7 Years Ago by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

This article has been dead for over six months. Start a new discussion instead.