套接字bind()使用不可用的地址

时间:2014-04-08 06:23:10

标签: c sockets bind icmp

当我尝试将不可用的地址绑定到icmp套接字时,就像没有分配给任何接口的东西一样,它会绑定到它而不会抛出任何错误。我做错了吗?

if (c->pc_saddr.ps_len == sizeof(saddr.sin_addr.s_addr)) {

    bzero(&saddr, sizeof(saddr));
    saddr.sin_len = sizeof(saddr);
    saddr.sin_family = AF_INET;
    bcopy(c->pc_saddr.ps_data, &saddr.sin_addr.s_addr,
          c->pc_saddr.ps_len);

    /*
     * note: if bind fails, just log it & let the kernel decide on the
     * source address to use.
     */
    if (bind(icmp_socket.ps_socket_fd, (struct sockaddr*)&saddr, sizeof(saddr)) != 0) {

        trace(TRACEFLAG_GENERAL, "%s: bind failed icmp: %s",
                   __FUNCTION__, strerror(errno));
    }
}

0 个答案:

没有答案