clinuxicmp

How to fetch address mask with ICMP


RFC 950, page 11:

A gateway receiving an address mask request should return it with the address mask field set to the 32-bit mask of the bits identifying the subnet and network, for the subnet on which the request was received.

I want to fetch a host address mask and build a ICMP address mask request packet to local gateway, and other IP. I use tcpdump -i eth0 icmp and find ICMP address mask request packet has been sent.But I haven't found any reponse. Is anything wrong? The main code is:

 struct icmp        *picmp;

 /* ICMP header */
 picmp = (icmp_t *)send_buf;
 picmp->icmp_type = ICMP_MASKREQ;    // Address Mask Request
 picmp->icmp_code = 0;
 picmp->icmp_id = pid;
 picmp->icmp_seq = npkt++;

 len = 12; // ICMP header length
 picmp->icmp_cksum = 0;
 picmp->icmp_cksum = in_cksum((u_short *)picmp, len);

 sendto(sock_fd, send_buf, len, 0, pr->p_addr, pr->addr_len);  

Solution

  • Address Mask is obsolete, as its primary function (hosts finding out their local network mask during network configuration) has been subsumed into Dynamic Host Configuration Protocol (DHCP RFC, Wikipedia). It's probably not implemented on most consumer routers. It has been officially deprecated in RFC 6918.

    If you want to query routers for configuration information, in order to learn the topology, the appropriate protocol is Simple Network Management Protocol (SNMP RFC, Wikipedia). This is a fairly complex protocol, so if you want to use it you should look for prewritten implementations (there are both libraries and CLI interfaces). However, routers generally require authorization of clients, so you won't be able to query random Internet routers for this; I'm not sure if consumer routers implement it at all, since it's uncommon to have central management of home routers.