• 常用网络知识


    1.字节序

    比如int a=0x12345678;

    大端字节序:低字节存在高位,高字节存在低位。78存在高位,12存在低位。

    小端字节序:低字节存在地位,高字节存在高位。78存在低位,12存在高位。

    x86通常是小端,arm通常大端。

    面试常考题:如何知道自己机器是大端还是小端?

    答:

    typedef union{

    unsigned short int value;

    unsigned char p[2];

    }to;

    to sp;

    sp.value=0xabcd;

    然后分别看p[0]等于0xab还是0xcd

    一般网络字节序是大端,机器字节序一般是小端

    #include<arpa/inet.h>里有4种字节序转化函数

    uint32_t htonl(uint32_t hostlong)            //长整型转换

    uint16_t htonl(uint16_t hostshort)            //短整型转换

    uint32_t ntohl(uint32_t netlong)            //长整型转换

    uint16_t ntohl(uint16_t netlong)            //短整型转换

    inet_pton();                        //字符串装换成网络ip

    inet_ntop();                        //网络ip转换成字符串

  • 相关阅读:
    Maven private reprository 更新
    Spark运行模式:cluster与client
    Spark脚本调用
    Java中hashCode与equal方法详解
    String值传递剖析
    Comparator 与 Comparable
    深入理解Java的接口和抽象类
    HitHub使用
    二叉树的递归与非递归遍历
    P1137 旅行计划
  • 原文地址:https://www.cnblogs.com/luoshiyong/p/10261585.html
Copyright © 2020-2023  润新知