LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 03-25-2012, 01:56 PM   #1
karan2386
Member
 
Registered: Jan 2012
Posts: 34

Rep: Reputation: Disabled
write on /proc entry through user space


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
 
Old 03-26-2012, 08:38 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
If this is SOLVED as you marked it can you provide your solution? It will help others who find this later.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kernel module - write to user space mrshanim Linux - Kernel 5 12-31-2010 11:25 AM
[SOLVED] How do you write to a proc file from a user program? beaglebird Programming 3 11-02-2009 01:13 AM
command to write into proc entry pravin.embedded Linux - Newbie 1 09-11-2008 08:03 AM
maximum size of entry in /proc linuxdoniv Programming 3 04-01-2008 03:41 PM
Retrieve write protect state of USB device in user space GeertPh Linux - Software 0 10-03-2006 01:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 05:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration