Is there any open source command line library? [closed] - c

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I want to add command line interface support to a server program.
So each time I want to check server's status, I can telnet to the server's control port,
and input command to check the server's status.
Is there any open source library implements such functionality so I need not write it from scratch?
Further more, if the library can provides more features such like cisco's command line interface (tab key hint, command query, vi mode, or even symbol based command), that's would be great.

libcli sounds like exactly the thing you are looking for. It includes Cisco-like functionality and a telnet server. I've never used it, but came across it a while back when I was looking for a similar CLI.

A telnet server is almost trivial to write from scratch, the only thing easier is the obsolete rlogin protocol, which is still accessible from ssh. You won't have any trouble making a few socket calls to implement such a thing.
You are about to be told, I am sure, not to use telnet but rather ssh. It's good advice, but you have two good choices here: implement telnet in open code locally and connect via an ssh tunnel, or, use an ssh server to log in via a secure channel.
See here: for SSH servers. That won't help you directly, although apache has a Java implementation that embeds easily. If you just google for "telnet server" you will get more links than I can possibly quote here, in a variety of languages, many containing example code for an easy implementation. It's also possible that the Stevens books treat this topic directly as well.

If you don't want to deal with sockets or shared memory segments, its rather easy to have your daemon update a SQLite3 database so that a client can get its stats with a simple query, however that can become problematic as you'd need to use the host OS's user/group management to grant underprivileged users access.
In all reality, its usually better to just use a simple socket connection. In Linux, its quite easy to figure out (locally) what user ID is calling and permit only a few.

You can use the socket library to listen to a TCP port, receive commands there and output back your status. There's not much code required to do that; an example can be found here: http://www.paulgriffiths.net/program/c/echoserv.php.
(The example program just returns the command that has been sent; clearly, you would want to replace Writeline(...); with something more specific to your application.)

Is readline(3) what you are looking for?
readline will read a line from the terminal and return it, using prompt as a prompt. If
prompt is NULL or the empty string, no prompt is issued. The line returned is allocated
with malloc(3); the caller must free it when finished. The line returned has the final new‐
line removed, so only the text of the line remains.
It was unclear from the question if you are looking to implement the connection of the user interaction. This answers, the UI part.

This is the software I used before. It provides almost the same CLI features with Cisco CLI interface.
All you need to do is porting the source code under lib folder.
Quagga Routing Suite
https://www.nongnu.org/quagga/

Related

Is it possible to use a GUI based text editor (e.g. Eclipse) from the terminal?

