Chapter 3: Standard BSD API Functions

 < Day Day Up > 



Overview

In this chapter, we take our first look at the details of the BSD Sockets API. This discussion is based on the Linux API, but this implementation follows the standard closely, so it will apply to other implementations as well. We focus on the basic Sockets API primitives first, and then in Chapter 4, Advanced Sockets Functions, we look at the more advanced functions. The Sockets functions that are discussed in this chapter are shown in Table 3.1.

Table 3.1: SOCKETS API FUNCTIONS DISCUSSED IN CHAPTER 3

Function

Description

socket

Creates a new socket endpoint

bind

Binds a local address to the socket

listen

Permits incoming connections for a server socket

accept

Accepts a new client connection for a server socket

connect

Connects to a server from a client socket

recv

Receives data through a socket

recvfrom

Receives data through a datagram socket

send

Sends data through a socket

sendto

Sends data through a datagram socket

close

Closes a socket endpoint

htons

Converts short to network byte order

ntohs

Converts short to host byte order

htonl

Converts long to network byte order

ntohl

Converts long to host byte order

inet_addr

Converts a dotted-notation string to a 32-bit network address

inet_ntoa

Converts a 32-bit network address to a dotted-notation string

inet_aton

Converts a dotted-notation string to a 32-bit network address

The following subsections illustrate the API calls, and discuss any special characteristics of their application and common problems that are associated in their use.

Note 

In this chapter, we demonstrate the calls as they appear in standard Linux distributions (which follows the BSD API). For embedded Sockets API implementations, the calls and include files may differ.



 < Day Day Up > 



BSD Sockets Programming from a Multi-Language Perspective
Network Programming for Microsoft Windows , Second Edition (Microsoft Programming Series)
ISBN: 1584502681
EAN: 2147483647
Year: 2003
Pages: 225
Authors: Jim Ohlund

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net