Canonicalize Hostname: $[ and $]

Tokens that appear between a $[ and $] pair of operators in the RHS are considered to be the name of a host. That hostname is looked up by using DNS[252] and replaced with the full canonical form of that name. If found, it is then copied to the workspace, and the $[ and $] are discarded.

For example, consider a rule that looks for a hostname in angle brackets and (if found) rewrites it in canonical form:

 R < $* > $@ < $[ $1 $] > canonicalize hostname

Such canonicalization is useful at sites where users frequently send mail to machines using the short version of a machine’s name. The $[ tells sendmail to view all the tokens that follow (up to the $]) as a single hostname.

If the name cannot be canonicalized (perhaps because there is no such host), the name is copied as is into the workspace. For configuration files lower than 2, no indication is given that it could not be canonicalized (more about this soon).

Note that if the $[ is omitted and the $] is included, the $] loses its special meaning and is copied as is into the workspace.

The hostname between the $[ and $] can also be an IP address. By surrounding the hostname with square brackets ([ and ]), you are telling sendmail that it is really an IP address:

wash.dc.gov                      ← a hostname
[123.45.67.8]                    ← an IPv4 address
[IPv6:2002:c0a8:51d2::23f4]      ← an IPv6 address

When the IP address between the square brackets corresponds to a known host, the address and the square brackets are replaced with that host’s canonical ...

Get sendmail, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.