HINTERNET InternetOpenUrl() on linux C - c

I am a native windows programmer and I was just starting to develop some applications on linux. I was wondering if there is a linux function similar to InternetOpenUrl(). I wanted to use this so I could open the Speakeasy speed test to download random images according to size to "speed test" internet connections. If there isn't a similar command does anyone have some C code for initiating a http socket to a server to download a file (or code to do the same on a ftp although i rather not use ftp). I would rather use the InternetOpenUrl() alternative if there is one but i am also open to other methods as well.

You're looking for libcurl, which incidentally also works on Windows.

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

How to synchronize code files on windows with WSL/linux?

Basically I have some C/C++ code that I need to build and debug on a Linux machine. Unfortunately, my windows laptop doesn't have enough free hard space to install some Linux dist nor does it have enough free RAM to comfortably run VM.
Until now, I dealt with it rather comfortably using WSL, but the scale was rather small. It was easy to edit and debug 2-3 .c files through CLI and gdb, but it became really annoying on a large scale projects.
I want something simple as "edit code in windows IDE [X], compile it on remote Linux/WSL (the project uses Makefiles), and preferably debug it via gdb".
VS has something close to what I want, but it can't deal with existing Linux projects. It needs to create a new configuration which is alien to the project's Makefile.
I know this question is a bit old, but I think the solution is to make a symlink between your WSL folder and the Window's folder. This is how I handled it for a Ubuntu-20.04 WSL:
Access PowerShell in Administrator mode
Type cmd.exe in the PowerShell
Once cmd.exe is opened, type mklink /d C:\<path_to_your_Windows_folder> \\wsl$\Ubuntu-20.04\home\<your_user>\<path_to_your_WSL_folder>
EDIT
This was tested under Windows 10 Version 2004 with WSL2
I'm unsure about C and C++ but it sounds like this is exactly the same as how i work in node and javascript every day.
I checkout my code using git inside WSL to a location like /mnt/c/code/myproject. Then using sublime/VS code/webstorm i edit the files in windows in the location c:\code\myproject this works really well and have been doing this every day for over a year.
Things to be aware of are that you need to ensure that your editor of choice saves files with linux line endings and that all command line operations are done inside WSL.
Please see this article to see the differences between windows and linux files and how this works inside the WSL.
I want something simple as "edit code in windows IDE , compile it on remote linux/WSL
You will have something as simple as that.
Only with Windows 19.03 though:
See "Updated WSL in Windows 10 version 1903 lets you access Linux files from Windows"
Microsoft's Craig Loewen says:
In the past, creating and changing Linux files from Windows resulted in losing files or corrupting data. Making this possible has been a highly requested and long anticipated feature. We're proud to announce you can now easily access all the files in your Linux distros from Windows.
So how does this work? He goes on to explain:
To put it briefly: a 9P protocol file server facilitates file related requests, with Windows acting as the client.
We've modified the WSL init daemon to include a 9P server. This server contains protocols that support Linux metadata, including permissions.
There is a Windows service and driver that acts as the client and talks to the 9P server (which is running inside of a WSL instance).
Client and server communicate over AF_UNIX sockets, since WSL allows interop between a Windows application and a Linux application using AF_UNIX as described in this post.
Warning:
The old rules still apply, you should NOT access your Linux files inside of the AppData folder!
If you try to access your Linux files through your AppData folder, you are bypassing using the 9P server, which means that you will not have access to your Linux files, and you could possibly corrupt your Linux distro.

Retrieve network camera stream URL in Linux

I am trying to retrieve rtsp URLs of cameras on my network. I can do this using Onvif Device Manager on Windows but how to do this on Linux using C/C++ or command line tool. I have tried various libs e.g. onvifc (OpenCVR) and onvifcpplib but none of them could compile on Linux, neither they have API documentation. Any suggestions please!
I was able to find a gsoap-onvif solution from https://github.com/tonyhu/gsoap-onvif. This programs successfully retrieves parameters from most of the Onvif complaint cameras.
you can have a try with python onvif, some feature you can use, may be other feature such as PTZ you can use .
also, you can have a try with opencvr's another project, https://github.com/veyesys/h5stream, if you can't compile,you can download from sourceforge.
Good luck.

Send data from local webpage to C program running locally

I'm looking for the simplest possible (cross-platform, but not necessarily cross-browser) code to send data from a local web page to a C (not C++) application running locally. Basically, I have an HTML page with a form and I want to send the data from that form to another process in the simplest way possible. (I know that I can read local data from a webpage relatively easily, especially now with HTML5, but writing outside of the javascript sandbox is a mystery.)
I know that browsers make this very hard to do for security concerns, and I don't want to open up my machine to attacks, but maybe I can run a very simple server inside the C application to receive the submitted data... Either way, I cannot run any standard webserver, so I need to have a C library/app that does it for me.
I've looked into .hta files (seem to only work for Windows) and some C web servers (all I've found are *nix specific). A similar question is how to transfer of data from webpage to a server c program , except that user allows the use of Java and other webserver platforms (I must use C).
UPDATE: Promising libraries: https://stackoverflow.com/questions/175507/c-c-web-server-library
Have you considered FastCGI? I have a fast CGI library written in C that might be helpful. It still needs a lot of work and I'm not sure if I would want to use in a production environment.
If you find any bugs or make any enhancements, please share them so that it can help others.
https://github.com/manvscode/shrewd-cgi
You could write a very simple web server in C, serve the page from it (avoids security issues), and post the form to it.
If you're bound to c, you'll have to go low-level and deal with all the nifty details around the sockets library. (There's a reason why people abstract that in high-level languages). Check out some example code for RPC in C with server and client here. If you can afford to bind to C, e.g. using Tcl, i would implement the server in a tcl script and bind your C functions as a Tcl command. That way you pass the content directly to your c method while avoiding to write all the sockets code low-level.
Send the desired data from web to specific port of your system (for example port X). Then run your application (e.g. APP) in background using following command:
nc -l X | ./APP
And of course you need nc package.

using libcurl to create a standalone site-polling program

I am creating a standalone (no DLLs) windows C/C++ program that uses HTTP POST to periodically send data to an HTTP server. I identified libCURL as the HTTP client library as it seems simple and reliable.
I still need to identify the environment (an IDE) which I can use to develop my project. My program has:
poller- which checks the status of the connection
a file writer when polled link is down
a component which POSTs the file when link is up
What is the appropriate IDE for this project? I heard endorsements for DevC++ and Visual C.
I am a newb to coding and this site. Pardon me if I am unclear in anything.
Any IDE will fit your need. Just install one of them and start coding.
Try CodeBlocks. It is light, more easy to work with and has more features than Dev C++.

Resources