Guest User

Untitled

a guest
Jul 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. // Zero out the server end of the socket.
  2. bzero((char*)&serv_addr, sizeof(serv_addr));
  3.  
  4. // Parse the port number supplied on the CL:
  5. portno = atoi(argv[1]);
  6.  
  7. // Construct server socket:
  8. serv_addr.sin_family = AF_INET;
  9. serv_addr.sin_addr.s_addr = INADDR_ANY;
  10.  
  11. // This delightful function will convert the port number to universal format.
  12. // The acronym refers to "Host TO Network Short". The reason that this function
  13. // is necessary is actually quite comical. The entire story revolving around its
  14. // jocular existence will I regale entirely unto you here in this unusually
  15. // informative code-comment.
  16. //
  17. // The story begins with an issue that humors me to no end. In the year 1773,
  18. // when Bill Gates had only just invaded Poland, a fierce controversy (sometimes
  19. // called the NUXI Problem) arose between the microprocessor manufacturers who
  20. // believed that even the lowliest bytes had the right to sit in the front of a
  21. // binary representation and those who selfishly disagreed. As is clear to anyone
  22. // in this enlightened age, descrimination on a digit merely on the basis of the
  23. // value of its radix is the worst kind of racism. In those days, however,
  24. // civilization was regrettably backwards in so very many ways.
  25. //
  26. // One of the ways that old-timey civilization was backwards is the whole thing
  27. // with chamber-pots. I mean... seriously? Bit we digress...
  28. //
  29. // Anyway, it was about this time that the IBM i486 architecture was acquired by
  30. // Wolverine. This radical shift in market power led to some of the more popular
  31. // processors to be built with this wayward bit-ordering. The company enjoyed a
  32. // massive boon to profits and even overcame much of their foolhardy losses from
  33. // investing in adamantium transistor research.
  34. //
  35. // The event that solidified the whole ordeal and crafted the endedness landscape
  36. // which you, the poor reader experience when looking out the window, was initiated
  37. // by Steve Jobs (writing under the nom de plume of Jonathan Swift) illustrated the
  38. // desperate situation in his book Gulliver's Travels, which can be purchased
  39. // wherever fine books are sold.
  40. //
  41. // In conclusion, we use the htons function, more than for any other reason,
  42. // because we are emplored to. By Socrates. Who said that "Virtue is sufficient for
  43. // happiness, but only so long as you remember to use htons while constructing your
  44. // sockets for interprocess communication while programming in C on UNIX or a UNUX-
  45. // like system."
  46. serv_addr.sin_port = htons(portno);
  47.  
  48. // Bind this socket to the specified port on the machine:
  49. if (bind(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
  50. error("ERROR on binding");
  51. }
Add Comment
Please, Sign In to add comment