device communication in terms of subnet mask and routing

Let's say I have host computer with two Ethernet adapters:

  • LAN adapter - connected to LAN, obtains IP address automatically.

  • Device adapter - with IP address 192.168.10.1, subnet mask 255.255.255.0.

  • I have also hardware device connected to Device adapter, it works like TCP/IP server, and configured with IP address 192.168.10.2, subnet mask 255.255.255.0.

    I have the following dumb rule to establish host-device comminication: set both subnet masks to 255.255.255.0, and define IP addresses that differ only by last component. That's fine, it works.

    Now I am reading the whole theory about TCP/IP communications (www.tcpipguide.com). How my case can be described in terms of network, subnet, mask, routing etc.? For example, host program sends UDP datagram to 192.168.10.2, port 1500. How this datagram is sent to the device? What decisions are done, what network components participate in the datagram delivering?


    the netmask can be thought as a bitmask for an IP address.

    if (address1 & netmask) == (address2 & netmask) then the 2 ip addresses are considered on the same subnet. (this expression can be written in many different ways...)

    the netmask is only a way to 'virtually' divide a network: the netmask is not part of the ip header, and is not transmitted on the wire. no-one knows the netmask of a device on the network, except the device itself. it is used internally inside the tcp stack of a device to take some basic routing decisions. note that there are other ways to define a subnet, which may not involve a netmask but achieves the same result: grouping multiple devices into a 'virtual' network.

    a router on which a device is plugged may even have a different definition of the netmask for this same device: it does not matter as long as the router is routing packets correctly. the netmask is used primarily to automatically compute some well-known addresses: for example, the broadcast address used for udp broadcast packets is computed from the ip address of a device and its netmask.

    in your specific case :

    there is no physical router, but your computer is a router (it routes packets internally to the different network interfaces). your computer contains a routing table which tells which outgoing interface a specific packet should use (on windows, try route print , on linux, as root, try route ).

    generally, the routing table is setup so that a packet goes out on the interface which is on the same subnet as the target device. the computer uses the above logical expression on each interface to determine if the destination is on the same subnet than this interface. if the expression is true, the packet goes out. each entry has a parameter (called a metric) which allows to chose the seemingly best interface in case multiple routes are possible.

    you should note that the routing table is dynamic: it can be modified manually, to add a specific route (eg if you know that a particular device is reachable through an interface but that device has an ip address which has no relation with this interface ip address/netmask). there are also some protocols (arp, dhcp...) used in a local network which broadcast routing informations, which are automatically handled by your system to modify the routing table.

    链接地址: http://www.djcxy.com/p/65792.html

    上一篇: 查找以太网连接的网络适配器名称

    下一篇: 设备通信就子网掩码和路由而言