2018-06-30         Matt

Passing IP in string to htonl

I am binding to socket in a kernel module. I get the IP in string format from another socket. How should I pass this IP to htonl(). I tried typecasting it to (long int). But, obviously it won't work.How to achieve this? unsigned int inet_addr(char *str){ int a, b, c, d; char arr[4]; sscanf(str, "%d.%d.%d.%d", &a, &b, &c, &d); arr[0] = a; arr[1] = b; arr[2] = c; arr[3] = d; return *(unsigned int *)arr;}//use it as follows://inet_addr() returns address in Network Byte Order, so no need of htonl()thesockaddr_in.sin_addr.s_addr = inet_addr(str)...

 c                     3 answers                     1 view
 2018-06-30         Louise

Reading simple structures from a binary file and displaying specific data on the screen in c

I'm a newbie to programming and I am coding my first project. Part of my project requires asking the user for day, month and year; writing the note in the file and then displaying the corresponding note to the month and year on the screen. Here is my structure for notes:typedef struct event{ int day; int month; int year; char title[20]; char text[400];} Note;and here is the part related to the input:Note tempNote;FILE *fptr;fptr = fopen("note.bin","wb");if(fptr==NULL){ printf("\n\n\t\tError\nCan not open the file"); exit(1);}printf("\n\n\t\tAdd title:\n...

 c                     1 answers                     93 view
 2018-06-30         Odelette

Improve INSERT-per-second performance of SQLite?

Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second!Background: We are using SQLite as part of a desktop application. We have large amounts of configuration data stored in XML files that are parsed and loaded into an SQLite database for further processing when the application is initialized. SQLite is ideal for this situation because it's fast, it requires no specialized configuration, and the database is stored on disk as a single file.Rationale: Initially I was disappointed with the ...

 c                     10 answers                     24 view
 2018-06-30         Werner

Getting a list of mounted file systems in a kernel module?

I'm trying to get a path to the mountpoint of a specific filesystem in a kernel module. In a user-space tool, I could read /proc/mount to do this, but from what I've tried and read, that's not possible in kernel space.How can I achieve this in a kernel module? You are able to get this from /dev/ directory also you just have to use grep and sed at that place for find correct mounting point. [XXX]

 c                     1 answers                     27 view
 2018-06-30         Osborn

Keep Netlink Socket open on kernel and User side

After I read some articles on netlink sockets, I tried to adopt this answer here Netlink SO.I added an endless loop to the userspace program:while (1) { memset(nlh, 0, NLMSG_SPACE(MAX_PAYLOAD)); iov.iov_base = (void *)nlh; iov.iov_len = NLMSG_SPACE(MAX_PAYLOAD); msg.msg_name = (void *)&dest_addr; msg.msg_namelen = sizeof(dest_addr); msg.msg_iov = &iov; msg.msg_iovlen = 1; ret = recvmsg(sock_fd, &msg, 0); if (ret == 0) { printf("Exit.\n"); exit(0); } else if (ret == -1) { perror("recvmsg:"); exit(1); } printf("%s", NLMSG_DATA(nlh));}To ge...

 c                     1 answers                     25 view
 2018-06-30         Maggie

system calls undefined! Compiling kernel module

