<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mahmoud Abdel Malek on Medium]]></title>
        <description><![CDATA[Stories by Mahmoud Abdel Malek on Medium]]></description>
        <link>https://medium.com/@mahmoud-malek?source=rss-d94e4e3ff891------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*o9p0DmEmqzb6_dgj</url>
            <title>Stories by Mahmoud Abdel Malek on Medium</title>
            <link>https://medium.com/@mahmoud-malek?source=rss-d94e4e3ff891------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:34:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mahmoud-malek/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What happens when you type google.com in your browser and press Enter]]></title>
            <link>https://medium.com/@mahmoud-malek/what-happens-when-you-type-google-com-in-your-browser-and-press-enter-d1964acf731d?source=rss-d94e4e3ff891------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1964acf731d</guid>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[tcp-ip]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Mahmoud Abdel Malek]]></dc:creator>
            <pubDate>Sat, 13 Apr 2024 19:01:12 GMT</pubDate>
            <atom:updated>2024-04-13T19:01:12.659Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*3SLWUjC0IgtJo2AzGr1zhQ.jpeg" /></figure><p>We will discuss in a simple &amp; deep way what happens when you type https://www.google.com in your browser and press Enter. ❤️</p><p>Before we start the journey it’s better to know what are common terminologies and acronyms.</p><p><strong>Protocol: </strong>is essentially a set of rules that govern how data is transmitted and received between devices on a network. (eg. format and sequence of messages exchanged between devices)</p><p><strong>IP</strong> <strong>(Internet Protocol)</strong>: is a fundamental protocol used in computer networks to enable communication between devices. It provides a unique address for each device connected to a network, known as an IP address. These addresses are used to identify and locate devices on the network, allowing them to send and receive data packets to and from each other</p><p><strong>DNS (Domain Name System)</strong>: A system that translates domain names (e.g., example.com) into <strong>IP</strong> addresses, allowing users to access websites and other internet resources using human-readable names.</p><p><strong>DNS Request: </strong>A DNS (Domain Name System) request is a query made by a client device to a DNS server to translate a domain name (e.g., example.com) into an IP address. This translation allows the client to locate and connect to the desired web server or other network resources.</p><p><strong>TCP/IP (Transmission Control Protocol/Internet Protocol)</strong>: The suite of protocols used for communication over the internet and most networks. It provides end-to-end data communication, ensuring that data packets are delivered reliably and in the correct order.</p><p><strong>HTTP (Hypertext Transfer Protocol):</strong> The protocol used for transferring hypertext documents on the World Wide Web. It defines how web browsers and servers communicate with each other.</p><p><strong>HTTPS (Hypertext Transfer Protocol Secure):</strong> An extension of HTTP that encrypts data transmitted over the internet, providing a secure connection between a web browser and a web server.</p><p><strong>HTTPS/SSL (Hypertext Transfer Protocol Secure/Secure Sockets Layer):</strong> HTTPS is an extension of HTTP that encrypts data transmitted between a web browser and a web server. SSL/TLS (Secure Sockets Layer/Transport Layer Security) protocols are used to establish a secure connection, ensuring that data exchanged between the client and server remains confidential and cannot be intercepted or tampered with by malicious third parties.</p><blockquote><strong>SSL (Secure Sockets Layer):</strong></blockquote><ul><li>SSL was the original protocol developed by Netscape in the mid-1990s to secure communications over the internet.</li><li>It provides security features such as encryption (to protect data in transit), data integrity (to ensure that data remains unaltered during transmission), and authentication (to verify the identity of the server).</li><li>SSL uses cryptographic algorithms to encrypt data, typically using symmetric encryption for data transmission and asymmetric encryption for key exchange and authentication.</li><li>SSL has several versions, including SSL 1.0 (which was never publicly released), SSL 2.0 (which had security vulnerabilities), SSL 3.0 (which addressed some of the vulnerabilities in SSL 2.0), and TLS 1.0 (which was based on SSL 3.0 and introduced significant improvements).</li></ul><blockquote><strong>TLS (Transport Layer Security):</strong></blockquote><ul><li>TLS is the successor to SSL and was developed by the Internet Engineering Task Force (IETF) to address the limitations and vulnerabilities of SSL.</li><li>TLS builds upon the foundation of SSL and provides enhanced security, improved performance, and better flexibility.</li><li>Like SSL, TLS provides encryption, data integrity, and authentication features to secure communications over the internet.</li><li>TLS has several versions, including TLS 1.0, TLS 1.1, TLS 1.2, and TLS 1.3, each introducing improvements in security and performance. TLS 1.3, the latest version, further enhances security and reduces latency by eliminating unnecessary cryptographic operations.</li></ul><p><strong>Load Balancer:</strong> A load balancer is a device or software component that distributes incoming network traffic across multiple servers or resources to ensure optimal resource utilization, improve responsiveness, and enhance reliability. It helps prevent server overload and downtime by evenly distributing workload among server instances.</p><p><strong>Web Server:</strong> A web server is a software application or hardware device that stores, processes, and delivers web content (such as web pages, images, videos) to client devices upon request. It uses HTTP or HTTPS protocols to communicate with web browsers and serves as the backbone of the World Wide Web.</p><p><strong>Application Server:</strong> An application server is a software framework or platform that provides an environment for running and managing web applications. It handles tasks such as executing application code, managing database connections, session management, and load balancing. Application servers facilitate the deployment and scalability of web applications.</p><p><strong>Database:</strong> A database is an organized collection of structured data stored electronically in a computer system. It allows for efficient data storage, retrieval, modification, and management. Databases are commonly used to store and manage various types of information in applications, websites, and enterprise systems.</p><p>Those are the basic concepts, we will explain more details, and all will become easy to comprehend.</p><p><strong>Now Let’s talk a look at when happens when you type google.com, and hit enter.</strong></p><ol><li><strong>DNS Resolution:</strong> When you type “google.com” in your browser, it sends a DNS request to a DNS server to resolve the domain name to its corresponding IP address. This step is crucial for locating the target server on the internet.</li><li><strong>Establishing TCP Connection</strong>: Once the browser obtains the IP address of “google.com,” it establishes a TCP (Transmission Control Protocol) connection with either Google’s server directly or with a load balancer that distributes incoming traffic among multiple servers. This ensures a reliable, ordered, and error-checked delivery of data packets between the client (your browser) and the server.</li><li><strong>SSL/TLS Handshake:</strong> As part of the TCP connection establishment, an SSL/TLS handshake occurs between your browser and Google’s server. This process involves negotiating encryption algorithms, exchanging cryptographic keys, and verifying the server’s identity using SSL/TLS certificates. This encryption secures the data exchanged between your browser and the server, protecting it from eavesdropping and tampering by malicious actors. It’s important to note that SSL/TLS certificates are essential for establishing trust and ensuring the authenticity of the server. Without proper SSL/TLS configuration, the connection may be vulnerable to attacks like Man-in-the-Middle (MITM).</li><li><strong>Firewall Filtering:</strong> Depending on the network setup, there may be firewalls or other security measures in place that filter and monitor incoming and outgoing traffic. These firewalls can be configured to inspect packets, enforce access policies, and protect against various threats. Both your computer’s firewall and Google’s servers may have such protections in place to safeguard against unauthorized access and malicious activity.</li><li><strong>Request and Response Exchange:</strong> With the TCP connection established and secured, your browser can now send HTTP requests to Google’s server, such as requesting the homepage of “google.com.” The server processes these requests and sends back HTTP responses containing the requested web content, such as HTML, CSS, JavaScript, and images. This communication continues as your browser fetches additional resources and interacts with the website’s functionality.</li></ol><blockquote>thank you for your great reading 💪🏻💕</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1964acf731d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unix Command Line Interpreter (Simple Shell)]]></title>
            <link>https://medium.com/@mahmoud-malek/unix-command-line-interpreter-simple-shell-3af4755e7df9?source=rss-d94e4e3ff891------2</link>
            <guid isPermaLink="false">https://medium.com/p/3af4755e7df9</guid>
            <category><![CDATA[alx-blog]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[bash]]></category>
            <dc:creator><![CDATA[Mahmoud Abdel Malek]]></dc:creator>
            <pubDate>Sun, 01 Oct 2023 21:12:40 GMT</pubDate>
            <atom:updated>2023-10-05T16:05:53.033Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>How to code your own simple shell</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-VwTa91m_rCsatXG1Ikhg.png" /><figcaption><a href="https://github.com/Swordfish90/cool-retro-term">source</a></figcaption></figure><p><strong>In this article I’m going to use C programming language</strong></p><blockquote>0x01 — What you need to know before you start</blockquote><ul><li>Basics of programming</li><li>Basics of C</li><li>Basics of UNIX command line</li><li>Unix <strong>system calls</strong></li></ul><blockquote>0x02 — Highly important functions &amp; system calls you will need</blockquote><p>Search and make sure you understand the following functions and system calls.</p><p>They are<strong> super important.</strong></p><ul><li>access (man 2 access)</li><li>chdir (man 2 chdir)</li><li>close (man 2 close)</li><li>closedir (man 3 closedir)</li><li>execve (man 2 execve)</li><li>exit (man 3 exit)</li><li>_exit (man 2 _exit)</li><li>fflush (man 3 fflush)</li><li>fork (man 2 fork)</li><li>free (man 3 free)</li><li>getcwd (man 3 getcwd)</li><li>getline (man 3 getline)</li><li>getpid (man 2 getpid)</li><li>isatty (man 3 isatty)</li><li>kill (man 2 kill)</li><li>malloc (man 3 malloc)</li><li>open (man 2 open)</li><li>opendir (man 3 opendir)</li><li>perror (man 3 perror)</li><li>read (man 2 read)</li><li>readdir (man 3 readdir)</li><li>signal (man 2 signal)</li><li>stat (__xstat) (man 2 stat)</li><li>lstat (__lxstat) (man 2 lstat)</li><li>fstat (__fxstat) (man 2 fstat)</li><li>strtok (man 3 strtok)</li><li>wait (man 2 wait)</li><li>waitpid (man 2 waitpid)</li><li>wait3 (man 2 wait3)</li><li>wait4 (man 2 wait4)</li><li>write (man 2 write)</li></ul><blockquote>0x03 — Now, I’m going to explain my approach</blockquote><p>The hardest part of this project for me, was about <strong>how to start</strong>, notice I’m not going to explain how to implement specific function or built-in commands, I’m just clarifying the idea of how things work, the big picture, Also i will provide some code examples to help you better understand.</p><p>I start by checking if the input comes from interactive mode or non- interactive mode, or files.</p><h4><strong>Example #0</strong></h4><pre>interactive vs non-interactive vs files<br>interactive mode<br>___________________<br>$ ./hsh<br>($) /bin/ls<br>hsh main.c shell.c<br>($)<br>($) exit<br>$<br><br>non interactive mode<br>_____________________<br>$ echo &quot;/bin/ls&quot; | ./hsh<br>hsh main.c shell.c test_ls_2<br>$<br>$ cat test_ls_2<br>/bin/ls<br>/bin/ls<br>$<br>$ cat test_ls_2 | ./hsh<br>hsh main.c shell.c test_ls_2<br>hsh main.c shell.c test_ls_2<br><br>files mode<br>____________________<br>$ ./hsh scriptname<br>//doing something in that script</pre><p>You can check the modes by (isatty) function, and you can check if the input is files by argc, if argc (number of arguments) is bigger than one, that means the user has entered the file name to read from.</p><p>Then, you will need to keep asking the user to enter commands and never stop that until the user exits or presses a special key or something. So I’ve created an infinite loop. it will only exit when a user sends signals that stop the shell, or a user enters (exit) command to exit from the shell.</p><p>I only print my prompt in the interactive mode. the prompt is just any string to show every time a user enters a command.</p><p>Next, I read line by line from whatever file or stdin, etc.</p><h4><strong>Example #1</strong></h4><pre>int main(int ac, char **av)<br>{<br> if (ac == 2)<br>  args.fd = open(av[1], O_RDONLY);<br><br> if (args.fd == -1)<br> {<br>  print_error(&amp;args);<br>  exit(1);<br> }<br><br>  while (1)<br> {<br>    /*if interactive print the prompt (eg. myshell-&gt;)*/<br><br>    if (interactive(ac))<br>       write(STDOUT_FILENO, args.prompt, _strlen(args.prompt));<br><br>  read_chars = _getline(&amp;args.line, &amp;size, args.fd);<br><br>  /*EOF: enf of file or Ctrl + D*/<br>  if (read_chars == -1)<br>  {<br>   free(args.line);<br>   exit(0);<br>  }<br><br>  /* case of Empty line*/<br>  if (read_chars == 1 &amp;&amp; args.line[0] == &#39;\n&#39;)<br>  {<br>   free(args.line);<br>   continue;<br>  }<br><br>  /* normal cases */<br><br>  args.line[read_chars - 1] = &#39;\0&#39;;<br>  remove_comments(&amp;args);<br>  make_commands(&amp;args.commands, args.line);<br>  variable_replacement(&amp;args);<br>  execute(&amp;args);<br> }</pre><p>The above (interactive) function checks if (isatt() &amp;&amp; ac == 1), That means, it is not files and interactive.</p><p><strong><em>Note</em></strong><em>: all examples are not complete and do not handle all cases.</em></p><p>You may notice that in the previous code, in normal cases, I do some stuff using some functions.<br><strong>let’s discuss what I’m doing:</strong></p><p>First of all, I’ve created a struct that holds all my variables i need in the entire shell. It really has almost every variable I need.<br>Why is it good? and what are the benefits of that?<br>1- It makes functions looks simple (eg. instead of writing a function that has lots of parameters, I’ve just created the most of the functions have one parameter ( the struct), I called this struct args.</p><p>2- It makes your code more readable.</p><p>3- Less code you need to write every time, and so on.</p><p>What are these functions?</p><pre>args.line[read_chars - 1] = &#39;\0&#39;;<br>  remove_comments(&amp;args);<br>  make_commands(&amp;args.commands, args.line);<br>  variable_replacement(&amp;args);<br>  execute(&amp;args);</pre><h4><strong>remove_comments</strong>:</h4><p>This function takes the line input, and just replace the first character( ‘#’ )by the null terminator( ‘\0’ )so that we kinda cut the line, everything after ‘#’ is ignored.</p><h4><strong>make_commnads</strong>:</h4><p>This function does a great job, it returns a linked list of commands<br>each node of this list, contain a 2D array, and the first string in the 2D array is the name of the program, and other strings are the arguments of the command if exists,</p><p>Notice that the command separators like ( &amp;&amp;, ||, ; , | , &gt;&gt;, &lt; , and so on)</p><p>That means’ i’m handling features like &amp;&amp;, ||, and pipes, redirections. but you don’t have to support all of that, I’m just tell you why i made a linked list of commands, that is because I assume that the user will enter advanced features.</p><h4><strong>Example #2</strong></h4><pre>list *make_commands(list **commands, char *line)<br>{<br> char **cmds = NULL;<br> char **comand = NULL;<br> int i = 0;<br><br>//split_logical- takes string and split it into array of strings based on<br>//separators like ( &amp;&amp;, ||, ; , | , &gt;&gt;, &lt; , and so on)<br> cmds = split_logical(line);<br> if (!cmds)<br>  return (NULL);<br><br><br> for (; cmds[i] != NULL; i++)<br> {<br>    //then each command in the array of strings that we got<br>    //from above split_logical we will split it based on spaces so that <br>    // we get the command and its arguemnts<br>    comand = split(cmds[i], &quot; &quot;);<br>    if (comand == NULL)<br>    {<br>     free_list(*commands);<br>     free_2D(cmds);<br>     return (NULL);<br>    }<br>    //Here i&#39;m adding the node as a ready array of strings<br>    //that is a complete command ready to execute<br>    if (add_node(commands, comand) == NULL)<br>    {<br>     free_list(*commands);<br>     free_2D(cmds);<br>     free_2D(comand);<br>     return (NULL);<br>    }<br><br>  free_2D(comand);<br>  comand = NULL;<br> }<br> free_2D(cmds);<br> return (*commands);<br>}<br></pre><h4>variable_replacement:</h4><p>This function handles replacing variables included in each command. For example: (echo $PATH) here we need to replace the variable PATH with its value. That’s what real world shells do.</p><p>Basically, it keeps looping over the list of commands and loops again inside each command. If it finds the ‘$’ character, we know that we should replace the next variable name with its value.</p><h4>execute:</h4><p>The execute function is responsible for executing the commands that are passed to it. It takes a single argument, args, which is a pointer to a structure that contains all the necessary arguments for the command execution.</p><p>Here’s a step-by-step explanation of what the function does:</p><ol><li>If the command is not “history”, it adds the command to the history.</li><li>It then enters a loop where it processes each command in the list of commands.</li><li>It checks if the command is a logical operator (like &amp;&amp; or ||). If it is, it handles the operator accordingly.</li><li>It then checks if the command is a pipe command. If it is, it forks a new process and executes the command. It also handles the input and output redirection if necessary.</li><li>If the command is a redirection command, it opens the necessary files and redirects the input or output accordingly.</li><li>If the command is not a built-in command, it checks if it’s an alias. If it is, it replaces the alias with the actual command.</li><li>If the command is not an alias, it gets the path of the command and executes it. If the path is not found, it prints an error message.</li><li>After all commands have been processed, it frees the memory allocated for the list of commands and the line.</li><li>The function then returns, and the shell is ready to accept the next command.</li></ol><p>In summary, the execute function is the heart of the shell. It processes each command, handles operators, pipes, and redirections, executes the command, and manages memory.</p><h4>Example #3</h4><pre>//This example doesn&#39;t contain all mentioned functionality above<br>void execute(ALL *args) {<br>    // If there are no commands, free the line and return<br>    if (args-&gt;commands == NULL) {<br>        free(args-&gt;line);<br>        return;<br>    }<br><br>    // Loop through each command in the list of commands<br>    while (args-&gt;commands != NULL) {<br>        // Get the next command in the list<br>        next = args-&gt;commands-&gt;next;<br><br>        // If the command is a built-in command, execute it<br>        if (is_built_in(args-&gt;commands-&gt;command)) {<br>            execute_built_in_command(args);<br>        } <br>        // If the command is not a built-in command, execute it as a normal command<br>        else {<br>            // Get the path of the command<br>            args-&gt;path = get_path(args-&gt;commands-&gt;command);<br><br>            // If the path is not found, print an error<br>            if (!args-&gt;path) {<br>                print_error(args);<br>            } <br>            // If the path is found, execute the command<br>            else {<br>                fork_and_execute_command(args);<br>            }<br>        }<br><br>        // Move to the next command in the list<br>        args-&gt;commands = args-&gt;commands-&gt;next;<br>    }<br><br>    // Free the memory allocated for the list of commands and the line<br>    free_list(args-&gt;commands);<br>    free(args-&gt;line);<br>}</pre><blockquote><em>This is the largest function at all :)</em></blockquote><p>GOOD job to reach to this point (●&#39;◡&#39;●)</p><blockquote>0x04 — FLOWCHART</blockquote><p>This Flowchart will help you see things in the big picture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*9e7OOhCYGvNz6S3nuKWirw.png" /></figure><blockquote>0x05 — Tips</blockquote><ul><li>Remember when you exit at any point in the shell you must free all dynamically allocated memory.</li><li>And you need to pay attention to cases where EOF is found you should free all previously allocated memory.</li><li>Read the manual pages very well, it will make a difference.</li><li><strong>THE GOLDEN RULE</strong> : if at any point you decide to allocate memory for whatever reason, you must consider freeing it, in any exit point or any failed function, because memory leaks is very difficult to fix.</li><li>Never code before planning or thinking. Always know what you are going to do, it will be much better if your write down all you ideas and your approach before running to code.</li><li>Consider all the features you need to handle. Before start coding. It will help you from rebuilding your shell, or change many lines of code.</li></ul><blockquote>Thank you for reading and for your patience.</blockquote><p>This was a project in the ALX software engineering programme.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3af4755e7df9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>