为什么TCP头部没有数据长度信息而UDP有

ipv4_header

为什么TCP头部没有数据长度信息而UDP有

先让我们看看IP,TCP,UDP的头部结构

1. IPv4 头部

2. TCP和UDP头部

可以看到IP的头部包换数据的长度,TCP的头部不包含数据长度,UDP的头部则包含。

从信息冗余的角度来看,UDP的长度信息是不需要的。

因为IPv4的头部已经包含了数据的长度信息,这里的数据如果当前的通讯协议是UDP,那么这个长度就包含了UDP的头部和UDP的数据,因为UDP的头部长度固定为8字节,那么这样就很容易的算出UDP的数据的长度了。

继续阅读

Posted in 网络开发 | Leave a comment

强大的linux命令ncat

强大的linux命令ncat      

ncat是linux内置的一个命令,可以提供tcp,udp的服务器和客户端,还可以作为代理服务器。

所以如果测试,完全不用自己写一个tcp和udp的服务器,直接使用ncat就可以。ncat默认是工作于tcp模式,如果要工作udp,则使用 -u选项。下面介绍一些非常经典的应用。

继续阅读

Posted in Linux系统学习, 网络安全, 网络开发 | 4 Comments

Linux查找动态库的3种方法

Linux查找动态库的3种方法

linux默认加载动态库的路径是 /lib或者是/lib64, 32位的系统是前者,64位是后者。

如果找不到还有3个地方

  1. LD_LIBRARY_PATH
  2. rpath
  3. ldconfig

通过设置LD_LIBRARY_PATH环境变量方式,让系统在这个环境变量设置的路径查找动态库。

$> export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:XXXXXX

继续阅读

Posted in Linux系统学习, Linux编程 | Leave a comment

CMake之RPath

CMake之RPath

其实rpath并不是定义或者发明的,这个东西是linux的东西,为什么把它和CMake放在一起讨论呢?是因为鄙人之前一直用手写Makefile来管理和编译工程,但是如今使用CMake,结果发现编译出来的可执行文件的链接到绝对路径的动态库,这样可执行文件就不可以拷贝到别的机器执行了,而之前使用makefile就没有这个问题。

继续阅读

Posted in Linux系统学习, Linux编程 | Leave a comment

CMake的CPack

CMake的CPack

CMake不仅可以用来管理工程,编译,安装,还可以制作安装包,安装包可以是压缩包还可以是rpm包。

下面利用一个简单的例子来解释如何使用CMake的cpack制作安装包

工程名 = Speaker

目录结构

Speaker +

              — CMakeLists.txt                ———> 1

继续阅读

Posted in Linux系统学习, Linux编程 | Leave a comment

RPM的安装,卸载,更新和查询

RPM的安装,卸载,更新和查询

下面的文字是摘自:

http://www.thegeekstuff.com/2010/07/rpm-command-examples/

非常全面的用例子的方式解释各个rpm的命令参数,懒得翻译了,就直接上原文了。

RPM command is used for installing, uninstalling, upgrading, querying, listing, and checking RPM packages on your Linux system.

RPM stands for Red Hat ackage Manager.

With root privilege, you can use the rpm command with appropriate options to manage the RPM software packages.

In this article, let us review 15 practical examples of rpm command.

Let us take an rpm of Mysql Client and run through all our examples.

1. Installing a RPM package Using rpm -ivh

RPM filename has packagename, version, release and architecture name.

For example, In the MySQL-client-3.23.57-1.i386.rpm file:

  • MySQL-client – Package Name
  • 3.23.57 – Version
  • 1 – Release
  • i386 – Architecture

When you install a RPM, it checks whether your system is suitable for the software the RPM package contains, figures out where to install the files located inside the rpm package, installs them on your system, and adds that piece of software into its database of installed RPM packages.

The following rpm command installs Mysql client package.

# rpm -ivh  MySQL-client-3.23.57-1.i386.rpm
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]

rpm command and options

  • -i : install a package
  • -v : verbose
  • -h : print hash marks as the package archive is unpacked.

You can also use dpkg on Debian, pkgadd on Solaris, depot on HP-UX to install packages.

2. Query all the RPM Packages using rpm -qa

You can use rpm command to query all the packages installed in your system.

# rpm -qa
cdrecord-2.01-10.7.el5
bluez-libs-3.7-1.1
setarch-2.0-1.1
.
.
  • -q query operation
  • -a queries all installed packages

To identify whether a particular rpm package is installed on your system, combine rpm and grep command as shown below. Following command checks whether cdrecord package is installed on your system.

# rpm -qa | grep 'cdrecord'

继续阅读

Posted in Linux系统学习, Linux编程 | Leave a comment

CMake的install

CMake的install

CMake不止可以用来管理工程,编译工程,还可以安装工程。就是用install命令,但是记住他是cmake的命令,所以不要直接把它当作是一个linux的命令,那样就和linux的install命令混淆了,linux自带一个install命令,它和cp相类似。cmake的install命令可以按照下面的方式使用:

继续阅读

Posted in Linux编程 | Leave a comment

CMake完整示例

 CMake完整示例

以下文字全部摘抄在cmake的官网

https://cmake.org/cmake-tutorial/

————————————————–

Below is a step-by-step tutorial covering common build system issues that CMake helps to address. Many of these topics have been introduced in Mastering CMake as separate issues but seeing how they all work together in an example project can be very helpful. This tutorial can be found in the Tests/Tutorial directory of the CMake source code tree. Each step has its own subdirectory containing a complete copy of the tutorial for that step

A Basic Starting Point (Step1)

The most basic project is an executable built from source code files. For simple projects a two line CMakeLists file is all that is required. This will be the starting point for our tutorial. The CMakeLists file looks like:

cmake_minimum_required (VERSION 2.6)
project (Tutorial)
add_executable(Tutorial tutorial.cxx)

Note that this example uses lower case commands in the CMakeLists file. Upper, lower, and mixed case commands are supported by CMake. The source code for tutorial.cxx will compute the square root of a number and the first version of it is very simple, as follows:

// A simple program that computes the square root of a number
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (int argc, char *argv[])
{
  if (argc < 2)
    {
    fprintf(stdout,"Usage: %s number\n",argv[0]);
    return 1;
    }
  double inputValue = atof(argv[1]);
  double outputValue = sqrt(inputValue);
  fprintf(stdout,"The square root of %g is %g\n",
          inputValue, outputValue);
  return 0;
}

继续阅读

Posted in Linux编程 | Leave a comment

理解HTTPS

理解HTTPS

HTTPS是HTTP + TLS(SSLv3)

HTTP是明文传送服务器与客户端之间的通讯内容。TLS是加密协议,

TLS=Transport Layer Security(传输层安全协议)

有了TLS的加入,就使客户端和服务器之间的通讯变成保密的了。关于TLS的详细的内容,请参看国际工程任务组的官网,

继续阅读

Posted in 网络安全 | Leave a comment

linux的脚本的参数

linux的脚本的参数

运行linux脚本的时候可以传参数进去,那么在脚本里面怎么访问这些参数呢?

先说3个与之相关的内置变量

1. $0 $1 $2 ….

分别代表第一,第二,第三参数,后面的参数以此类推

$0代表的运行该脚本的使用的命令

继续阅读

Posted in Linux系统学习 | Leave a comment