What Linux Port is always writing [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am experimenting reading (and eventually writing) serial ports in C. I want to be able to connect to a port on debian and read in some data but I need a port that is writing (speaking). I am new to linux programming.
What port, that will definitely be present and talking in debian, can I connect to to read some data in?
Can you also suggest a port I can eventually use to write to aswell?
I've tried connecting to /dev/ttyUSB1 that this example uses but that port doesn't exist.

I would suggest either open /dev/random (or /dev/urandom) as Paul suggests or create your own socket and read/write to that. Don't just pick an arbitrary socket and hope it has information that no other process needed.
If this is your first time working with sockets I would also suggest that you try playing around with things in a language like python simply because you don't need to recompile to see where you went wrong and the warnings are often more readable (take a look at https://docs.python.org/2/howto/sockets.html)
As a side note: If you have access to an arduino you might like to try connecting to that socket (usually something like ser = serial.Serial('/dev/ttyACM0', 9600) in python).

Related

Pass from HC-05 Data Mode to HC-05 AT Command mode by writing some bunch of code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
My main problem is to reduce the power consumption of the HC-05 Bluetooth module. As it may be known, such a module consumes lower and lower energy when it is in the AT Command Mode (between 1.5 and 3 mA current). Since my project requires sending real time data that change every 15seconds, I want to keep the module in the AT command mode in the 15seconds that the HC-05 don't receive any data. I obviously believe that this kind of idea/solution will dramatically save the energy of the module. In other words, instead of keeping the module in data mode permanently, it will be set in data mode during 15seconds, and in AT command mode during 15seconds, after that it returns to the data mode and still 15seconds etc... I want to know is there any solution for that ? For example writing a bunch of C code (since my Hc-05 is directly connected to an STM32 board) to pass for the AT commande mode every 15seconds
Thanks in advance.
In the absence of any sample code, the answer to your only explicit question
I want to know is there any solution for that ?
is, "Yes."

Make REST API call from C without using libcurl [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I was trying to make REST calls from C; came across libcurl which was successful in doing that dynamically. But the code needs to be ported on to a Cortex M0 board, which need a lower footprint. Is there any workaround? All I need is to make a REST API call from C without any external library or overhead.
Well, how low do you want to go?
C doesn't know anything about REST, it doesn't know HTTP, not even TCP or something like a network interface. On bare metal, you'd start by reading the hardware specs of your network interface card and programming it (through ports, memory mapped registers, etc....) -- You'd have to understand ARP, IP, ICMP etc (and, of course, implement it), just to get a TCP connection on top of that.
Assuming there's an operating system in place, you'll be given some API, then the answer would depend on what this API allows. A typical level would be a "socket abstraction", like BSD sockets, which gives you functionality to establish a TCP connection. So, "all" you'd have to do is implement a HTTP client on top of that.
Unfortunately, HTTP itself is a complex protocol. You'd have to implement all the requests you need, with Content-Types, transfer encodings, etc and also handle all possible server responses appropriately. These are a lot. Bring content negotiation to the table, partial responses, etc ... it's "endless" work. That's exactly the reason there are libraries like curl that already implement all of this for you.
So, sorry to say that, but there's no simple answer possible giving you what you want here. If you want to get the job done, use a library. Maybe you can find something smaller than libcurl.
What you can do is to compile the library yourself, linking it statically and using compiler options like gcc's -ffunction-sections -fdata-sections and the linker option --gc-sections in an attempt to drop code from the library you don't use, this might help to reduce size.

Allowing linux firewall to receive packets for my code [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I wrote a c code for ping command and for some reason it doesn't receive any reply. I spent couple of days trying to find problem with the code, but later I have checked packet sending with wireshark. I found that the reply was send to me (the destination is unreachable, as it should be with destination IP I entered). In Internet I found that my firewall could cause this problem, but I didin't find any solution for it. So please help me, how can I add some kind of exeption for my firewall for the certain code? Thank you.
EDITED
The iptables output:
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Wireshark output:
17 0.641636029 192.168.0.134 192.168.0.1 ICMP 120 Destination unreachable (Port unreachable)
Also I probably made a mistake and the problem may be not in the receiving, but in sending packet
Try to check firewall using the following command iptables -L -n And provide output
Consider using some library like liboping or libping
Be aware that ping uses ICMP (see icmp(7)). Your program is likely to require root privilege. So you need to run it as root, or use setuid techniques.
Check systematically against failure every system call that you are using (see syscalls(2) for a list). Read errno(3) and use perror(3) (or strerror(errno)).
Use also strace(1) on your program to understand what system calls are done (and which one is failing).

How to monitor my own private fd using D-bus? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have some doubt when taking D-bus IPC into my client program.
In my opinion, D-bus has its own way to manage the low-level socket.
The socket fd is packed into a 'DBusConnection', and then be used to communicate with daemon, write/read/dispatch/loop. That's ok.
But if the client needs to directly monitor/select another socket, such as monitor a tcp port, using its own way sometimes.
Is D-bus fit for this situation ? How could I select the two sockets at the time when using with D-bus ?
Is D-bus designed to communicate with other local processes only via 'DBusConnection' connecting with daemon ?
I just start to use D-bus, and really confused.
Any help will be appreciated ~
Sorry I did not present it clearly.
I'll take with an example to detail it.
Some guys familiar with D-bus may have looked up the source code of 'dbus-monitor', one tool attached to D-bus.
'dbus-monitor' uses 'dbus_bus_get' to create a connection with daemon,
and then call 'dbus_connection_get_object_path_data' to tell dameon which objects it support, and so forth( sth not cared here ),
finally, '_dbus_loop_run' for main loop.
With curiosity, I have done some diving work about the implementations of these D-bus APIs. ( It's not enough obviously. )
From my point of view, same with the usual IPC logic, the essential work of these steps looks like (May be it's not quite sure.) : open a local socket, connect to the server(daemon), read/write/select (the server uses epoll) socket fd.
Ok, thanks for your patience. fine~
In order to communicate with daemon, D-bus creates a socket and uses its own way(API) to manipulate the socket. ( the socket fd is encapsulated into
D-bus's connection structure -- 'DBusConnection', we can NOT directly operate it. )
Now my question is if I need D-bus to create a 'DBusConnection' (encapsulate a local socket fd) to talk to the daemon, like 'dbus-monitor'.
And at the same time, my client application also needs to create another socket fd to monitor a tcp port.
I wonder whether there is a way to simultaneously 'select' these two kind of socket fd? ( one encapsulated in D-bus's connection structure
which can NOT be select explicitly, another is a general socket fd. )

A way for saving data after closing a C program [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to use the c-programming language to built a small database for students. Only the admnistrator should enter delete or modify the data. I have developed this program in C. But when i close my program, the data is lost. At the beginning i thought to store these data in files (like xml) but know i thinking to store these data on hardware (harddisk or sd-card). Is it possible? Any suggestions?
You could write a separate program which acts as a "server" - that is, it runs continuously and communicates only through some sort of network interface - named pipes or TCP/IP or whatever. When your "client" program starts up it attempts to establish a connection with the server - if it does not find the server it starts it up and then establishes communications with it. Once the "server" is found the "client" requests any saved data from the "server", which the "server" then returns if it has any. When the "client" decides to shut down it first communicates with the "server", passing any data it wishes to save to the "server" which then stores it (perhaps in a file, perhaps in memory - the implementation is up to you).
Best of luck.

Resources