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