Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

  • Print
  • + Share This
This chapter is from the book

Exercises

3.1 Why must value-result arguments such as the length of a socket address structure be passed by reference?

3.2 Why do both the readn and writen functions copy the void* pointer into a char* pointer?

3.3 The inet_aton and inet_addr functions have traditionally been liberal in what they accept as a dotted-decimal IPv4 address string: allowing from one to four numbers separated by decimal points, and allowing a leading 0x to specify a hexadecimal number, or a leading 0 to specify an octal number. (Try telnet 0xe to see this behavior.) inet_pton is much stricter with IPv4 address and requires exactly four numbers separated by three decimal points, with each number being a decimal number between 0 and 255. inet_pton does not allow a dotted-decimal number to be specified when the address family is AF_INET6, although one could argue that these should be allowed and the return value should be the IPv4-mapped IPv6 address for the dotted-decimal string (Figure A.10).

Write a new function named inet_pton_loose that handles these scenarios: If the address family is AF_INET and inet_pton returns 0, call inet_aton and see if it succeeds. Similarly, if the address family is AF_INET6 and inet_pton returns 0, call inet_aton and if it succeeds, return the IPv4-mapped IPv6 address.

  • + Share This
  • 🔖 Save To Your Account