I am new to kernel module programming, and trying to create raw socket in my kernel module using 'sys_socket'. I am binding this socket to an interface using 'sys_bind' and 'sys_ioctl' (for fetching interface number).While compiling my module, I get the following errors:make -C /lib/modules/3.13.0-68-generic/build M=/root/Kernel_Module modulesmake[1]: Entering directory `/usr/src/linux-headers-3.13.0-68-generic'CC [M] /root/Kernel_Module/kernel_module.oBuilding modules, stage 2.MODPOST 1 modulesWARNING: "sys_ioctl" [/root/Kernel_Module/kernel_module.ko] undefined!WARNING: ...

 c                     1 answers                     28 view
 2018-06-30         Lynn

Linear Search function compiles but no output

I do not understand what is wrong with this code of Linear search. It compiles but on execution exits without output.turns - no. of test cases.size - size of array.x - element to be searched.#include <stdio.h>int linearSearch(int arr[], int size, int element){ int i = 0; for(i=0; i< size; i++) { if(arr[i] == element) { return i; } } return 0;}int main(){ int turns, size; scanf("%d", &turns); while(turns--) { scanf("%d", &size); int arr[size]; for(int j=0; j < size; j++) ...

 c                     1 answers                     33 view
 2018-06-30         Prudence

Difference b/w getting an address of variable using %p and %d

Here is an example#include <stdio.h>int main(){ int a; printf("%d\n",&a); printf("%p\n",&a); return 0;}======Output======= -2054871028 0x7ffd8585280c Do these two address point to same address in RAM ? And how can i get the value by using each one of them, especially the second one. %d format specifier is used to output a signed decimal integer.From C Standard#7.21.6.1p8 d,i The int argument is converted to signed decimal i...

 c                     1 answers                     34 view
 2018-06-30         Bowen

Reading strings between ";" in a .txt file in C

I have to read data from a .txt file and put them inside a B-tree. The problem is: I am having trouble to read the data from the file. Each data between the ";" must be stored in a different variable, so that I can show it when the user. The idiom is Portuguese but I hope you can understand it.UPDATE - The code so far:#include <stdio.h>#include <stdlib.h>#include <strings.h>struct veiculos{ int lote; char placa[50]; char uf[10]; char motor[50]; int renavam; char chassi[100]; int ano; char marca[100]; char proprietario[100]; ch...

 c                     4 answers                     33 view
 2018-06-30         Kevin

Is there a way to modify Linux syscall table in a proprietary kernel module?

I wrote an kind of SELinux clone that supervises system call execution such as open and execve.The result is proven by SELinux as a secure way to monitor all disk access made by users.The code modifies the syscall table in the following way: Change the name->address relationship of a syscall After the change, the syscall name is my own function, which then calls the original syscall. the original syscall address is protected by address space layout randomization which requires scanning 16 exabytes of data, and the address changes with every reboot. Old trick, but the...

 c                     1 answers                     37 view
 2018-06-30         Isaac

LKM Implicit declaration of function stat

I am currently writing a Linux Kernel Module (for the first time).I am trying to use the stat function. I understand that regular imports are not going to work in Kernel code, so I imported their equivalent (that is what I thought...):#include <linux/stat.h>#include <linux/errno.h>#include <linux/unistd.h>I don't get any error about the imports directly, but I get the following messages:error: implicit declaration of function ‘stat’ [-Werror=implicit-function-declaration]error: ‘errno’ undeclared (first use in this function)For the two lines respectively:i...

 c                     1 answers                     37 view
 2018-06-30         Ella

sleeping during an execlp call to avoid output 'lag'? is it possible?

Currently i'm screwin around with a shell that i'm developing for Linux in C, and somebody recently pointed me towards execlp to execute separate programs from within my shell. The example i have implemented in the shell currently is very simple, execute the shell, run the 'date' command, and execlp launches 'date', which, simply enough, prints the date to the terminal. the problem in this case, is although the date program executes successfully and prints to the terminal, it prints right after the shell prompt. I'm guessing execlp returns the date just a hair too late, cau...

 c                     1 answers                     30 view
 2018-06-30         Max

Where are Lua's "global" local values stored?

I need to call a Lua function from C and as long the function is global I can find it in the global table, but if it is declared local, how can I push the address on the stack to call it?function MyGlobal() print("Global")endlocal function MyLocalGlobal() print("Local")endCalling MyGlobal() from C isn't a problem it works fine. I lookup the function in the global table.But how do I call MyLocalGlobal() from C? It isn't in the global table, but where is it and how can I push the address?I'm using Lua 5.3.4. The MyLocalGlobal() function isn't really global. It's local to...

 c                     1 answers                     67 view
 2018-06-30         Irene

Sum of the odd digits and even digits from the input and compare them. If both are equal print stat1 else stat2

This is the code, this code is not working. For loop needs to be used for this program. I need help to make this work. Program prints same statement for different numbers. Kindly debug this and help me to understand the concept.#include<stdio.h>int main(){ int n,i,sum=0,sum1=0,rem; printf("enter values\n"); scanf("%d",&n); for(i=n;i<=n;) { rem=n%10; if(rem%2 == 0) { sum=sum+rem; } else { sum1=sum1+rem; } n=n/10; }if(sum==sum1) printf("I will win the Card Game");else ...

 c                     3 answers                     0 view

Page 2144 of 2144  |  Show More Pages:  Top Prev Next Last