Book Image

Hands-On Network Programming with C

By : Lewis Van Winkle
Book Image

Hands-On Network Programming with C

By: Lewis Van Winkle

Overview of this book

Network programming enables processes to communicate with each other over a computer network, but it is a complex task that requires programming with multiple libraries and protocols. With its support for third-party libraries and structured documentation, C is an ideal language to write network programs. Complete with step-by-step explanations of essential concepts and practical examples, this C network programming book begins with the fundamentals of Internet Protocol, TCP, and UDP. You’ll explore client-server and peer-to-peer models for information sharing and connectivity with remote computers. The book will also cover HTTP and HTTPS for communicating between your browser and website, and delve into hostname resolution with DNS, which is crucial to the functioning of the modern web. As you advance, you’ll gain insights into asynchronous socket programming and streams, and explore debugging and error handling. Finally, you’ll study network monitoring and implement security best practices. By the end of this book, you’ll have experience of working with client-server applications and be able to implement new network programs in C. The code in this book is compatible with the older C99 version as well as the latest C18 and C++17 standards. You’ll work with robust, reliable, and secure code that is portable across operating systems, including Winsock sockets for Windows and POSIX sockets for Linux and macOS.
Table of Contents (26 chapters)
Title Page
Dedication
About Packt
Contributors
Preface
Index

Installing libssh


You can obtain the latest libssh library from https://www.libssh.org/. If you are proficient in installing C libraries, feel free to give it a go. Otherwise, read on for step-by-step instructions.

Before beginning, be sure that you've first installed the OpenSSL libraries successfully. These are required by the libssh library.

We will need CMake installed in order to build libssh. You can obtain CMake from https://cmake.org/. They provide a nice GUI installer, and you shouldn't run into any difficulties. Make sure you select the option to add CMake to your PATH during installation:

Once you have the CMake tool and the OpenSSL libraries installed, navigate to the libssh website to download the libssh source code. At the time of writing, Version 0.8.7 is the latest, and it is available from https://www.libssh.org/files/0.8/. Download and extract the libssh source code.

Take a look at the included INSTALL file.

Now, open a command window in the libssh source code directory. Create a new build folder with the following commands:

mkdir build
cd build

Keep this command window open. We'll do the build here in a minute.

Start CMake 3.14.3 (cmake-gui) from the start menu or desktop shortcut.

You need to set the source code and build locations using the Browse Source... and Browse Build... buttons. This is shown in the following screenshot:

Then, click Configure.

On the next screen, select MinGW Makefiles as the generator for this project. Click Finish.

It may take a moment to process.

From the configuration options, make the following changes:

  1. Uncheck WITH_NACL
  2. Uncheck WITH_GSSAPI
  3. Change CMAKE_INSTALL_PREFIX to c:\mingw

Then, click Configure again. It will take a moment. If everything worked, click Generate.

You should now be able to build libssh.

Go back to your command window in the build directory. Use the following command to complete the build:

mingw32-make

After the build completes, use the following command to copy the files over to your MinGW installation:

mingw32-make install

You can try building ssh_version.c from Chapter 11, Establishing SSH Connections with libssh, to test that everything is installed correctly. It should look like the following: