From 2a039bd954ccb9104f31467a32c950512dc1f334 Mon Sep 17 00:00:00 2001 From: Hizenberg Date: Sun, 1 Sep 2024 17:37:42 +0530 Subject: [PATCH] more clean --- Conversion_Functions/readme.md | 84 +++++++++++++++++++++++++ System_Calls/readme.md | 18 ++++++ readme.md | 109 +-------------------------------- 3 files changed, 103 insertions(+), 108 deletions(-) create mode 100644 Conversion_Functions/readme.md create mode 100644 System_Calls/readme.md diff --git a/Conversion_Functions/readme.md b/Conversion_Functions/readme.md new file mode 100644 index 0000000..0f01e08 --- /dev/null +++ b/Conversion_Functions/readme.md @@ -0,0 +1,84 @@ +## Functions' used are :- + +### Functions for conversion between network and host byte order : + + 1. `uint32_t htonl( uint32_t hostlong )` + * Convert *hostlong* in **host byte order** to **network byte order**. + + 2. `uint16_t htons( uint16_t hostshort )` + * Convert *hostshort* in **host byte order** to **network byte order**. + + 3. `uint32_t ntohl( uint32_t netlong )` + * Convert *netlong* in **network byte order** to **host byte order**. + + 4. `uint16_t ntohs( uint16_t netshort )` + * Convert *netshort* in **network byte order** to **host byte order**. + + +### Functions for conversion between network representation to presentation representation : + +Since the IP address are presentable in form of (for eg.) 194.10.11.5 for IPv4, but the actual representation in network is in raw byte form. So, for easy conversion between the two, apis are provided for such conversion. + +1. `const char *inet_ntop(int af, const void* src, char* dst, socklen_t size)` + + Parameters : + + * af : + + Type : `int` + + Value : `AF_INET`, `AF_INET6`. + + Purpose : Used to specify type of address we are converting (IPv4 or IPv6). + + * src : + + Type : `const void *` + + Value : Buffer containing raw byte address in form. + + * dst : + + Type : `char *` + + Value : Buffer for storing the IP address in presentable form. + + * size : + + Type : `socklen_t` + + Value : `INET_ADDRSTRLEN` or `INET6_ADDRSTRLEN`. + + Purpose : Maximum size of buffer to store the IP address. + + Return type : + + * Type : `const char *` + + * Purpose : Pointer to *dst* if no error occured, otherwise returns null pointer and set global error variable `errno`. + +2. `int inet_pton(int af, const char *src, void *dst)` + + **Parameter :** + + * af : + + Type : `int` + + Value : `AF_INET`, `AF_INET6`. + + Purpose : Used to specify type of address we are converting (IPv4 or IPv6). + + * src : + + Type : `const char *` + + Value : String to convert address in presentable form to network compatible form. + + * dst : + + Type : `void *` + + Value : empty buffer. + + Purpose : To store address in network compatible form. \ No newline at end of file diff --git a/System_Calls/readme.md b/System_Calls/readme.md new file mode 100644 index 0000000..0dac68f --- /dev/null +++ b/System_Calls/readme.md @@ -0,0 +1,18 @@ +# System Calls : + +Below are the system calls that can be used to access network functionality. + +* **getaddrinfo()** : + + * Function prototye + + ``` + int getaddrinfo(const char *node, // e.g. "www.example.com" or IP + const char *service, // e.g. "http" or port number + const struct addrinfo *hints, + struct addrinfo **res); + ``` + + 1. node : + + Type : `const char *` \ No newline at end of file diff --git a/readme.md b/readme.md index 89892c0..eeda124 100644 --- a/readme.md +++ b/readme.md @@ -235,111 +235,4 @@ Let's first discuss about the important `struct` and then how we use apis' to es Value : `AF_INET` or `AF_INET6`. - Purpose : To distinguish address family it contains. - ---- - - - -## Functions' used are :- - -### Functions for conversion between network and host byte order : - - 1. `uint32_t htonl( uint32_t hostlong )` - * Convert *hostlong* in **host byte order** to **network byte order**. - - 2. `uint16_t htons( uint16_t hostshort )` - * Convert *hostshort* in **host byte order** to **network byte order**. - - 3. `uint32_t ntohl( uint32_t netlong )` - * Convert *netlong* in **network byte order** to **host byte order**. - - 4. `uint16_t ntohs( uint16_t netshort )` - * Convert *netshort* in **network byte order** to **host byte order**. - - -### Functions for conversion between network representation to presentation representation : - -Since the IP address are presentable in form of (for eg.) 194.10.11.5 for IPv4, but the actual representation in network is in raw byte form. So, for easy conversion between the two, apis are provided for such conversion. - -1. `const char *inet_ntop(int af, const void* src, char* dst, socklen_t size)` - - Parameters : - - * af : - - Type : `int` - - Value : `AF_INET`, `AF_INET6`. - - Purpose : Used to specify type of address we are converting (IPv4 or IPv6). - - * src : - - Type : `const void *` - - Value : Buffer containing raw byte address in form. - - * dst : - - Type : `char *` - - Value : Buffer for storing the IP address in presentable form. - - * size : - - Type : `socklen_t` - - Value : `INET_ADDRSTRLEN` or `INET6_ADDRSTRLEN`. - - Purpose : Maximum size of buffer to store the IP address. - - Return type : - - * Type : `const char *` - - * Purpose : Pointer to *dst* if no error occured, otherwise returns null pointer and set global error variable `errno`. - -2. `int inet_pton(int af, const char *src, void *dst)` - - **Parameter :** - - * af : - - Type : `int` - - Value : `AF_INET`, `AF_INET6`. - - Purpose : Used to specify type of address we are converting (IPv4 or IPv6). - - * src : - - Type : `const char *` - - Value : String to convert address in presentable form to network compatible form. - - * dst : - - Type : `void *` - - Value : empty buffer. - - Purpose : To store address in network compatible form. - ---- - -### System Calls :- - -Below are the system calls that can be used to access network functionality. - -* getaddrinfo() : - - 1. **Function prototye** - - ``` - int getaddrinfo(const char *node, // e.g. "www.example.com" or IP - const char *service, // e.g. "http" or port number - const struct addrinfo *hints, - struct addrinfo **res); - ``` - + Purpose : To distinguish address family it contains. \ No newline at end of file