01-关于QNX network网络那些事情

1. socket/网络测试程序

socket_service.c

#include 
#include 
#include 
#include 

#include 
#include 
#include 


int main ( int argc , char ** argv )
{
    int rc = 0;
    int fd;
    struct sockaddr_un addr;
    socklen_t len;
    memset(&addr, 0, sizeof(addr));
    addr.sun_family = AF_UNIX;
    snprintf(addr.sun_path, sizeof(addr.sun_path), "/tmp/test_socket-0");

    unlink(addr.sun_path);

    fd = socket(AF_UNIX, SOCK_STREAM, 0);
    if (fd < 0)
    {
            printf("socket create failed\n");
            rc = -4;
            goto EXIT_FLAG;
    }


    rc = bind(fd, (struct sockaddr*)&addr, sizeof(addr));
    if (rc < 0)
    {
            printf("bind failed\n");
            rc = -5;
            goto EXIT_FLAG;
    }

    listen(fd, 10);

EXIT_FLAG:
    return rc;
}

1.1 bind 问题以及衍生的疑问。

编译socket 可执行程序,经常遇到bind失败,提示permission。

# ./socket_service
bind failed

怎么搞都不行。

涉及网络,还是得io-pkt处理下

#io-pkt-v6-hc -i1 -ptcpip prefix=/alt

运行: 

#SOCK=/alt socket_service

然后就成了。。。。。。

但是SOCK=/alt ifconfig 是本地127.0.0.1 啊,如果其他网卡传输呢? 囧

# SOCK=/alt ifconfig
lo0: flags=8049 mtu 33136
        inet 127.0.0.1 netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1

本机明明有几个网卡,为什么SOCK=/alt 下只有lo0?

# ifconfig
lo0: flags=8049 mtu 33136
        inet 127.0.0.1 netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
pflog0: flags=0 mtu 33136
emac0: flags=8943 mtu 1500
        capabilities=27
        enabled=0
        address: 02:04:00:00:01:02
        media: Ethernet none
        inet 192.168.1.1 netmask 0xffffff00 broadcast 192.168.1.255
        inet alias 0.0.0.0 netmask 0xff000000 broadcast 255.255.255.255
        inet6 fe80::4:ff:fe00:102%emac0 prefixlen 64 scopeid 0x21
vp0: flags=8943 mtu 1500
        capabilities rx=1f
        capabilities tx=7e
        enabled rx=1f
        enabled tx=0
        address: aa:aa:aa:aa:aa:aa
        media: Ethernet autoselect
        status: active
        inet 0.0.0.0 netmask 0xff000000 broadcast 255.255.255.255
        inet6 fe80::a8aa:aaff:feaa:aaaa%vp0 prefixlen 64 scopeid 0x22
bridge0: flags=41 mtu 1500
 

网卡信息: 

# nicinfo
pflog0:

emac0:
  EMAC Ethernet Device Ethernet Controller

  Link is DOWN

  Physical Node ID ........................... 020400 000102
  Current Physical Node ID ................... 020400 000102
  Current Operation Rate ..................... Unknown
  Active Interface Type ...................... MII
    Active PHY address ....................... 7
  Maximum Transmittable data Unit ............ 1514
  Maximum Receivable data Unit ............... 1514
  Promiscuous Mode ........................... On
  Multicast Support .......................... Enabled

  Packets Transmitted OK ..................... 0
  Bytes Transmitted OK ....................... 0
  Broadcast Packets Transmitted OK ........... 0
  Multicast Packets Transmitted OK ........... 0
  Memory Allocation Failures on Transmit ..... 0

  Packets Received OK ........................ 0
  Bytes Received OK .......................... 0
  Broadcast Packets Received OK .............. 0
  Multicast Packets Received OK .............. 0
  Memory Allocation Failures on Receive ...... 0

  Single Collisions on Transmit .............. 0
  Deferred Transmits ......................... 0
  Late Collision on Transmit errors .......... 0
  Transmits aborted (excessive collisions) ... 0
  No Carrier on Transmit ..................... 0
  Receive Alignment errors ................... 0
  Packets Dropped on receive ................. 0
  Ethernet Header length field mismatches .... 0
  Ethernet Headers out of range .............. 0
  Oversized Packets received ................. 0

