TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Socket programming – well commented examples

1 pointsby rainbowgardenabout 10 years ago

1 comment

greenyodaabout 10 years ago
I don&#x27;t understand how this code in client.c works:<p><pre><code> char filler[16] = {0}; ... filler[0] = (unsigned short)AF_INET; filler[2] = (unsigned short)htons(port); filler[4] = (unsigned long)htonl(INADDR_ANY); </code></pre> In C, sizeof(char) is one byte. Since htons() returns a short (the port number in network order), wouldn&#x27;t you get an overflow and lose data when you assign it to filler[2]?<p>(And similarly for filler[4].)
评论 #9089074 未加载