当我尝试将不可用的地址绑定到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));
}
}