Beej's Guide to Network Programming Using Internet Sockets
Brian "Beej" Hall
beej@beej.us
Version 2.3.23
November 5, 2005
Copyright © 2005 Brian "Beej Jorgensen" Hall
Contents
- 1. Intro
- 1.1. Audience
- 1.2. Platform and Compiler
- 1.3. Official Homepage
- 1.4. Note for Solaris/SunOS Programmers
- 1.5. Note for Windows Programmers
- 1.6. Email Policy
- 1.7. Mirroring
- 1.8. Note for Translators
- 1.9. Copyright and Distribution
- 2. What is a socket?
- 2.1. Two Types of Internet Sockets
- 2.2. Low level Nonsense and Network Theory
- 3. structs and Data Handling
- 3.1. Convert the Natives!
- 3.2. IP Addresses and How to Deal With Them
- 4. System Calls or Bust
- 4.1. socket()--Get the File Descriptor!
- 4.2. bind()--What port am I on?
- 4.3. connect()--Hey, you!
- 4.4. listen()--Will somebody please call
me?
- 4.5. accept()--"Thank you for calling port
3490."
- 4.6. send() and recv()--Talk
to me, baby!
- 4.7. sendto() and
recvfrom()--Talk to me, DGRAM-style
- 4.8. close() and
shutdown()--Get outta my face!
- 4.9. getpeername()--Who are you?
- 4.10. gethostname()--Who am I?
- 4.11. DNS--You say "whitehouse.gov", I say "63.161.169.137"
- 5. Client-Server Background
- 5.1. A Simple Stream Server
- 5.2. A Simple Stream Client
- 5.3. Datagram Sockets
- 6. Slightly Advanced Techniques
- 6.1. Blocking
- 6.2. select()--Synchronous I/O Multiplexing
- 6.3. Handling Partial send()s
- 6.4. Son of Data Encapsulation
- 6.5. Broadcast Packets--Hello, World!
- 7. Common Questions
- 8. Man Pages
- 8.1. accept()
- 8.2. bind()
- 8.3. connect()
- 8.4. close()
- 8.5. gethostname()
- 8.6. gethostbyname(), gethostbyaddr()
- 8.7. getpeername()
- 8.8. errno
- 8.9. fcntl()
- 8.10. htons(), htonl(),
ntohs(), ntohl()
- 8.11. inet_ntoa(), inet_aton()
- 8.12. listen()
- 8.13. perror(), strerror()
- 8.14. poll()
- 8.15. recv(), recvfrom()
- 8.16. select()
- 8.17. setsockopt(), getsockopt()
- 8.18. send(), sendto()
- 8.19. shutdown()
- 8.20. socket()
- 8.21. struct sockaddr_in, struct in_addr
- 9. More References
- 9.1. Books
- 9.2. Web References
- 9.3. RFCs
Privacy Policy
Privacy Policy and how we use information on this Web Site.
This Web Site does not collect nor store any user identifiable information.
The web server runs a stats package WUSAGE which gives the webmaster information related to visitors to this web site. However it is not possible to identify individual users with this information and the statistics are collected purely to analyze traffic to this web-site.
There is currently no mailing list maintained at this web site so users email addresses are not collected or stored.
We use outside ad companies to display ads on this site. These ads may contain cookies and/ or web beacons and are collected by the ad companies. We do not have access to this collected information.
Google, as a third-party vendor, uses cookies to serve ads on this site.
Google's use of the DART cookie enables it to serve ads to users based on their visit to this site and other sites on the Internet.
Users may opt out of the use of the DART cookie by visiting the Google ad and content network privacy policy.