How to temporarily disable IPv6 on Ubuntu? You need to diagnose a communication issue or track down a network problem?

IPv6 provides solution of the IPv4 address exhaustion as it’s offering a much larger addressing space.
However, there are few instances in which IPv6 is casing network problems.
Some hardware doesn’t utilize it or take any advantages of IPv6 communications protocol. There are instances in which the temporary and easy solution is to (permanently) disable it. It can be easily re-enabled when it needed again.

In case you need to disable it, either only for troubleshooting or permanently, you can use the following terminal commands.

First of all, let’s verify the current status of your IPv6 communications protocol.

If this command returns 0 that means IPv6 is enabled in your system.

Scroll down to the end of the file and insert these three lines below.

Save and quit your editor, then reboot your system.

Verifying the status of IPv6.

This command should return 1 meaning you successfully disabled IPv6 communications protocol.

To re-enable IPv6 just simple delete or comment out those 3 lines above.

You can use

to read values from file, it should return:

There are some additional commands if this method does not work.

Disable the network manager

Get the IP address from the server using:

List of IP address

Removing all IP information from an interface (enp2s1 in my case)

Assign the first ip addresses like this:

You can repeat for other IP addresses.
You can add the default route using:

List of network devices:

Restart the networking.service

or

Ipv6 test is a free online service to diagnose connection problems: http://ipv6-test.com/

SQLite – How to use fundamental functions in C++

SQLite operations in C++

This tutorial aimed to demonstrate how to use SQLite database operations such as CREATE, INSERT, UPDATE, SELECT and DELETE in C++. Since the appearance first smartphone and other mobile devices SQLite become most widely deployed and used database engine in the world. Precise numbers are difficult to obtain but SQLite is likely used more than all other database engines combined. We can find SQLite in every Android device, iPhone and iOS device, Mac, Windows10, Firefox, Chrome, Safari, Skype, Dropbox, TurboTax, QuickBooks, PHP, Python, television sets, set-top cable boxes and many automotive multimedia systems.

It’s an open-source SQL database engine. You can download the source code or precompiled binaries depending your requirements. You might also need to add [-lsqlite3] and [-std=c++17] to successfully compile, create an executable file. Each of the following source code available on my git repository.

github.com/lnrsoft/sqlite3_cpp_basics_updated
or
lnrrepo.ddns.net/git/lnrsoft/sqlite3_cpp_basics_updated

Use this link local_db.sqlite (5 downloads) if you would like to download the local_db.sqlite file that I used in this tutorial.

Step 1 – The first thing we need to do is to create the actual database file that we will use in this article. I called sqltdemo.db in our case.

Compile and run our source code to create the local_db.sqlite with the following command. Here we link our code with the sqlite3 library that will create our db file.

Verify our result:

Step 2 – CREATE TABLE

Compile and run.

Step 3 – INSERT INTO our CANDIDATE TABLE

Compile and run.

Step 4 – Fetch and display records from the company CANDIDATE TABLE. In this scenario we use a callback function that obtains results from SELECT statement.

Compile and run.

Step 5 – Using UPDATE statement to update any records in our CANDIDATE table.

Compile and run.

Step 6 – DELETE statement can delete any records from the CANDIDATE table.

Compile and run.

I recommend you to check the official SQLite documentation at sqlite.org for more advance SQLite features and options and support. For further info about using sql with c++ you might found it useful to read me previous post of  a simple Qt tool to test QSqlDatabase access connection to a MySQL database. I created this simple Qt command line tool to test connection between Qt client applications and a remote Mysql Server. The code includes Secure Sockets Layer (SSL) support to test secure connection. The QSqlDatabase class provides an interface for accessing a database through a connection where an instance of QSqlDatabase represents the connection. The connection provides access to the database via one of the supported database drivers, which are derived from QSqlDriver.

Alternatively, we can subclass your own database driver from QSqlDriver. My next post will be an article how to write your own database driver in Qt for Unix, OSX and Windows platforms.

Install Java SE Development Kit 10.0.1 on Ubuntu 18.04 LTS x64

Download: jdk-10.0.1_linux-x64_bin.tar.gz

You might need to reboot your system.

[C++] MemorySanitizer

MemorySanitizer is a detector of uninitialized memory reads in C/C++ programs. Uninitialized values occur when stack- or heap-allocated memory is read before it is written. MSan detects cases where such values affect program execution.
At this time, MemorySanitizer supports Linux x86_64 only.
To use MemorySanitizer, compile and link your program with -fsanitize=memory -fPIE -pie. To get any stack traces, add -fno-omit-frame-pointer.

