




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















-^ A^ socket^ is^ an^ abstraction
of^ a^ communication^ endpoint
-^ Applications^ use^ socket
descriptors^ to^ access^ sockets
-^ Socket^ descriptors^ are
implemented^ as^ file^ descriptors
in the^ UNIX^ System • Many^ of^ the^ functions^
that^ deal^ with^ file^ descriptors, such^ as^ read^ and^ write
,^ work^ with^ a^ socket^ descriptor
-^ Uniquely^ identified^ by
an^ Internet^ address,^ an
end‐to‐end protocol^ (TCP,^ UDP,^ SCTP),
and^ a^ port^ number
4
^ struct in_addr{^ in_addr_t s_addr;^ /*^32
‐bit^ IPv4^ address^ /^ /^ network
byte ordered^ /^ }; struct sockaddr_in{ uint8_t^ sin_len;^ /^ length^ of
structure^ (16)^ */ sa_family_t sin_family;^
/*^ AF_INET^ / in_port_t sin_port;^ /^16
‐bit^ TCP^ or^ UDP^ port^ number
/ /^ network^ byte^ ordered
*/ struct in_addr sin_addr;
/*^32 ‐bit^ IPv4^ address^ / /^ network^ byte^ ordered
/ char^ sin_zero[8];^ /^ unused
*/ };
Data^ types^ for^ the^ s_addr,
sin_family and^ sin_port members. The^ in_addr_t must^
be^ unsigned^ integer^ type
of^ at^ least 32 bits. in_port_t at^ least^16
bits. And^ sa_family_t can
be^ any^ unsigned^ integer
type. The^ latter^ is^ normally
an^8 ‐bit^ unsigned^ integer
if^ the length^ field^ is^ supported. Otherwise^ unsigned
16 ‐bit^ integer^ if^ not^ supported. Both^ the^ IPv4^ address
and^ the^ TCP^ and^ UDP
port^ numbers are^ stored^ in^ the^ structure
in^ network^ byte^ order.
The^ SIN6_LEN^ constant
must^ be^ defined^ if^ the system^ supports^ the
length^ member^ for^
socket^ address structure. IPv6^ is^ AF_INET6^. ^128 bit^ sin6_addr member. The^ sin_flowinfo member
is^ divided^ into^ two^ fields: The^ low‐order^20 bytes
are^ the^ flow^ label The^ high‐order^12 bytes
are^ reserved Research^ topic The^ sin6_scope_id^ identifies
the^ scope^ zone^ in^ which scope^ is^ meaningful.
IPv6^ Socket^ Address
Structure struct in6_addr {^ uint8_t^ s6_addr[16];
/*^128 ‐bit^ IPv6^ address
}; #define^ SIN6_LEN^ /*^ required^ for^ compile‐time
tests^ / struct sockaddr_in6 { uint8_t^ sin6_len;^ /^ length
of^ this^ struct (28)^ */ sa_family_t sin6_family;
in_port_t sin6_port;^ /*
transport^ layer^ port#^
uint32_t^ sin6_flowinfo;
/*^ flow^ information,^ undefined
struct in6_addr^ sin6_addr;
/*^ IPv6^ address^ */ uint32_t^ sin6_scope_id;
/*^ set^ of^ interfaces^ for
a^ scope^ */ };
#include^ <netinet/in.h>uint16_t^ htons(uint16_t^ host16bitvalue) ; uint32_t^ htonl(uint32_t^ host32bitvalue) ;
Both return: value in network byte order uint16_t^ ntohs(uint16_t^ net16bitvalue) ; uint32_t^ ntohl(uint32_t^ net32bitvalue) ;
Both return: value in host byte orderdocsity.com
-^ There^ are^ two^ groups
-^ These^ functions^ are
19
#include^ <strings.h> void^ bzero(void^ *dest,^ size_t
nbytes); void^ bcopy(const^ void^ *src,^ void
*dest,^ size_t^ nbytes); int^ bcmp(const^ void^ *ptr1,^ const
void^ *ptr2,^ size_t^ nbytes);^ Returns: 0 if equal, nonzero if unequal
memset sets^ the^ specified
number^ of^ bytes^ to^ the
value^ c in^ the^ destination. memcpy is^ similar^ to
bcopy,^ but^ the^ order^ of
the^ two pointer^ arguments^ is^ swapped.
bcopy correctly^ handles overlapping^ fields,^ while
the^ behavior^ of^ memcpy is undefined^ if^ the^ source
and^ destination^ overlap.
The^ ANSI^ C memmove function^ must
be^ used^ when^ the^ fields
overlap. memcmp compares
two^ arbitrary^ byte^ strings
and^ returns 0 if^ they^ are^ identical. If^ not^ identical,^ the^ return
value^ is either^ greater^ than^0 or
less^ than^ 0,^ depending
on^ whether the^ first^ unequal^ byte^
pointed^ to^ by^ ptr1^ is^ greater
than^ or less^ than^ the^ corresponding
byte^ pointed^ to^ by^ ptr2.