quest4tech.net

 

Network Functions

Winstock Byte-ordering Functions

 TERM  EXPLANATION
htonl Converts from host to network byte-order for a 32-bit (long) quantity .
htons Converts from host to network byte-order for a 16-bit (short) quantity .
ntohl Converts from network to host byte-order for a 32-bit (long) quantity .
ntohs Converts from network to host byte-order for a 16-bit (short) quantity .

 TERM  EXPLANATION
sendto Transmits data to a host address specified in a socket address structure, using a simple message buffer.
recvfrom Recieves data from a socker and optionally records the network address of the sending host, using a simple message buffer.

Select Functions The select function performs synchronous I/O multiplexing by monoitoring the status of multiple sockets.

 TERM  EXPLANATION
FD_ZERO Initialises a set of socket handles.
FD_SET Adds a socket handle to a set.
FD_ISSET Returns a non-sero value (true) if the socket handle is set and zero (false) if the socket handle is not set.
FD_CLR Removes a socket handle from a set.

SOCKET FUNCTIONS

The following tables are from my notes on using socket functions on a UNIX system. An example of how each socket function was used is given underneath the main equation.


FUNCTION EXPLANATION
socket_handle = socket(protocol_family, socket_type, protocol);

fd = (AF_INET, SOCK_STREAM, 0);
Creates a socket
result = bind (socket_handle, local_socket_address, address_length);

result = (fd, (struct sockaddr*)&addr, sizeof(addr));
Associates a local address (combination of host address and protocol port) with a socket.
result = listen(socket_handle, queue_length);

result = (fd, 5);
Listen for incoming service requests, acknowledges them and places them into a queue of given length.
result = select(number_of_sockets, readable_sockets, writeable_sockets, error_sockets, max_time);

result = select(MaxFds, &setReadTest, &setWriteTest, &setErrorTest, &time_out);
 
result = accept(socket_handle, socket_address, address_length);

result = accept(fd, (struct sockaddr*)&addr, &addlen);
Accepts function lets the server accept connections from a client program. When a request arrives at the specified socket, the socket implementation fills the socket address structure with the address of the client that requested the connection.

 

FUNCTION EXPLANATION
return_value = sendto(socket_handle, message_buffer, buffer_length, special_flags, socket_address_structure, address_structure_length);
 
 
return_value = sendto(fd, icmp, 8, 0, (struct sockaddr*) &addr, sizeof(addr));
Function sendto is used on an unconnected socket. Remote host information is stored in the socket-data structure, pointed to in the fifth parameter in the sendto function.

return_value = recvfrom(socket_handle, message_buffer, buffer_length, special_flags, socket_address_structure, address_structure_length));
 
 
 
return_value = recvfrom(fd, recbuff, sizeoff(recvbuff), 0, (struct sockaddr*) &addr, &addrlen);
Retrieves data from a protocol port and on an unconnected socket (SOCK_DGRAM), and extracts from the datagram header the network address of the host that sent the datagram. The recvfrom function copies the network address of the host that sent the datagram into the socket address structure pointed to in the fifth parameter.

UK Amazon

USA Amazon


BOOKS

data communications and network book for sale Advance Programming in the UNIX environment by Richard Stevens. Fully comprehensive guide that I used for my design and programing work on UNIX systems. Read the reviews and buy the book at Amazon, click  here for UK  or   here for USA.
quest4tech.net Index

 Main Index

UK SPONSERS

USA SPONSERS