Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8151861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:31:52+00:00 2026-06-06T15:31:52+00:00

I am using following api to initialize sockfd at client side:(sockfd=3) if ((sockfd =

  • 0

I am using following api to initialize sockfd at client side:(sockfd=3)

              if ((sockfd = socket(p->ai_family, p->ai_socktype,p->ai_protocol))  == -1) {
                    perror("client: socket");
                    continue;
            }

& initializing my TPKT_Buff to {3,0,0,0} value by using function :

            if(Fill_TPKT(PStack,TPKT_Buff) != 0)
  {
   printf("Error while filling TPKT Buffer");
   return 1;
  }printf("tpkt/2_Buff%x %x\n",TPKT_Buff[0],TPKT_Buff[1]);printf("sockfd=%d\n",sockfd);

But, after calling function :

 if(Fill_COTP(PStack,&cotp) != 0)
    {
     printf("Error while filling COTP Structure!");
     return 1;
    }

my socfd & TPKT_Buff values changed to zero TPKT_Buff={0,0,0,0} & sockfd=0 :

printf("sockfd=%d\n",sockfd);
 printf("TPKT/2_Buff=%x %x\n",TPKT_Buff[0],TPKT_Buff[1]);

Definitions of functions Fill_COTP & Fill_TPKT are as follows :

  int Fill_TPKT(FILE *fptr,unsigned char *buf)
  {
   fseek(fptr,14,SEEK_SET);
   fscanf(fptr,"%d",buf+0);

   fseek(fptr,15,SEEK_CUR); 
   fscanf(fptr,"%d",buf+1);

   return 0;
  }

 int Fill_COTP(FILE *fptr, COTP *cotp)
 {
  unsigned short temp;

  fseek(fptr,13,SEEK_CUR);
  fscanf(fptr,"%d",&temp);
  cotp->Destination_Ref[1] = temp;
  cotp->Destination_Ref[0] = temp>>8;
  printf("%x %x\n",cotp->Destination_Ref[0],cotp->Destination_Ref[1]);
  fseek(fptr,13,SEEK_CUR);
  fscanf(fptr,"%d",&temp);
  cotp->Source_Ref[1] = temp;
  cotp->Source_Ref[0] = temp>>8;
  printf("%x %x\n",cotp->Source_Ref[0],cotp->Source_Ref[1]);
  fseek(fptr,14,SEEK_CUR);
  fscanf(fptr,"%d",&temp);
  cotp->Source_Tsap[1] = temp;
  cotp->Source_Tsap[0] = temp>>8;
  printf("%x %x\n",cotp->Source_Tsap[0],cotp->Source_Tsap[1]);
  fseek(fptr,14,SEEK_CUR);
  fscanf(fptr,"%d",&temp);
  cotp->Destination_Tsap[1] = temp;
  cotp->Destination_Tsap[0] = temp>>8;
  printf("%x %x\n",cotp->Destination_Tsap[0],cotp->Destination_Tsap[1]);
  fseek(fptr,17,SEEK_CUR);
  fscanf(fptr,"%d",&(cotp->TPDU_size));
  printf("%x\n",cotp->TPDU_size);
  return 0;
 }

Here PStack is a file pointer.
I am not getting why my sockfd & TPKT_Buff values changing to zero even I am not using these values in my function Fill_COTP();
Please give some suggestion.
Definition of COTP is:

       typedef struct
         {
          unsigned char PDU_type;
          unsigned char Destination_Ref[2];
          unsigned char Source_Ref[2];
          unsigned char Source_Tsap[2];
          unsigned char Destination_Tsap[2];
          unsigned char TPDU_size;
         } COTP;

There is no relation between sockfd & TPKT_Buff.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:31:54+00:00Added an answer on June 6, 2026 at 3:31 pm

    The trouble appears to be in the line:

    fscanf(fptr,"%d",&(cotp->TPDU_size)); 
    

    Your TPCU_size is unsigned char TPDU_size; which is only 1 byte (assuming this to be the size of ‘char’) in size, but you are trying put 4 bytes (assuming that to be the size of ‘int’) into it during fscanf, thereby potentially overwriting the memory around it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following functions: # The epoch used in the datetime API. EPOCH
I am using the following plugin: http://flowplayer.org/tools/scrollable.html and under the sub-heading of Scripting API
I'm trying to simply test my RESTful API with cURL. Using the following invocation:
I am using a com DLL in the following manner: #Region API Function <DllImportAttribute(abc.dll,
The following line of code is causing me an Exception using (new INVU.API.CallContextStore()) {
I'm using chrome devtools network API and the following code but always the alert
Im using the Twitter API to read the Favorites RSS, it generates the following
I am using the Google Maps api. When I take the following URL and
I'm using MySQL API's function mysql_real_escape_string() Based on the documentation, it escapes the following
With a third party API I observed the following. Instead of using, public static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.