I want to send a message using D-Bus but I get an error:
process 30860: arguments to dbus_message_new_signal() were incorrect, assertion "_dbus_check_is_valid_path (path)" failed in file ../../../dbus/dbus-message.c line 1456.
This is normally a bug in some application using the D-Bus library.
Message is null!
My code:
#include <stdio.h>
#include <dbus/dbus.h>
int main(){
DBusConnection *conn;
DBusError err;
dbus_error_init(&err);
conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
if(!conn){
fprintf(stderr, "DBus error %s: %s\n", err.name, err.message);
return(1);
}
dbus_bus_request_name(conn, "org.test", DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
if(dbus_error_is_set(&err)){
fprintf(stderr, "DBus error %s: %s\n", err.name, err.message);
dbus_connection_close(conn);
return(1);
}
DBusMessage *msg;
msg = dbus_message_new_signal("org/test/mon/data", "org.test.mon.data", "Data");
if(msg == NULL){
fprintf(stderr, "Message is null!\n");
return(1);
}
dbus_message_append_args(msg, DBUS_TYPE_STRING, "My message", DBUS_TYPE_INVALID);
if(!dbus_connection_send(conn, msg, NULL)) fprintf(stderr, "Error sending message!\n");
dbus_message_unref(msg);
dbus_connection_flush(conn);
dbus_connection_close(conn);
}
I tried to follow dozens of tutorials and examples but I think I missed something.
I just need to send a message with a text.
In addition to fixing the code as recommended by jku, it’s recommended that you don’t use libdbus for connecting to D-Bus: its design is outdated, and is a pain to use correctly.
It’s easier to use a more modern high-level API, such as GDBus.
The first argument to dbus_message_new_signal() is a D-Bus path and the spec says this about paths:
The path must begin with an ASCII '/' (integer 47) character
Related
I'm using Libssh to log into an ethernet switch and run commands. I can connect and log in just fine but commands cannot be run. The program just returns "Channel request exec failed" as the ssh error. Normal ssh outside of the program works as expected and commands can be executed. The program can run commands on my localhost just fine. I've tried different commands as well, including just the help command or things that would never produce errors if run. This is the function I'm using to send the command:
int send_command(ssh_session session, char *command){
int rc;
ssh_channel channel;
channel = ssh_channel_new(session);
if (channel == NULL){
fprintf(stderr, "***Error in channel creation: %s***\n", ssh_get_error(session));
exit(-1);
}
rc = ssh_channel_open_session(channel);
if (rc != SSH_OK){
fprintf(stderr, "***Error opening channel: %s***\n", ssh_get_error(session));
exit(-1);
}
rc = ssh_channel_request_exec(channel, command);
if (rc != SSH_OK){
fprintf(stderr, "***Error sending command: %d, %s***\n", rc, ssh_get_error(session));
exit(-1);
}
char buffer[256];
int nbytes;
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer),0);
while (nbytes > 0){
if (fwrite(buffer, 1, nbytes, stdout) != nbytes){
fprintf(stderr,"***Error writing result: %s***\n", ssh_get_error(session));
exit(-1);
}
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
}
ssh_channel_send_eof(channel);
ssh_channel_close(channel);
ssh_channel_free(channel);
return SSH_OK;
}
I think it might have something to do with the custom CLI the switch is using - it's not a true linux terminal. The switch processor I'm logging into is running some kind of simplistic linux OS that I can't find information on. Are there different types of consoles I need to account for? Should I be opening a shell, even though the commands are programmatic and won't require user input? I've mostly been following the libssh tutorial to get this working so I don't know much about why things work or don't work, just that they do. I'm running this from a Cygwin enviroment on a windows machine if that matters.
I was writing my first client in C when I reached the point where I have to send a socket to the server. When i try to get its address I get a
Resource temporarily unavailable
and I can't find what is causing this problem.
dadesSoftConfig->ipServer has inside localhost
struct hostent *ent;
ent = gethostbyname(dadesSoftConfig->ipServidor);
if (ent == NULL) {
int errnum = errno;
fprintf(stderr, "Client finalitzat: %s\n", strerror(errnum));
exit(EXIT_FAILURE);
}
I do not send any socket, wait for any data yet when I do this call , this is happening at the very beginning, even before the register phase of my protocol.
As requested, this is a print of the dadesSoftConfig:
DEBUG_INFO: Nom: SW-01
Mac: 89F107457A36
Server: localhost
Server-port: 2019
And this is how I print it:
void print_software_configuration(TDadesSoftConfig *dades) {
char *msg;
msg = (char *) malloc(sizeof(char) * 75);
if (sprintf(msg, "\tNom: %s \t\tMac: %s \t\tServer: %s \t\tServer-port: %d\n",
dades->nom, dades->mac, dades->ipServidor, dades->serverPort) < 0) {
fprintf(stderr, "No s'ha pogut mostrar el contingut llegit\n");
} else {
print_debug_info(msg);
}
free(msg);
}
I tried sending "127.0.0.1" to gethostbyname() function and the code perfectly works, even when I store it to my struct. Any idea why it doesn't work when sending "localhost"?
As pointed by my prints, the data structure was correct, but the data it contained was not. Info should be displayed separated by \t\t not a \n\t\t.
The problem was solved when setting correctly the delimiters to strtok() function which parses the input.
I used socket in my program to let the client communicate with the prover namely the server. Firstly, the client send local file to the prover, and it succeed. Then, the client send signatures of that file to the prover, but the program has stuck. I think the recv function of the prover cannot receiver any data so it failed, but I don't know why it happend. Can anyone explain it?
/* send file */
if (on_cmd_send_file_client(sockProver, username, party, filename, blocksize, blocknum)) {
printf("%s(%d)-%s:%d-%s\n", __FILE__, __LINE__, __FUNCTION__, errno, strerror(errno));
return (errno ? errno : -1);
}
/* send signature */
length = pairing_length_in_bytes_G1(pairing);
if (on_cmd_send_sig_client(sockProver, username, party, filename, length, blocknum)) {
printf("%s(%d)-%s:%d-%s\n", __FILE__, __LINE__, __FUNCTION__, errno, strerror(errno));
return (errno ? errno : -1);
}
I suggest you start both the client and a server in debugging mode to understand what exactly is happening. As it stands now, it is difficult to say what exactly is the cause of the communication stall. There might be a framing problem, i.e., the server waits for more data, while the client thinks it already sent everything. I saw quite many cases in which recv was assumed to do framing, which it does not for TCP.
I'm having an issue where by pcap_datalink() is always returning 1. To my understanding this is LINKTYPE_ETHERNET. But, the device I am using is a wireless card and in my case en0.
This is stopping me from putting the card into monitor mode, and stopping my WLAN filters from working. I've tried to run this on both OSX and Linux with the same results. I also run as root.
Here's the part of my code that's causing the problem. For the example, assume dev is set to en0 (wireless device on Mac).
#include <stdio.h>
#include <pcap.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
pcap_t *pcap_h;
char *dev, errbuf[PCAP_ERRBUF_SIZE];
struct bpf_program fp;
struct pcap_pkthdr header;
const u_char *packet;
if(argc < 2)
{
printf("Usage: %s device\n", argv[0]);
exit(EXIT_FAILURE);
}
dev = argv[1];
if((pcap_h = pcap_create(dev, errbuf)) == NULL)
{
printf("pcap_create() failed: %s\n", errbuf);
exit(EXIT_FAILURE);
}
if(pcap_can_set_rfmon(pcap_h) == 0)
{
printf("Monitor mode can not be set.\n");
}
if(pcap_set_rfmon(pcap_h, 1) != 0)
{
printf("Failed to set monitor mode.\n");
exit(EXIT_FAILURE);
}
if(pcap_activate(pcap_h) != 0)
{
printf("pcap_activate() failed\n");
exit(EXIT_FAILURE);
}
/*
* Compile a filter to sniff 802.11 probe requests
* Filter: type mgt subtype probe-req
*/
if(pcap_compile(pcap_h, &fp, "type mgt subtype probe-req", 0, PCAP_NETMASK_UNKNOWN) == -1)
{
printf("pcap_compile() failed: %s\n", pcap_geterr(pcap_h));
exit(EXIT_FAILURE);
}
/*
* Set the compiled filter
*/
if(pcap_setfilter(pcap_h, &fp) == -1)
{
printf("pcap_setfilter() failed: %s\n", pcap_geterr(pcap_h));
exit(EXIT_FAILURE);
}
pcap_freecode(&fp);
packet = pcap_next(pcap_h, &header);
printf("Header: %d\n", header.len);
pcap_close(pcap_h);
return 0;
}
Any idea's why pcap_datalink() is always returning 1?
Edit
Updated code, and added pcap_set_rfmon() before the call to pcap_activate(). I get an error:
pcap_compile() failed: 802.11 link-layer types supported only on 802.11
Are you shure this is what's is stopping you from putting the card into monitor mode, and stopping your WLAN filters from working, or do you do this call to pcap_datalink() as a check trying to pinpoint the issue?
Be aware that, from PCAP-LINKTYPE(7):
For a live capture or ``savefile'', libpcap supplies, as the
return value of the pcap_datalink(3PCAP) routine, a value that
indicates the type of link-layer header at the beginning of the
packets it provides. This is not necessarily the type of link-layer
header that the packets being captured have on the network from
which they're being captured; for example, packets from an IEEE 802.11
network might be provided by libpcap with Ethernet headers that
the network adapter or the network adapter driver generates from the
802.11 headers.
So I would not take this LINKTYPE_ETHERNET / DLT_EN10MB return value as the sure indication of a problem here.
EDIT:
Also, pcap_set_rfmon() is supposed to be call before the handle is activated, which is not visible in your code.
pcap is rather touchy about the order things should be done. Have a look at the man pages for pcap_can_set_rfmon and pcap_set_rfmon.
The order should be:
pcap_create
pcap_can_set_rfmon
pcap_set_rfmon (if so far so good)
then and only then, pcap_activate
i've occourred in this error using RSA_private_decrypt:
error0407106b: lib(4):funct:(113):reason(107)
what does it means?
and why i have this error only if i work on the net, and not if i work on localhost?
You can use ERR_error_string to get a more descriptive error message like so:
ERR_load_crypto_strings();
ERR_error_string(ERR_get_error(), err);
fprintf(stderr, "%s\n", err);
Make sure you include <openssl/err.h> as well.