x11_parse_ip.c 455 B

12345678910111213141516171819202122
  1. /*
  2. * Try to make sense of a string as an IPv4 address, for
  3. * XDM-AUTHORIZATION-1 purposes.
  4. */
  5. #include <stdio.h>
  6. #include "putty.h"
  7. #include "ssh.h"
  8. bool x11_parse_ip(const char *addr_string, unsigned long *ip)
  9. {
  10. int i[4];
  11. if (addr_string &&
  12. 4 == sscanf(addr_string, "%d.%d.%d.%d", i+0, i+1, i+2, i+3)) {
  13. *ip = (i[0] << 24) | (i[1] << 16) | (i[2] << 8) | i[3];
  14. return true;
  15. } else {
  16. return false;
  17. }
  18. }