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

  • SEARCH
  • Home
  • 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 7693199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:01:45+00:00 2026-05-31T21:01:45+00:00

I am writing to /proc/tx_info through user space by following programme: int main() {

  • 0

I am writing to /proc/tx_info through user space by following programme:

int main()
{
char *prot;
char addr[14];
FILE *fp;
int i = 0; 
prot = (char *)malloc(sizeof(char *));
//addr = (char *)malloc(sizeof(char *));
printf("\n enter the protocol for test\n");
scanf(" %s",prot);
printf("\n enter the addr::");
scanf(" %s",addr);

fp =fopen("/proc/tx_info","w");
if(fp == NULL)
{
printf("\n unable to write on /proc/tx_info \n");
}
fprintf(fp,"%s ",prot);
while(addr[i] != '\0')
{
fprintf(fp,"%c",addr[i]);
i++;
}
fclose(fp);

and have a proc read and write programme as follows

char tx_buffer[100];
char tx_buffer[100];
static int proc_max_size = 100;
static unsigned long buffer_size =0;


int proc_read(char *buffer,char **buffer_location,off_t offset,int buffer_length,int *eof,void *data)
{
int ret;
if(offset>0)
  {
    ret=0;
   } else {
  memcpy(buffer,tx_buffer,buffer_size);
    ret = buffer_size;
   }

            return ret;
}

int proc_write(struct file *filp, const char *buffer, unsigned long count, void *data)
{

    if(count > proc_max_size)
          count = proc_max_size;
    if(copy_from_user(tx_buffer,buffer,count))
            return -EFAULT;
//      tx_buffer[count] = '\0';
     buffer_size = count;
    return count;
}

my i/p to prog was tcp 192.137.190.187
and i do cat /proc/tx_info gives me following o/p:

tcp 192.137.190.18�

why last digit of ip address is not printing

  • 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-05-31T21:01:47+00:00Added an answer on May 31, 2026 at 9:01 pm

    You’re only allocating 14 characters to your address array. You need potentially 15 plus the null terminator, so you should allocate 16 characters.

    In other words, you’re writing past the end if the array and it’s being clobbered before you print. You’re invoking undefined behavior by writing past the end of the array.

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

Sidebar

Related Questions

I am trying to loop through every process in a /proc utility I'm writing
I'm writing a stored proc in SQL Server 2008. The following code: SELECT @LastAccessed
I am writing a proc to create a header in an output file. Currently
I copy and paste code from this URL for creating and reading/writing a proc
Writing the code for the user authentication portion of a web site (including account
I am writing a SQL Stored Proc which takes in a single table valued
I'm currently writing a simple multicaster module. Only one process can open a proc
I'm writing a Ruby 1.9 C extension and I want to do the following
I'm writing this application that will allow a user to define custom quizzes and
I am writing a proc. The proc counts the occurrences of certain activities in

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.