Origins tracking

[C++] AddressSanitizer

AddressSanitizer is a memory error detector for C/C++. It finds:

-Use after free (dangling pointer dereference)
-Heap buffer overflow
-Stack buffer overflow
-Global buffer overflow
-Use after return
-Use after scope
-Initialization order bugs
-Memory leaks

In order to use AddressSanitizer we will need to compile and link your program using clang with the -fsanitize=address switch. To get a reasonable performance add -O1 or higher.

[C++] ThreadSanitizer

ThreadSanitizer is a data race detector for C/C++. Data races are one of the most common and hardest to debug types of bugs in concurrent systems.
Here is an example of a data race that can lead to crashes and memory corruptions:

[C++] How to install gcc-7 on Ubuntu LTS 16.04

[C++] Return absolute_path using boost::filesystem

Return absolute_path using boost::filesystem

Note:
You’ll need to add the boost libraries to the linking phase with the -L flag and the names of the libraries with the -l flag. This is different from the compilation phase where only the -I include path is needed. For example in my case:

boost::filesystem tutorials
https://meetingcpp.com/blog/items/handling-files-using-boost-filesystem.html
http://www.boost.org/doc/libs/1_55_0/libs/filesystem/doc/tutorial.html
http://www.boost.org/doc/libs/1_44_0/libs/filesystem/v3/doc/tutorial.html
http://www.boost.org/doc/libs/1_51_0/libs/filesystem/doc/reference.html#Absolute-path
http://www.boost.org/doc/libs/1_53_0/libs/filesystem/doc/reference.html
http://www.boost.org/doc/libs/1_55_0/libs/filesystem/doc/reference.html#copy_file
http://wiki.lihebi.com/boost.html

The Boost C++ Libraries
AdvC++Libs.key
boost-graph-library
asio_doc
dima-boost-intro
Boost_for_KDE_Developers-Volker_Krause

[C++] An Interesting Bit Array Example

Here is an interesting bit array task and its solution in C++ that I thought it’s worth to share with you.
You are given four integers values: N, A, B, and C. You need to use them in order to create the sequence called bitArray with the following pseudo-code:

Task: calculate the number of distinct integer in the bitArray sequence.

Solution
Input: four space separated integers on a single line, N, A, B, and C  respectively.
Where N = 32, A = 16, B = 16, C = 16.
Output: 
one integer that denotes the number of distinct integer in the bitArray sequence equals 7 as we set N, A, B, C values.

If you’d like to read the input from the console simply comment out line 57 and 62 and toggle comment selection on line 58, 59, 60 and 61.
Input read from the console:

four space separated integers on a single line, N, A, B, and C  respectively.
Output print to the console: 
One integer that denotes the number of distinct integer in the sequence called bitArray.

The number of distinct integer  in the sequence  will be 536870912 when we change the previously set integer values to:

Use Wandbox online C++ compiler

[C++] cxx_status and support in Clang

Here is the list of current C++ implementation status and support in Clang as per Aug 2017.
You can find the complete list of features and minimum Clang version with support on the source page: https://clang.llvm.org/cxx_status.html

C++11 implementation status
Clang 3.3 and later implement all of the ISO C++ 2011 standard. By default, Clang builds C++ code according to the C++98 standard, with many C++11 features accepted as extensions. You can use Clang in C++11 mode with the -std=c++11 option. Clang’s C++11 mode can be used with libc++ or with gcc’s libstdc++.

C++14 implementation status
Clang 3.4 and later implement all of the ISO C++ 2014 standard.

You can use Clang in C++14 mode with the -std=c++14 option (use -std=c++1y in Clang 3.4 and earlier).

C++17 implementation status
Clang 5 and later implement all the features of the C++ 2017 Draft International Standard.
You can use Clang in C++17 mode with the -std=c++17 option (use -std=c++1z in Clang 4 and earlier).

C++2a implementation status
Clang has experimental support for some proposed features of the C++ standard following C++17, provisionally named C++2a. Note that support for these features may change or be removed without notice, as the draft C++2a standard evolves.
You can use Clang in C++2a mode with the -std=c++2a option.

More technical specifications and standing documents on the source page: https://clang.llvm.org/cxx_status.html