Which IP address will be 100% invalid. That is, what 32-bit field can be used as the value of the fact that IP is not set correctly. Will be stored in struct sockaddr. If possible, I want to avoid checking .sa_family, they will be unacceptable for either IPv4 or IPv6, in the case of bringing to it. Unacceptable means that the probability of such an address is extremely small or absent. It will be used only for x64.

  • What is not satisfied with 127.0.0.1? - cpp_user
  • one
    255.255.255.255 broadcast. it can never be used - Saidolim
  • This piece is used in a proxy that is running on a machine that has a web server that is needed to configure this proxy. Accordingly, if for some reason the wrong ip is set for the back-end server (which you suggest may be 127.0.0.1) instead of a back-end server, the server responsible for the configuration of the proxy itself will be responsible, which is unacceptable. - Gurman
  • And where will the packets go if they are sent to the address 255.255.255.255? - Gurman
  • 127.0.0.1 - 127.255.255.255 is the loopback. IP is valid and is used for local port verification. All packages are returned. To another port does not go. - Saidolim

2 answers 2

It is not entirely clear how this will be used, but as the most obvious choice I would recommend 0.0.0.0 .
Advantages: there are no packets with such an outgoing address (i.e., in this narrow sense, the address cannot be assigned).
Disadvantage: when you try to connect a socket to this IP, via BSD sockets, we get to an arbitrary local machine interface. No, no, don't tell me about 127.0.0.1 - the address on the loopback interface. When opening 127.0.0.1 we also get on our machine, but the socket will sit specifically on the loopback interface, but where it will sit at opening 0.0.0.0 depends on the implementation.

If you want security in the sense that (even in the absence of checks for IP equality of a special value) connecting a socket to a special-purpose IP does not lead to anything, then take 127.255.255.255 - connect to the proposed IP fails in Linux even with root privileges . * In addition, it belongs to 127.0.0.0/8 and, therefore, under no circumstances will it go further than the first healthy router. And it is a broadcast address on the specified network, i.e., a packet with such an outgoing IP should not appear again (for comparison, outgoing 255.255.255.255 happens in DHCP packets).

What will happen when I convert these addresses to IPv6? Specify how the ghost is meant, and I will supplement the answer.


* If you do not do setsockopt ( sock , SOL_SOCKET, SO_BROADCAST, ...). If you do (as in the ping and netcat applications with the -b key), the API behavior for 127.255.255.255 does not differ from 255.255.255.255 : connect 127.255.255.255 . Only in the case of 255.255.255.255 packets actually go to the network, and in the case of 127.255.255.255 - they do not physically go anywhere (with a good loopback setting).

  • Yes, 127.255.255.255 is an interesting offer. And connect on INADDR_NONE == 255.255.255.255 does it pass? - avp
  • @avp: According to ICMP and with SO_BROADCAST - imagine. Try it out under Linux # strace ping -bc 1 255.255.255.255 - Incnis Mrsi
  • And connect - that (same tcp / sctp) and here? ICMP is essentially the same datagram protocol as UDP (through which the DHCP you mention works). - avp
  • one
    One - write system call in different guises. - avp
  • one
    Of course, I know that TCP cannot work with a broadcast destination. But they asked me to bring an invalid IP - I brought one without regard to the protocol, with reinsurance so that I can do it. - Incnis Mrsi

255.255.255.255 broadcast - it can never be used

PS If this is the right answer, let others help ...

UPDATE

from Gurman Thank you SD, I will do it. 254.255.255.255 + iptables

  • And where will the packets go if they are sent to the address 255.255.255.255? - Gurman
  • and I also think that 255.255.255.255 "at the end" IPv6 is quite valid. Or I'm wrong? - Gurman
  • 255.255.255.255 is the IP address of the mailing list. Pickets are not going anywhere. Router stop such packages. - Saidolim pm
  • @Gurman you are right, for IPv6 this is a valid IP but the task says that you need a 32 bit value. If they have IPv6, then you just need to fill in all the fields with units - Saidolim
  • This is not theirs but mine)) The router is far away. Where do they go inside my linux network stack? will not any server start responding to them? By analogy with the addresses 127.0.0.1 and 0.0.0.0 - Gurman