I'd like to use terminal for all of my normal git and compiling and running processes (my school has a server that is linked to my repo on bitbucket), but I really don't like terminal-based text editing software such as Emacs and Vim. Is it possible to open and edit files from the terminal using a GUI based text editor? The reason I'm asking is because the terminal is the only way I can access the server files. Thanks in advance!
Aw, but vim is the best! :) Well, you can use nano, which is friendlier. Or, if you insist: if you are using SSH to connect to the server (and the server has an X server running !) then you can look into the ssh -X option to view X windows on your remote machine.
Oh and you could look into scp command as well (behaves almost just like regular cp, but the destination is on another host). That way you could edit on your machine, then copy it via SSH (although you'd want to be careful when copying files directly to the server filesystem)
Edit: Also, if you really don't like using the terminal (why though? (-: ), some file managers allow you to get the same functionality of the previous commands purely via GUI (for example).
You've left out some important information that someone would need to know to answer your questions. The other posters have made some assumptions.
You've mentioned this "terminal", but it's not clear exactly what that is, or how you're getting to it. What kind of computer do you have in front of you? What shell is running in that terminal? Is the shell running on your local computer, or have you remotely connected to a server and running that shell on the remote computer?
Based on what you said, I have a feeling you're making a remote connection to a server, perhaps using ssh. You likely have either a Windows or Mac PC in front of you. In those circumstances, running a GUI editor like Eclipse is possible, but likely not practical. You would have to have Eclipse installed on that remote computer, and you would be displaying the Eclipse window on your local computer using the X11 protocol. That takes a lot of bandwidth.
If my assumptions are correct, my recommendations depend on how long you expect you're going to want to stay familiar with this environment. If you intend to do this sort of work forever, then you should learn vi and Emacs to the best of your ability. As someone who's been using Emacs likely longer than you've been alive, I'd recommend you learn it, but vi is also a critical skill.
UNIXY systems provide open or gopen, depending on your OS, that should get the job done. From the man page:
By default, gopen will open filename with the application currently assigned to the file's extension. But by specifing the -a flag on the command line you can tell gopen to open the file with another application.
This means that you can use it to open files in your preferred editor
with a line like
gopen -a Eclipse file

Shared memory segment getting deleted? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm using a simple pthreads process-shared mutex in a shared memory segment to coordinate multiple server instances.
Code is straightforward:
On startup server attaches to shared memory segment if it exists, or creates it if it doesn't:
shm_open(), mmap(MAP_SHARED) etc.
This works very well while testing, but once deployed after a while i come across cases where server instances don't coordinate at all. I can replicate this by deleting the shared memory segment after a server has started: future servers instances will create/use a new segment but the existing one is stuck with the old segment nobody uses so in effect it's isolated from the rest ...
So my guess is the shared memory segment in /dev/shm is getting deleted somehow, and not by me. This is the only thing that makes sense... What is going on here ??
Running debian with linux 4.9.
Ah, looks like systemd is the culprit:
From dev-shm-files-disappearing:
After hours of searching and reading, I found the culprit. It's a setting for systemd. The /etc/systemd/logind.conf contains default configuration options, with each of them commented out. The RemoveIPC option is set to yes by default. That option tells systemd to clean up interprocess communication (IPC) for "user accounts" who aren't logged in. This does not affect "system accounts"
In my case, the files and directories were being created for a user account, not a system account.
There are two possible solutions:
Create the files with/for a system user -- a user created with the system option (adduser -r or adduser --system)
Edit /etc/systemd/logind.conf, uncomment the line RemoveIPC=yes, change it to RemoveIPC=no, save, and reboot the system
In my case, I went with option #2 because the user was already created.
See also this post on postgresql mailing list.

Very simple DNS server

I have a linux server has an ad-hoc wireless network for clients to connect to. Once connected I want users to always be redirected to it's own web server no matter what URL they type in. The large solution would be to set up a full DNS server (with BIND or equivalent) but that seems like overkill. All I need is a simple program that will listen for any DNS request and always respond with the same IP address.
I looked around for one but couldn't seem to find one. It would preferably be written in C or Perl as I don't really want to install any other scripting languages.
Use Net::DNS::Nameserver and write your own reply handler.
For C, look at:
How to Build a custom simple DNS server in C/C++
Create custom DNS name server in C
I would suggest using dnsmasq. It's more full-featured than you absolutely need, but it's very well-written, small, and easy to install, and the only configuration you would need to give it is --address='/#/1.2.3.4' to tell it to answer all queries (that don't match some other rule) with the address 1.2.3.4. dnsmasq is well-known and maintained and probably a more robust server than Net::DNS::Nameserver.
I've used fakedns.py when reversing malware. It may be too limited for your situation.
As I answered in the other related question, I wrote a basic DNS server in C++ for a job interview under BSD license.
I think the code was pretty clean, though I didn't made unit tests :-(
I tested it with dig, and it took about a week understanding DNS protocol + implementing + documentation.
If anyone would want to extend it, I guess it would not be very difficult.
Because I think it only supported inverse queries, as that was asked in the exercise.
The code could be found here:
http://code.google.com/p/dns-server/
It was migrated to: https://github.com/tomasorti/dns-server

How to start a VNC server in C?

I need to open a lightweight X server in C language. I figure vnc may be lightweight enough and universal in all Linux flavor and windows. Is there a C API to start vnc server? What libraries does it need?
If you know the name of the binary (executable) that you want to start, you can probably just use system() to start it. Assuming the binary is in /usr/bin/vncserver:
system("/usr/bin/vncserver");
Note though, as pointed out in a comment, that your question is fairly confused. A VNC server is not an X server. It's perfectly possible to run a VNC server without running X "inside" it. So starting a VNC server will most likely not help with your problem. I suggest you post a new question with a more clear description of what you're trying to achieve, this sounds a lot like you're "jumping" to a solution.

What is the best solution for remote desktop / visual support? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
We are currently investigating different remote-desktop support solutions to help our clients if they have any problems with our software and I would like some input on the best solutions out there.
We have the following needs / wishes:
Cross platform
Preferrably no installation on the user-end
Should penetrate firewalls and not be bothered by antivirus stuff.
Should leave no residu behind after support.
I know of VNC, logmeinrescue.com, dameware remote control, msn remote desktop and many others, but which one is the best?
I would also suggest TeamViewer, there is a free version and a commercial one that you can rebrand with your logo to redistribute to your clients. It does require (non administrative) install but works also behind firewalls.
Copilot
We use UltraVnc SC (Single Click), see here:
http://www.uvnc.com/addons/singleclick.html
Your client needs only download a small file from your helpdesk and run it. Then your helpdesk can control the client's desktop. The small file will uninstall itself after closing the session. The requirement is your UltraVNC should be run in listen mode.
Definitely TeamViewer!
Especially because it's very easy for the 'other side'.
No complicated skills required. Just install and run it. Easy to explain over the phone while immediatly asking for their 'code'.
Try CoPilot.
TeamViewer has been a great help to me so far but it's only available on Windows and Mac. No Linux support unfortunately.
I personally feel that UltraVNC is the best support tool for Windows boxes, especially since the end user can see what you're doing as you're doing it. Very good for training purposes as well.
RDP is neat, but I find it very frusting to use, unless on high-bandwidth or bandwidth stable machines. Port forwarding can also be a pain if the routing hardware is not great at the end users endpoint. You also need to worry about user permissions and enabling RDP as well, which if you need to do in 3rd person, can be tricky.
UltraVNC (like the other VNC clients) has a cool "Listening Host" which allows you to still VNC into a VNC server if the server's endpoint is not a direct connection to the net. This can be very useful. I've worked in the financial services sector, and we use VNC in this capacity and have never had any issue both installing it enmasse and have never had a security breach.
SSH is also an option, and with OpenSSH you can use it on windows (using cygwin) but this isn't always suitable.
In the end, I think VNC is possibly your best bet.
I've had very good experiences with CrossLoop. It's free and allows you to setup a connection within 2 minutes.
I use logmein.com quite a bit which works very well but it does have a full client installation. However it is available at any point and once installed does not require user to allow remote connection (which may or may not be ok with your customers).
Given your requirements, I think CoPilot is probably your only option, although you will require client interaction - they need to download and run an executable, but its very straightforward.
I have had good experience with the remote control of NTRSupport. Quite easy to use with no installation required.
I also used and/or use the following software that does not cover all your requirements:
Timbuktu Pro - Bad performance, few features, can't recommend it nowadays.
UltraVNC - Works, but I remember some problems with clipboard and file transfer support.
PCAnywhere - Works, but the performance was never satisfying, Awkward clipboard handling.
RDP - Great for Windows machines but can be problematic when it is not clear whether you have to use the console session or not. Sometimes, you disconnect a server session just by accident.
For windows only: Crossloop

Resources