vp0:
   Ethernet Controller

  Physical Node ID ........................... 000000 000000
  Current Physical Node ID ................... AAAAAA AAAAAA
  Current Operation Rate ..................... 0 kb/s half-duplex
  Active Interface Type ...................... Unknown
  Maximum Transmittable data Unit ............ 1500
  Maximum Receivable data Unit ............... 1500
  Promiscuous Mode ........................... Off
  Multicast Support .......................... Enabled

  Packets Transmitted OK ..................... 569738
  Bytes Transmitted OK ....................... 38252684
  Broadcast Packets Transmitted OK ........... 3814
  Multicast Packets Transmitted OK ........... 6
  Memory Allocation Failures on Transmit ..... 0

  Packets Received OK ........................ 757679
  Bytes Received OK .......................... 1098494853
  Broadcast Packets Received OK .............. 904
  Multicast Packets Received OK .............. 80
  Memory Allocation Failures on Receive ...... 0


bridge0:
 

> > > ※解答※: 解答此问题还得从qnx网络架构说起。

01-关于QNX network网络那些事情_第1张图片

结合QNX特性,如果要使用内核的网络,需要调用NetworkManager以及TCP/IP Manager 接口。

而我们第三方测试程序,使用网络资源的话需要io-pkt特殊处理。

即:io-pkt-v6-hc -ptcpip stacksize=8192,prefix=/alt

或者io-pkt-v6-hc -i1 -ptcpip prefix=/alt

然后通过[ SOCK=/alt + 指令 ] 来操作网络

通过上述指令后,SOCK=/alt 仅仅只有本地127.0.0.1 网段。如何添加其他网卡?

# SOCK=/alt ifconfig
lo0: flags=8049 mtu 33136
        inet 127.0.0.1 netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1

这个时候需要SOCK=/alt mount -T io-pkt 操作实现

如添加vp0接口:

SOCK=/alt mount -T io-pkt -o peer=/dev/qvm/la/la_to_host,bind=/dev/vdevpeer/vp0,mac=aaaaaaaaaaaa,mode=0660 /lib/dll/devnp-vdevpeer-net.so

# SOCK=/alt ifconfig
lo0: flags=8049 mtu 33136
        inet 127.0.0.1 netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
vp0: flags=8802 mtu 1500
        capabilities rx=1f
        capabilities tx=7e
        enabled rx=1f
        enabled tx=0
        address: aa:aa:aa:aa:aa:aa
        media: Ethernet autoselect
        status: active

设置vp0 ip 

 # SOCK=/alt ifconfig vp0 192.168.1.1

# SOCK=/alt ifconfig
lo0: flags=8049 mtu 33136
        inet 127.0.0.1 netmask 0xff000000
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
vp0: flags=8843 mtu 1500
        capabilities rx=1f
        capabilities tx=7e
        enabled rx=1f
        enabled tx=0
        address: aa:aa:aa:aa:aa:aa
        media: Ethernet autoselect
        status: active
        inet 192.168.1.1 netmask 0xffffff00 broadcast 192.168.1.255
        inet6 fe80::a8aa:aaff:feaa:aaaa%vp0 prefixlen 64 scopeid 0x11

 综上,不要问我怎么知道的,我也是孤独摸索了好几天。。。。。。。囧。 既然摸索成功了,就分享出来,免得同行同学在这里折腾浪费时间精力。

你可能感兴趣的:(QNX平台开发,汽车电子,qnx,net,qnx,网络,qnx,socket,io-pkt,bind)