Dans Linux, le port n'est pas utilisable par bind() :
Si, il l'est :
422 int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
423 {
424 struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
425 struct sock *sk = sock->sk;
426 struct inet_sock *inet = inet_sk(sk);
427 struct net *net = sock_net(sk);
428 unsigned short snum;
429 int chk_addr_ret;
430 u32 tb_id = RT_TABLE_LOCAL;
431 int err;
432
433 /* If the socket has its own bind function then use it. (RAW) */
434 if (sk->sk_prot->bind) {
435 err = sk->sk_prot->bind(sk, uaddr, addr_len);
436 goto out;
437 }
...
495 /* Make sure we are allowed to bind here. */
496 if ((snum || !inet->bind_address_no_port) &&
497 sk->sk_prot->get_port(sk, snum))
http://lxr.free-electrons.com/source/net/ipv4/af_inet.c#L422static int do_ip_setsockopt(struct sock *sk, int level,
int optname, char __user *optval, unsigned int optlen)
{
...
case IP_BIND_ADDRESS_NO_PORT:
inet->bind_address_no_port = val ? 1 : 0;
break;
http://lxr.free-electrons.com/source/net/ipv4/ip_sockglue.cDonc oui tu peux appeler
bind avec un port 0 avec la bonne option, mais non, ça ne sert à rien, comme j'ai montré avec
listen.