2

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);  
General Grievance
  • 4,555
  • 31
  • 31
  • 45
hel
  • 581
  • 10
  • 26
  • 1
    I'll bet most routers don't actually implement this service. Clients generally get this using DHCP these days, the ICMP method is a remnant of the days before BOOTP and DHCP were designed. – Barmar Mar 24 '16 at 01:37
  • Thanks! With DHCP, can I fetch address mask? I'm not familiar with DHCP. – hel Mar 24 '16 at 01:40
  • How are you initializing your network configuration if you're not using DHCP? – Barmar Mar 24 '16 at 01:41
  • How can I build DHCP request packet? – hel Mar 24 '16 at 01:41
  • DHCP is not normally used by application programs. It's used just when the network stack is configuring itself. The address mask is one of the many settings that's returned by the server. – Barmar Mar 24 '16 at 01:43
  • I see. Is there any way for application program to fetch address mask of certain host like ICMP address mask request? – hel Mar 24 '16 at 01:45
  • I've included a link to the DHCP RFC in my answer. – Barmar Mar 24 '16 at 01:45
  • The only address mask you generally need to know is your own. That's what Address Mask Request was intended for, and it's what DHCP supplies. So no, there's no way to fetch the address mask of some other network. – Barmar Mar 24 '16 at 01:46
  • I want to find topology in LAN. So address mask is helpful to determine subnet and network. – hel Mar 24 '16 at 01:47

1 Answers1

2

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.

Community
  • 1
  • 1
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Yeah, I've considered SNMP. But in my LAN, the router seems not to support SNMP. – hel Mar 24 '16 at 01:58
  • LIke I said, there's little need for it in consumer routers, network management is normally only needed for large organizations that use enterprise-grade routers. – Barmar Mar 24 '16 at 02:02