CentOS 上安装新版本 python

请看: 安装python以及解决版本问题

但在安装新版本后,yum不能正常使用了。原因是yum是基于默认的python版本运行的,例如CentOS6.2基于python2.6。但我们安装版本后建立了链接,覆盖掉了默认python调用,导致yum脚本无法正常调用到自己想要的版本。

解决方案

vim /usr/bin/yum

将第一行 #!/usr/bin/python 修改成 #!/usr/bin/python2.6

安装新版本python

wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar xjf Python-2.7.3.tar.bz2
cd Python-2.7.3
./configure
make
make atlinstall

这时 python2.7.3 版本已经安装成功了。 但调用 python –version 依然会显示并使用旧版本

解决办法就是重新建立一个链接并覆盖掉旧的

ln -s /usr/local/bin/python2.7 /usr/bin/python -f

再调用 python –version 显示结果

[root@centos]# python --version
Python 2.7.3

至此,问题解决 :)

压缩

enData = zlib.compress(data)[2:-4]

对应:

compress2(dstbuf, &dstLen, strSrc, srcLen, 6);

解压

deData = zlib.decompress(enData, -zlib.MAX_WBITS)

对应:

bool gzipInflate( const std::string& compressedBytes, std::string& uncompressedBytes ) {
    if ( compressedBytes.size() == 0 ) {
        uncompressedBytes = compressedBytes ;
        return true ;
    }

    uncompressedBytes.clear() ;

    unsigned full_length = compressedBytes.size() ;
    unsigned half_length = compressedBytes.size() / 2;

    unsigned uncompLength = full_length ;
    char* uncomp = (char*) calloc( sizeof(char), uncompLength );

    z_stream strm;
    strm.next_in = (Bytef *) compressedBytes.c_str();
    strm.avail_in = compressedBytes.size() ;
    strm.total_out = 0;
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;

    bool done = false ;

    //if (inflateInit2(&strm, (16+MAX_WBITS)) != Z_OK)
    if (inflateInit2(&strm, -MAX_WBITS) != Z_OK)
    {
        free( uncomp );
        return false;
    }

    while (!done) {
        // If our output buffer is too small
        if (strm.total_out >= uncompLength ) {
            // Increase size of output buffer
            char* uncomp2 = (char*) calloc( sizeof(char), uncompLength + half_length );
            memcpy( uncomp2, uncomp, uncompLength );
            uncompLength += half_length ;
            free( uncomp );
            uncomp = uncomp2 ;
        }

        strm.next_out = (Bytef *) (uncomp + strm.total_out);
        strm.avail_out = uncompLength - strm.total_out;

        // Inflate another chunk.
        int err = inflate (&strm, Z_SYNC_FLUSH);
        if (err == Z_STREAM_END) done = true;
        else if (err != Z_OK)  {
            break;
        }
    }

    if (inflateEnd (&strm) != Z_OK) {
        free( uncomp );
        return false;
    }

    for ( size_t i=0; i<strm.total_out; ++i ) {
        uncompressedBytes += uncomp[ i ];
    }
    free( uncomp );
    return true ;
}

Linux使用gcc编译使用zlib库的代码时,使用 -lz 来链接(link) zlib 库。

否则就会出现类似 undefined reference to `deflateInit_’ 的错误

当调用tcpdump时,出现错误:tcpdump: USB link-layer type filtering not implemented

原因

说明系统可能有多块网卡共存。

需要指定工作网卡才能开始截包,使用参数举例

[root@centos]# tcpdump -i eth0 udp port 53

在实际使用中例子中“eth0”“udp”“53”等参数,要根据实际需要来进行修改。 虽然一般单网卡默认名称应该是eth0,但也有其他情况。实际中要使用ifconfig查看自己需要使用的网卡。

错误原因

我手上一个项目本身采用gcc编译。后来因为代码功能需要移植到g++中时,出现了 “inet_addr” was not declared in this scope 这个错误。

解决方案

// 添加该头文件
#include <arpa/inet.h>

如果出现下面错误:

error: string: No such file or directory
error: vector: No such file or directory
  • 说明在将g++项目用gcc编译