I am trying to use some old devices called sensinodes . There are a couple of pieces of software needed for this, contiki, sdcc and the some nano_usb_programmer
I'm working from these instruction and I can't seem to make the nano_usb_programmer on ubuntu 16.04 LTS as this pretty old now and things have moved on.
https://github.com/avian2/contiki
When making the nano element I get the error *Edited
In file included from main.c:17:0:
opts.h:25:2: error: redefinition of typedef ‘mode_t’ with different type
}mode_t;
^
In file included from /usr/include/stdlib.h:314:0,
from main.c:10:
/usr/include/x86_64-linux-gnu/sys/types.h:70:18: note: previous declaration of ‘mode_t’ was here
typedef __mode_t mode_t;
^
main.c: In function ‘main’:
main.c:57:6: warning: implicit declaration of function ‘opts_parse’ [-Wimplicit-function-declaration]
if (opts_parse(argc, argv) < 0)
^
main.c:77:4: warning: implicit declaration of function ‘prog_scan’ [-Wimplicit-function-declaration]
prog_scan();
^
main.c:178:7: warning: implicit declaration of function ‘hexfile_out’ [-Wimplicit-function-declaration]
hexfile_out(line_data, 0x04, 0, ptr, 2);
^
main.c:220:15: warning: implicit declaration of function ‘hexfile_build_tables’ [-Wimplicit-function-declaration]
if((rval = hexfile_build_tables(opts.filename, page_buffer, page_table)) == -1)
^
main.c:231:4: warning: implicit declaration of function ‘hexfile_program’ [-Wimplicit-function-declaration]
hexfile_program(page_buffer, page_table);
^
Makefile:25: recipe for target 'main.o' failed
make: *** [main.o] Error 1
It is pointing to line 25 the following file, my c knowledge just isn't any where near good enough to fix this. Any help would be great.
/*
* opts.h
*
* Created on: Dec 21, 2009
* Author: martti
*/
#ifndef OPTS_H_
#define OPTS_H_
#include "cdi.h"
typedef enum
{
USAGE,
VERSION,
SCAN,
WRITE,
WRITE_FAST,
READ,
WRITE_MAC,
READ_MAC,
LOCK,
ERASE
}mode_t;
typedef struct opts_t
{
int port;
chip_t chip;
mode_t mode;
uint8_t write_mac[8];
ramcode_t code_in_ram;
char *filename;
}opts_t;
extern opts_t opts;
#endif /* OPTS_H_ */
Related
I'm trying to write a test program using windows.h. I have a simple main function with a function in it and doesn't work when I compile it:
#include <windows.h>
#include <stdio.h>
int main(){
COORD coords;
SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, &coords);
return 0;
}
But when I compile it using "mingw32-gcc main.c" i get:
main.c: In function 'main':
main.c:107:5: warning: implicit declaration of function 'SetConsoleDisplayMode' [-Wimplicit-function-declaration]
SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, &coords);
^~~~~~~~~~~~~~~~~~~~~
main.c:107:60: error: 'CONSOLE_FULLSCREEN_MODE' undeclared (first use in this function)
SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, &coords);
^~~~~~~~~~~~~~~~~~~~~~~
main.c:107:60: note: each undeclared identifier is reported only once for each function
(It says it's in line 107 because I wrote additional functions that does not need windows.h and don't cause trouble as I don't use them, also they are commented)
I am trying to port some patches to linux-4.4 kernel and I am facing following error ./arch/arm64/include/asm/processor.h:159:40: error: implicit declaration of function ‘task_stack_page’ [-Werror=implicit-function-declaration]. Could you give me any pointer on this as to where the issue comes from?
In file included from ./arch/arm64/include/asm/debug-monitors.h:25:0,
from ./arch/arm64/include/asm/bug.h:21,
from include/linux/bug.h:4,
from include/linux/thread_info.h:11,
from include/asm-generic/preempt.h:4,
from arch/arm64/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:60,
from include/linux/spinlock.h:50,
from include/linux/seqlock.h:35,
from include/linux/time.h:5,
from include/uapi/linux/timex.h:56,
from include/linux/timex.h:56,
from include/linux/sched.h:19,
from arch/arm64/kernel/asm-offsets.c:21:
./arch/arm64/include/asm/compat.h: In function ‘arch_compat_alloc_user_space’:
./arch/arm64/include/asm/processor.h:159:40: error: implicit declaration of function ‘task_stack_page’ [-Werror=implicit-function-declaration]
((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)
^
./arch/arm64/include/asm/ptrace.h:137:5: note: in definition of macro ‘compat_user_mode’
(((regs)->pstate & (PSR_MODE32_BIT | PSR_MODE_MASK)) == \
^
./arch/arm64/include/asm/compat.h:236:38: note: in expansion of macro ‘user_stack_pointer’
#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
^
./arch/arm64/include/asm/compat.h:236:57: note: in expansion of macro ‘task_pt_regs’
#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
^
./arch/arm64/include/asm/compat.h:240:24: note: in expansion of macro ‘compat_user_stack_pointer’
return (void __user *)compat_user_stack_pointer() - len;
^
./arch/arm64/include/asm/processor.h:159:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)
^
./arch/arm64/include/asm/ptrace.h:137:5: note: in definition of macro ‘compat_user_mode’
(((regs)->pstate & (PSR_MODE32_BIT | PSR_MODE_MASK)) == \
^
./arch/arm64/include/asm/compat.h:236:38: note: in expansion of macro ‘user_stack_pointer’
#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
^
./arch/arm64/include/asm/compat.h:236:57: note: in expansion of macro ‘task_pt_regs’
#define compat_user_stack_pointer() (user_stack_pointer(task_pt_regs(current)))
^
./arch/arm64/include/asm/compat.h:240:24: note: in expansion of macro ‘compat_user_stack_pointer’
return (void __user *)compat_user_stack_pointer() - len;
^
./arch/arm64/include/asm/processor.h:159:3: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)
^
I have checked the code and made sure that proper header files are included. Is there any gcc debug options to find where the error is coming from? I wonder why there is no tool (I might be wrong) to debug such compilation errors so that we can easily find the cause of errors
i have next simple code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include "hiredis.h"
#include "async.h"
#include "adapters/libevent.h"
void onMessage(redisAsyncContext *c, void *reply, void *privdata) {
redisReply *r = reply;
if (reply == NULL) return;
int j;
if (r->type == REDIS_REPLY_ARRAY) {
for (j = 0; j < r->elements; j++) {
printf("%u) %s\n", j, r->element[j]->str);
}
}*/
}
int main (int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
struct event_base *base = event_base_new();
redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
if (c->err) {
printf("error: %s\n", c->errstr);
return 1;
}
redisLibeventAttach(c, base);
redisAsyncCommand(c, onMessage, NULL, "SUBSCRIBE messages");
event_base_dispatch(base);
return 0;
}
program compiles and runs well. but it returns error "Segmentation fault" when executes. if i comment redisAsyncCommand() function error disappears.
where is the error in my code?
added:
when i compile my code i have warnings:
make all
'Building file: ../src/redis.c'
'Invoking: Cross GCC Compiler'
arm-linux-gnueabihf-gcc -I"C:\SysGCC\Raspberry\include" -I"C:\SysGCC\Raspberry\include\hiredis" -I"C:\SysGCC\Raspberry\include\event2" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/redis.d" -MT"src/redis.o" -o "src/redis.o" "../src/redis.c"
In file included from ../src/redis.c:7:0:
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h: In function 'redisLibeventAddRead':
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:56:15: warning: passing argument 1 of 'event_add' from incompatible pointer type
event_add(&e->rev,NULL);
^
In file included from C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:33:0,
from ../src/redis.c:7:
C:\SysGCC\Raspberry\include\event2/event.h:937:5: note: expected 'struct event *' but argument is of type 'struct event **'
int event_add(struct event *ev, const struct timeval *timeout);
^
In file included from ../src/redis.c:7:0:
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h: In function 'redisLibeventDelRead':
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:61:15: warning: passing argument 1 of 'event_del' from incompatible pointer type
event_del(&e->rev);
^
In file included from C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:33:0,
from ../src/redis.c:7:
C:\SysGCC\Raspberry\include\event2/event.h:950:5: note: expected 'struct event *' but argument is of type 'struct event **'
int event_del(struct event *);
^
In file included from ../src/redis.c:7:0:
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h: In function 'redisLibeventAddWrite':
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:66:15: warning: passing argument 1 of 'event_add' from incompatible pointer type
event_add(&e->wev,NULL);
^
In file included from C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:33:0,
from ../src/redis.c:7:
C:\SysGCC\Raspberry\include\event2/event.h:937:5: note: expected 'struct event *' but argument is of type 'struct event **'
int event_add(struct event *ev, const struct timeval *timeout);
^
In file included from ../src/redis.c:7:0:
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h: In function 'redisLibeventDelWrite':
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:71:15: warning: passing argument 1 of 'event_del' from incompatible pointer type
event_del(&e->wev);
^
In file included from C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:33:0,
from ../src/redis.c:7:
C:\SysGCC\Raspberry\include\event2/event.h:950:5: note: expected 'struct event *' but argument is of type 'struct event **'
int event_del(struct event *);
^
In file included from ../src/redis.c:7:0:
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h: In function 'redisLibeventCleanup':
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:76:15: warning: passing argument 1 of 'event_del' from incompatible pointer type
event_del(&e->rev);
^
In file included from C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:33:0,
from ../src/redis.c:7:
C:\SysGCC\Raspberry\include\event2/event.h:950:5: note: expected 'struct event *' but argument is of type 'struct event **'
int event_del(struct event *);
^
In file included from ../src/redis.c:7:0:
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:77:15: warning: passing argument 1 of 'event_del' from incompatible pointer type
event_del(&e->wev);
^
In file included from C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:33:0,
from ../src/redis.c:7:
C:\SysGCC\Raspberry\include\event2/event.h:950:5: note: expected 'struct event *' but argument is of type 'struct event **'
int event_del(struct event *);
^
In file included from ../src/redis.c:7:0:
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h: In function 'redisLibeventAttach':
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:102:5: warning: implicit declaration of function 'event_set' [-Wimplicit-function-declaration]
event_set(&e->rev,c->fd,EV_READ,redisLibeventReadEvent,e);
^
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:104:25: warning: passing argument 2 of 'event_base_set' from incompatible pointer type
event_base_set(base,&e->rev);
^
In file included from C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:33:0,
from ../src/redis.c:7:
C:\SysGCC\Raspberry\include\event2/event.h:627:5: note: expected 'struct event *' but argument is of type 'struct event **'
int event_base_set(struct event_base *, struct event *);
^
In file included from ../src/redis.c:7:0:
C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:105:25: warning: passing argument 2 of 'event_base_set' from incompatible pointer type
event_base_set(base,&e->wev);
^
In file included from C:\SysGCC\Raspberry\include\hiredis/adapters/libevent.h:33:0,
from ../src/redis.c:7:
C:\SysGCC\Raspberry\include\event2/event.h:627:5: note: expected 'struct event *' but argument is of type 'struct event **'
int event_base_set(struct event_base *, struct event *);
^
'Finished building: ../src/redis.c'
' '
'Building target: redis'
'Invoking: Cross GCC Linker'
arm-linux-gnueabihf-gcc -L"C:\SysGCC\Raspberry\arm-linux-gnueabihf\sysroot\usr\local\lib" -L"C:\SysGCC\Raspberry\arm-linux-gnueabihf\lib" -o "redis" ./src/redis.o -lhiredis -levent_core -lpthread
'Finished building target: redis'
' '
00:20:55 Build Finished (took 1s.130ms)
EDIT
It seems the main issue was in the included adapter file.
The issue I pointed towards was unrelated.
Here is just one quick issue I noticed:
if (r->type == REDIS_REPLY_ARRAY) {
for (j = 0; j < r->elements; j++) {
printf("%u) %s\n", j, r->element[j]->str);
}
}
Your code assumes that the reply is an array of Strings.
This is incorrect.
The Subscribe command also returns an Array response and the last member of that response is a NUMBER (not a string).
Hence, the assumption that it's an array of strings will fail.
I'm not sure if that's the cause, but it is likely to be an important issue.
Good Luck!
P.S.
I might be shamelessly promoting my own project here, but you might enjoy using facil.io's integrated Redis Pub/Sub engine. If you need Websocket or HTTP support, it might save you a lot of coding.
I want to pass a string > 1024 chars to my module (filesystem).
As kernel parameters are limited to 1024 chars, someone recommended to use sysfs instead.
I tried to include this example in my super.c class to create a string 'filename' & string 'code' entry in sysfs for my module.
static decl_subsys(myfs, NULL, NULL);
struct myfs_attr {
struct attribute attr;
char *value;
};
static struct myfs_attr fname = {
.attr.name="filename",
.attr.owner = THIS_MODULE,
.attr.mode = 0644,
.value = "/my/test/path",
};
static struct myfs_attr code = {
.attr.name="code",
.attr.owner = THIS_MODULE,
.attr.mode = 0644,
.value = "0101",
};
When compiling my module I get a lot of errors (line 41 is decl_subsys):
fs/myfs/super.c:41:26: error: expected ‘)’ before ‘(’ token
fs/myfs/super.c:50:2: error: unknown field ‘owner’ specified in initializer
fs/myfs/super.c:50:2: warning: initialization from incompatible pointer type [enabled by default]
fs/myfs/super.c:50:2: warning: (near initialization for ‘fname.attr.name’) [enabled by default]
...
fs/myfs/super.c: At top level:
fs/myfs/super.c:83:15: error: variable ‘myfsops’ has initializer but incomplete type
fs/myfs/super.c:84:2: error: unknown field ‘show’ specified in initializer
fs/myfs/super.c:84:2: warning: excess elements in struct initializer [enabled by default]
fs/myfs/super.c:84:2: warning: (near initialization for ‘myfsops’) [enabled by default]
fs/myfs/super.c:85:2: error: unknown field ‘store’ specified in initializer
fs/myfs/super.c:85:2: warning: excess elements in struct initializer [enabled by default]
fs/myfs/super.c:85:2: warning: (near initialization for ‘myfsops’) [enabled by default]
fs/myfs/super.c:89:2: error: unknown field ‘myfs_ops’ specified in initializer
fs/myfs/super.c:89:2: warning: initialization from incompatible pointer type [enabled by default]
fs/myfs/super.c:89:2: warning: (near initialization for ‘myfstype.release’) [enabled by default]
fs/myfs/super.c: In function ‘init_myfs_fs’:
fs/myfs/super.c:1554:2: error: implicit declaration of function ‘kobj_set_kset_s’ [-Werror=implicit-function-declaration]
fs/myfs/super.c:1554:19: error: ‘myfs_subsys’ undeclared (first use in this function)
fs/myfs/super.c:1554:19: note: each undeclared identifier is reported only once for each function it appears in
fs/myfs/super.c:1554:32: error: ‘fs_subsys’ undeclared (first use in this function)
fs/myfs/super.c:1557:2: error: implicit declaration of function ‘subsystem_register’ [-Werror=implicit-function-declaration]
fs/myfs/super.c: In function ‘exit_myfs_fs’:
fs/myfs/super.c:1579:2: error: implicit declaration of function ‘subsystem_unregister’ [-Werror=implicit-function-declaration]
fs/myfs/super.c:1579:24: error: ‘myfs_subsys’ undeclared (first use in this function)
Is this tutorial just outdated for my 3.5 kernel or am I missing something else?
How could I create 2 char string entries for my module in sysfs?
Here is the source code for transmitting data to a "param_buf" string. As requested, without read method. Only store.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <asm/string.h>
static struct kobject *register_kobj;
static char *param_buf;
// function for many symbol data enter
static ssize_t __used store_value(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count){
printk(KERN_ALERT "you entered %s\n", buf);
strncpy(param_buf, buf, PAGE_SIZE - 1);
return count;
}
// register function to attribute
static struct kobj_attribute store_val_attribute = __ATTR( put_parameters, 0220, NULL, store_value);
// put attribute to attribute group
static struct attribute *register_attrs[] = {
&store_val_attribute.attr,
NULL, /* NULL terminate the list*/
};
static struct attribute_group reg_attr_group = {
.attrs = register_attrs
};
static int hello_init(void){
param_buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
// create sysfs object ( /sys/kernel/test_1025_sym directory )
register_kobj = kobject_create_and_add("test_1025_sym", kernel_kobj);
if (!register_kobj)
return -ENOMEM;
//create attributes (files)
if(sysfs_create_group(register_kobj, ®_attr_group)){
kobject_put(register_kobj);
return -ENOMEM;
}
return 0;
}
static void hello_exit(void){
printk(KERN_ALERT "last value was %s\n", param_buf);
kfree(param_buf);
kobject_put(register_kobj);
}
MODULE_LICENSE("Dual BSD/GPL");
module_init(hello_init);
module_exit(hello_exit);
You can test it in such a way:
cat /etc/fstab > /sys/kernel/test_1025_sym/put_parameters
For two string entries: copy a store_value function, register one more store_val_attribute and put it to attributes list.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Following this article, I am trying to get a C program to compile that uses TPC_REPAIR.
http://oroboro.com/dealing-with-network-port-abuse-in-sockets-in-c/
TCP_REPAIR is defined in
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h
Including this header conflicts with the ones required for other socket APIs.
Here's my code
#include <stdio.h>
#include <unistd.h>
#include <linux/socket.h>
#include <uapi/linux/in.h>
#include <netinet/tcp.h>
#include "/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h"
int main(int argc, char* argv[])
{
int cfd;
struct sockaddr_in addr;
char ch='r';
cfd=socket(AF_INET, SOCK_STREAM, 0);
addr.sin_family=AF_INET;
addr.sin_addr.s_addr=inet_addr("10.160.102.40");
addr.sin_port=htons(9988);
if(connect(cfd, (struct sockaddr *)&addr,
sizeof(addr))<0) {
perror("connect error");
return -1;
}
if(write(cfd, &ch, 1)<0) perror("write");
if(read(cfd, &ch, 1)<0) perror("read");
printf("\nReply from Server: %c\n",ch);
//close(cfd);
int aux = 1;
if(setsockopt(cfd, SOL_TCP, TCP_REPAIR, &aux, sizeof( aux )) < 0 )
{
perror( "could not turn on repair mode" );
}
return 0;
}
And here's gcc output
In file included from /usr/include/netinet/tcp.h:56:0,
from new_client.c:5:
/usr/include/x86_64-linux-gnu/sys/types.h:45:18: error: conflicting types for ‘loff_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:45:26: note: previous declaration of ‘loff_t’ was here
/usr/include/x86_64-linux-gnu/sys/types.h:61:17: error: conflicting types for ‘dev_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:15:25: note: previous declaration of ‘dev_t’ was here
/usr/include/x86_64-linux-gnu/sys/types.h:76:19: error: conflicting types for ‘nlink_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:19:17: note: previous declaration of ‘nlink_t’ was here
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:133:0,
from /usr/include/netinet/tcp.h:56,
from new_client.c:5:
/usr/include/time.h:104:19: error: conflicting types for ‘timer_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:25:26: note: previous declaration of ‘timer_t’ was here
In file included from /usr/include/netinet/tcp.h:56:0,
from new_client.c:5:
/usr/include/x86_64-linux-gnu/sys/types.h:198:1: error: conflicting types for ‘int64_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:113:17: note: previous declaration of ‘int64_t’ was here
/usr/include/x86_64-linux-gnu/sys/types.h:204:1: error: conflicting types for ‘u_int64_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:112:17: note: previous declaration of ‘u_int64_t’ was here
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:220:0,
from /usr/include/netinet/tcp.h:56,
from new_client.c:5:
/usr/include/x86_64-linux-gnu/sys/select.h:76:5: error: conflicting types for ‘fd_set’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:14:26: note: previous declaration of ‘fd_set’ was here
In file included from /usr/include/netinet/tcp.h:56:0,
from new_client.c:5:
/usr/include/x86_64-linux-gnu/sys/types.h:236:20: error: conflicting types for ‘blkcnt_t’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/types.h:134:23: note: previous declaration of ‘blkcnt_t’ was here
In file included from /usr/include/x86_64-linux-gnu/sys/uio.h:29:0,
from /usr/include/x86_64-linux-gnu/sys/socket.h:28,
from /usr/include/netinet/tcp.h:57,
from new_client.c:5:
/usr/include/x86_64-linux-gnu/bits/uio.h:44:8: error: redefinition of ‘struct iovec’
/usr/src/linux-headers-3.8.0-29-generic/include/uapi/linux/uio.h:16:8: note: originally defined here
In file included from /usr/include/x86_64-linux-gnu/sys/socket.h:40:0,
from /usr/include/netinet/tcp.h:57,
from new_client.c:5:
/usr/include/x86_64-linux-gnu/bits/socket.h:180:8: error: redefinition of ‘struct sockaddr’
/usr/src/linux-headers-3.8.0-29-generic/include/uapi/linux/socket.h:19:27: note: originally defined here
/usr/include/x86_64-linux-gnu/bits/socket.h:193:8: error: redefinition of ‘struct __kernel_sockaddr_storage’
/usr/src/linux-headers-3.8.0-29-generic/include/uapi/linux/socket.h:13:8: note: originally defined here
/usr/include/x86_64-linux-gnu/bits/socket.h:204:5: error: expected identifier before numeric constant
/usr/include/x86_64-linux-gnu/bits/socket.h:253:8: error: redefinition of ‘struct msghdr’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/socket.h:47:8: note: originally defined here
/usr/include/x86_64-linux-gnu/bits/socket.h:280:8: error: redefinition of ‘struct cmsghdr’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/socket.h:69:8: note: originally defined here
/usr/include/x86_64-linux-gnu/bits/socket.h:310:24: error: conflicting types for ‘__cmsg_nxthdr’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/socket.h:111:32: note: previous definition of ‘__cmsg_nxthdr’ was here
/usr/include/x86_64-linux-gnu/bits/socket.h:339:5: error: expected identifier before numeric constant
In file included from /usr/include/x86_64-linux-gnu/sys/socket.h:40:0,
from /usr/include/netinet/tcp.h:57,
from new_client.c:5:
/usr/include/x86_64-linux-gnu/bits/socket.h:417:8: error: redefinition of ‘struct linger’
/usr/src/linux-headers-3.8.0-29-generic/include/linux/socket.h:34:8: note: originally defined here
In file included from new_client.c:6:0:
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:24:8: error: redefinition of ‘struct tcphdr’
/usr/include/netinet/tcp.h:92:8: note: originally defined here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:135:6: error: nested redefinition of ‘enum tcp_ca_state’
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:135:6: error: redeclaration of ‘enum tcp_ca_state’
/usr/include/netinet/tcp.h:179:6: note: originally defined here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:136:2: error: redeclaration of enumerator ‘TCP_CA_Open’
/usr/include/netinet/tcp.h:181:3: note: previous definition of ‘TCP_CA_Open’ was here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:138:2: error: redeclaration of enumerator ‘TCP_CA_Disorder’
/usr/include/netinet/tcp.h:182:3: note: previous definition of ‘TCP_CA_Disorder’ was here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:140:2: error: redeclaration of enumerator ‘TCP_CA_CWR’
/usr/include/netinet/tcp.h:183:3: note: previous definition of ‘TCP_CA_CWR’ was here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:142:2: error: redeclaration of enumerator ‘TCP_CA_Recovery’
/usr/include/netinet/tcp.h:184:3: note: previous definition of ‘TCP_CA_Recovery’ was here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:144:2: error: redeclaration of enumerator ‘TCP_CA_Loss’
/usr/include/netinet/tcp.h:185:3: note: previous definition of ‘TCP_CA_Loss’ was here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:148:8: error: redefinition of ‘struct tcp_info’
/usr/include/netinet/tcp.h:188:8: note: originally defined here
/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h:193:8: error: redefinition of ‘struct tcp_md5sig’
/usr/include/netinet/tcp.h:235:8: note: originally defined here
This is really not useful
#include "/usr/src/linux-headers-3.8.0-29/include/uapi/linux/tcp.h"
Because either the kernel supports it or it does not. You can check for it like this:
find /usr/include -type f -exec grep TCP_REPAIR {} /dev/null \;
/usr/include/linux/tcp.h:#define TCP_REPAIR 19 /* TCP sock is under repair right now */
/usr/include/linux/tcp.h:#define TCP_REPAIR_QUEUE 20
/usr/include/linux/tcp.h:#define TCP_REPAIR_OPTIONS 22
if it's there, great, otherwise you'll have to use the workaround.
Here's an Ubuntu that has it
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.10
Release: 12.10
Codename: quantal
It looks like SOL_TCP is only defined in /usr/include/netinet/tcp.h
find /usr/include -type f -exec grep SOL_TCP {} /dev/null \;
/usr/include/netinet/tcp.h:# define SOL_TCP 6 /* TCP level */
To overcome the unfortunate absence of SOL_TCP in /usr/include/linux/tcp.h. You can try to simply copy it from netinet/tcp.h, it's just a number after all.
#ifndef SOL_TCP
#define SOL_TCP 6
#endif
However, the man page of setsockopt offers an even better approach:
To manipulate options at any other level the protocol number of the appropriate protocol controlling the option is supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, level should be set to the protocol number of TCP; see getprotoent(3).