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 MinGW GCC


MinGW is a port of GCC to Windows. It is the compiler we recommend for this book.

You can obtain MinGW from http://www.mingw.org/. Find the download link on that page and download and run the MinGW Installation Manager (mingw-get).

The MinGW Installation Manager is a GUI tool for installing MinGW. It's shown in the following screenshot:

Click Install. Then, click Continue. Wait while some files download, and then click Continue once again.

At this point, the tool will give you a list of packages that you can install. You need to mark mingw32-base-bin, msys-base-bin, and mingw32-gcc-g++-bin for installation. This is shown in the following screenshot:

You will also want to select the mingw32-libz-dev package. It is listed under the MinGW Libraries section. The following screenshot shows this selection:

The g++ and libz packages we've selected are required for building libssh later.

When you're ready to proceed, click Installation from the menu and select Apply Changes.

A new dialog will show the changes to be made. The following screenshot shows what this dialog may look like:

Click the Apply button to download and install the packages. Once the installation is complete, you can close the MinGW Installation Manager.

To be able to use MinGW from the command line easily, you will need to add MinGW to yourPATH.

The steps for adding MinGW to your PATH are as follows:

  1. Open the System control panel (Windows key + Pause/Break).
  2. Select Advanced system settings:
  1. From the System Properties window, navigate to the Advanced tab and click the Environment Variables... button:
  1. From this screen, find the PATH variable under System variables. Select it and press Edit....
  2. Click New and type in the MinGW path—C:\mingw\bin, as shown in the following screenshot:
  1. Click OK to save your changes.

Once MinGW has been added to your PATH, you can open a new command window and enter gcc --version to ensure that gcc has been installed correctly. This is shown in the following screenshot: