#ifdef SIOCSHWTSTAMP not found - c

I want to take hardware timestamps on the network card. I found some example code from Solarflare which checks whether the following label is defined:
#ifdef SIOCSHWTSTAMP
struct ifreq ifr;
struct hwtstamp_config hwc;
#else
static_assert(false); // I added this to check whether my system has the label defined
#endif
but the static_assert is getting triggered, so this label is not defined in my system.
I am including these headers:
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
so clearly it's not defined in those.
We installed linux-libc-dev but it doesn't seem to have helped.
Which header should it exist in, so I can check?
My kernel version is 3.10.0-1062.4.1.el7.x86_64 and CentOS 7

In the Linux OS it's defined in the User API kernel headers, i.e. in the
include/uapi/linux/sockios.h for latest v3.10.y kernel as of today.
For newer kernel it's still there.
The necessary structure and enumeration values are defined in include/uapi/linux/net_tstamp.h.

Related

Identifying kernel space in the preprocessor?

I'm writing the header of a kernel module. The header is known to the module, but also used by callers in user space. This is a problem, because some types used should be included from different files depending on whether the header is currently in user or kernel space (or so this question makes me think).
I don't want to maintain two separate header files, so I've been thinking of a solution like this:
#ifndef IN_KERNEL
#include <stdint.h>
#else
#include <linux/types.h>
With IN_KERNEL being defined somewhere in my kernel code. Is there a preprocessor constant that already does this?
From reading this, it seems that an existing constant used for this purpose is __KERNEL__.
#ifndef __KERNEL__
#include <stdint.h>
#else
#include <linux/types.h>
#endif

Modularity of a system in c

i have a few libraries which I use in modules of the same system.
My problem is that when I do #include to the h files, finally in the system it says "undefined reference to ..." different functions of the module which included twice, once in each different module. It is probably because of the double declaration, how do I manage it ?
I have "rialtor.h" in which:
#include <stdbool.h>
#include "apartment.h"
#include "offer.h"
I have "client.h", in which:
#include <stdbool.h>
#include "apartment.h"
#include "offer.h"
I have "system.c" in which:
#include "rialtor.h"
#include "client.h"
You're looking in the wrong place. An undefined reference is a linker error. You're not including all the needed object files or libraries on the command line that produces your executable.

how to change pipe size in c (or let parent get child's value without using pipe) [duplicate]

I have included following headers:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
I have also tried to use
#define _GNU_SOURCE
before #include <unistd.h>, but it also does not help.
I try to use fcntl and pass it F_SETPIPE_SZ as second argument, but I keep getting this error message:
error: ‘F_SETPIPE_SZ’ undeclared (first use in this function)
I actually found out that I don't need this, but I'm just curious why I can't use it.
Thank you.
So here's solution, thanks to Chrono Kitsune:
Put
#define _GNU_SOURCE
before any includes.
So here's the solution, thanks to Chrono Kitsune:
Put
#define _GNU_SOURCE
before any includes.
You should also pay attention to Chrono Kitsune's other comment.
F_SETPIPE_SZ/F_GETPIPE_SZ are relatively recent. Older kernels (e.g. 2.6.32 as used in RHEL6) don't have them. If you look in /usr/include/linux/fcntl.h and these constants aren't defined, then this API isn't going to work and you'll have to find some way to bypass it in whatever you're building.

Include directives not importing

I've been having this problem multiple times throughout a program I'm currently working on where gcc doesn't recognize a function or file type that I import from a library even though the include directive is clearly at the top of the program with all the others. To get around this I've just been finding similar libraries and using functions from those, but for what I'm trying to do right now none of the libraries I have found are working. Here is my list of directives:
#include "oscar.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <libgen.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <utime.h>
#include <malloc.h>
I'm currently trying to change the access and modification times in a file. I've tried using utime(), utimes(), futimens() and several other variations and all of them are having the same problem. GCC isn't recognizing many of the functions or file types. For example, I'm trying to use futimens():
futimens(m_file_desc, times);
but gcc gives the following error
warning: implicit declaration of function ‘futimens’
You probably need to need to specify the feature test macros.
From the man page:
futimens():
Since glibc 2.10:
_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
Before glibc 2.10:
_GNU_SOURCE
So, depending on your glibc version, you need to either define _GNU_SOURCE or _XOPEN_SOURCE, or _POSIX_C_SOURCE with appropriate values.

F_SETPIPE_SZ undeclared

I have included following headers:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
I have also tried to use
#define _GNU_SOURCE
before #include <unistd.h>, but it also does not help.
I try to use fcntl and pass it F_SETPIPE_SZ as second argument, but I keep getting this error message:
error: ‘F_SETPIPE_SZ’ undeclared (first use in this function)
I actually found out that I don't need this, but I'm just curious why I can't use it.
Thank you.
So here's solution, thanks to Chrono Kitsune:
Put
#define _GNU_SOURCE
before any includes.
So here's the solution, thanks to Chrono Kitsune:
Put
#define _GNU_SOURCE
before any includes.
You should also pay attention to Chrono Kitsune's other comment.
F_SETPIPE_SZ/F_GETPIPE_SZ are relatively recent. Older kernels (e.g. 2.6.32 as used in RHEL6) don't have them. If you look in /usr/include/linux/fcntl.h and these constants aren't defined, then this API isn't going to work and you'll have to find some way to bypass it in whatever you're building.

Resources