How to know the active slave interface in a bonding pair - c

I am working under Linux, with two physical ethernet interfaces.
I have grouped the two interfaces to a bonding interface for backup... and it works.
I would like to know if there is any way to know, from my C user program, what is the active interface.
Thanks

Look at /sys/class/net/bond0/bonding/active_slave and read it using a program or code of your choice. (Replace path accordingly if using an interface name different from bond0.)

Another method to know it (tested on Debian) is looking at the file /proc/net/bonding/bondX. Replace bondX with the name of your interface.

Related

How to get display devices name in Linux

I'd like to find linux analogs of EnumDisplayDevices and EnumDisplaySettingsEx WinAPI functions.
The info I need to get is display name and state (if it active or not), width, height, bits per pixel and frequency.
How can I get this info using C (C++)?
Thanks.
As mentioned by 'Some programmer dude' in the comments you can have to go through the X window system. Most specifically one option would be the RandR protocol. Here is the protocol specification as well as the source code of the command xrandr that invokes the XRR functions and outputs most of the info that you want on the terminal. Look for the place where the
XRRScreenResources *res
is populated and then how the modes are fetched from it using the find_mode() function.
other commands that might assist you and don't go over the RandR extensions could be xprop(1), xdpyinfo(1), xwininfo(1)
Some programmer dude and ramrunner are absolutely correct. For most Linux systems, the graphical "desktop" is based on X Windows. Command-line tools for querying your X "display" include xrandr and xdpyinfo. The C-language source code for both are freely available; you can find many example programs with a Google search.
... HOWEVER ...
X Windows is "client/server". Your Linux "desktop" need not be on your physical PC; your X "display" could just as easily be a Windows desktop. In this case - xrandr and xdpyinfo are still applicable: they refer to where you're displaying (e.g. an XMing client on Windows), and not the physical host Linux is running on.
If you want to query the graphics devicews on your physical server ... then you'll instead use commands like lshw -c display or get-edid

Find D-Bus unique address using gdbus

I'm trying to find out the best way to acquire the unique D-Bus address of an object in the D-Bus system bus using the GDBus library on Linux.
Here are version numbers of the libraries I am using:
# ls /usr/lib |grep -e dbus -e glib -e gio
libdbus-1.so
libdbus-1.so.3
libdbus-1.so.3.14.11
libdbus-glib-1.so
libdbus-glib-1.so.2
libdbus-glib-1.so.2.3.3
libgio-2.0.so
libgio-2.0.so.0
libgio-2.0.so.0.5000.3
libglib-2.0.so
libglib-2.0.so.0
libglib-2.0.so.0.5000.3
Basically, I want to know the unique name/address of the object /org/bluez/hci0 located on the system bus using gdbus library. Does anyone have an example of how I would do this using the C library?
Right now I can use the command
# dbus-monitor --system
To figure out that the address I need is :1.22. I'm almost certain that there's a better way to find the address then parsing the text output of that command.
Thanks!
Why not use the well-known name of the service to find it (and if you want to keep track of the current unique owner, use g_bus_watch_name() to get it).
In fact, in the case of bluez I don't think there's ever a reason to search for "/org/bluez/hci0" as you should be using D-Bus ObjectManager API to find the objects/interfaces that the bluez service exports.
To clarify some of the concepts here:
D-Bus address: There is no such thing as an ‘address’ in D-Bus in the way you’re thinking. There are object paths, well-known names and unique names. The term ‘address’ is used to describe the socket path which clients use to connect to the dbus-daemon, but this is unrelated to what you’re asking.
Unique name: Like :1.22, this uniquely identifies a particular connection to the dbus-daemon. Typically, each application has one connection to the daemon, so this typically identifies a single application. (However, applications can have more than one connection to the bus if they want; if so, each connection would have a different unique address). A well-known name is a consistent name for a service’s connection to the dbus-daemon, which is used as an alias for its unique name. For example, org.bluez or org.freedesktop.FileManager1 are both well-known names.
Object address: Like /org/freedesktop/SomeService/blah, this is actually called an object path. Object paths are only unique within the context of a single D-Bus connection, so the path /a/b/c will typically refer to different objects for D-Bus connections :1.1 and :1.2. (Hence the question “how can I find the unique name of the object path /a/b/c?” is ill-formed, because there may be many unique names which export such an object.)

How to programmatically set a file in "hidden" in C

I'am working on an program in C for a web connected touchscreen.
In case internet is down, my boss want me to write in a low secured file the intels about the sales, for memory when internet will be back.
For now, its on a .txt, and I'd like to set the attribute of the file in "hidden".
One of you got a function or an open flag for that case?
The OS I am using is Windows 7.
This is specific to the operation system.
When you create a file you can pass a couple of attributes describing the file.
In case of windows you have : FILE_ATTRIBUTE_HIDDEN.
If you already have a file you can call the SetFileAttributes function.Check this link from msdn :
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365535(v=vs.85).aspx.
In Windows you can use SetFileAttributes() function described here

Programmatically capture X11 region with ffmpeg in C/whatever

There is an input format option to ffmpeg -- x11grab which allows one to capture specified region and output it to file/stream. I'm trying to do the same thing programmatically, but i haven't found any non-basic tutorials/reference for ffmpeg API.
I wonder, how it is possible to open x11 region with avformat_input_file or something like this. Or should i do it with XCopyArea/etc?
(Any programming language will satisfy)
There are many applications that take a screenshot. Major hint: it's open source, use the source. If you can't find the code in ffmpeg, any example application will do:
http://git.gnome.org/browse/gnome-screenshot/tree/src/screenshot-utils.c#n425
This is gnome-screenshot source code. This example uses gdk_get_default_root_window().

Retrieving Mac Address for the given IP-Address

Is there any way to retrieve the mac-address for the given ip-address from the ARP table without providing the Interface name ??
I do know the procedure of retrieving the mac address using ioctl call but in that case I should provide the interface name .. :(
One Crude Solution: Read /proc/net/arp file ... :( .. other than that .. any system call or anything else where i can retrieve the mac-address without the need of interface name ??
NOTE: Simple C based solution not interested in scripting libraries.
NOTE: I am expecting a *NUX based solution rather than WINDOWS based one.
I do know the procedure of retrieving
the mac address using ioctl call but
in that case I should provide the
interface name
So all you need is a way to find the interface name associated with a given IP. The ioctl SIOCGIFCONF will give you that.

Resources