The ft_ping project is a custom implementation of the ping command, which is widely used to test the reachability of a host on an Internet Protocol (IP) network. This project is part of the 42 School curriculum, designed to help students understand the basics of network programming and system functions.
Description This implementation of ping uses various system and network functions to send ICMP "echo request" packets to a host and listen for ICMP "echo reply" packets. It measures the round-trip time for messages sent from the originating host to a destination computer.
Key Functions gettimeofday: Gets the current time. exit: Exits the program. inet_ntop / inet_pton: Converts IP addresses from binary to text form and vice versa. ntohs / htons: Converts values between network byte order and host byte order. signal / alarm / usleep: Manages signals and process sleeping. socket / setsockopt / close: Manages socket operations. sendto / recvmsg: Sends and receives messages on a socket. getpid / getuid: Gets process and user IDs. getaddrinfo / getnameinfo / freeaddrinfo: Manages address information. strerror / gai_strerror: Converts error codes to human-readable strings. printf and its family: Outputs data. Usage To use ft_ping, compile the project using make, which generates the ft_ping executable. Then, run the executable with a target host as an argument.
Basic Usage bash
./ft_ping [host] Verbose Mode To enable verbose output, use the -v option.
bash
./ft_ping -v [host] Testing with Docker You can test the ft_ping project using Docker with Debian 11. Simply run the following shell script:
bash
./myScript.sh This script will set up a Docker container with Debian 11 for you to test the project in an isolated environment.
Compiling for Different Operating Systems The Makefile provided allows for compiling the project for different operating systems, including MacOS and Linux.
MacOS Compilation To compile for MacOS, use the following command:
bash
make macos Linux Compilation To compile for Linux, use the following command:
bash
make linux This ensures that the project can be compiled and run on different platforms without any issues.
License This project is licensed under the MIT License - see the LICENSE.md file for details.
This README.md file now includes the additional information about testing with Docker using Debian 11 and compiling for different operating systems using the Makefile.
kr -------------------------------------------------------------------
ft_ping ft_ping ํ๋ก์ ํธ๋ ping ๋ช ๋ น์ด์ ์ฌ์ฉ์ ์ ์ ๊ตฌํ์ ๋๋ค. ping์ ์ธํฐ๋ท ํ๋กํ ์ฝ(IP) ๋คํธ์ํฌ์์ ํธ์คํธ์ ๋๋ฌ ๊ฐ๋ฅ์ฑ์ ํ ์คํธํ๋ ๋ฐ ๋๋ฆฌ ์ฌ์ฉ๋ฉ๋๋ค. ์ด ํ๋ก์ ํธ๋ 42 School ์ปค๋ฆฌํ๋ผ์ ์ผ๋ถ๋ก, ํ์๋ค์ด ๋คํธ์ํฌ ํ๋ก๊ทธ๋๋ฐ๊ณผ ์์คํ ํจ์์ ๊ธฐ์ด๋ฅผ ์ดํดํ๋๋ก ๋๊ธฐ ์ํด ์ค๊ณ๋์์ต๋๋ค.
์ค๋ช ์ด ping ๊ตฌํ์ ๋ค์ํ ์์คํ ๋ฐ ๋คํธ์ํฌ ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ICMP "์์ฝ ์์ฒญ" ํจํท์ ํธ์คํธ๋ก ๋ณด๋ด๊ณ ICMP "์์ฝ ์๋ต" ํจํท์ ์์ ํฉ๋๋ค. ๋ฐ์ ํธ์คํธ์์ ๋์ ์ปดํจํฐ๋ก ๋ณด๋ธ ๋ฉ์์ง์ ์๋ณต ์๊ฐ์ ์ธก์ ํฉ๋๋ค.
์ฃผ์ ํจ์
gettimeofday: ํ์ฌ ์๊ฐ์ ๊ฐ์ ธ์ต๋๋ค.
exit: ํ๋ก๊ทธ๋จ์ ์ข ๋ฃํฉ๋๋ค.
inet_ntop / inet_pton: IP ์ฃผ์๋ฅผ ์ด์ง ํ์๊ณผ ํ ์คํธ ํ์ ์ฌ์ด์์ ๋ณํํฉ๋๋ค.
ntohs / htons: ๋คํธ์ํฌ ๋ฐ์ดํธ ์์์ ํธ์คํธ ๋ฐ์ดํธ ์์ ์ฌ์ด์์ ๊ฐ์ ๋ณํํฉ๋๋ค.
signal / alarm / usleep: ์ ํธ์ ํ๋ก์ธ์ค ์ฌ๋ฆฝ์ ๊ด๋ฆฌํฉ๋๋ค.
socket / setsockopt / close: ์์ผ ์์ ์ ๊ด๋ฆฌํฉ๋๋ค.
sendto / recvmsg: ์์ผ์์ ๋ฉ์์ง๋ฅผ ๋ณด๋ด๊ณ ๋ฐ์ต๋๋ค.
getpid / getuid: ํ๋ก์ธ์ค ๋ฐ ์ฌ์ฉ์ ID๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
getaddrinfo / getnameinfo / freeaddrinfo: ์ฃผ์ ์ ๋ณด๋ฅผ ๊ด๋ฆฌํฉ๋๋ค.
strerror / gai_strerror: ์ค๋ฅ ์ฝ๋๋ฅผ ์ฌ๋์ด ์ฝ์ ์ ์๋ ๋ฌธ์์ด๋ก ๋ณํํฉ๋๋ค.
printf ๋ฐ ๊ด๋ จ ํจ์: ๋ฐ์ดํฐ๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
์ฌ์ฉ๋ฒ ft_ping์ ์ฌ์ฉํ๋ ค๋ฉด make๋ฅผ ์ฌ์ฉํ์ฌ ํ๋ก์ ํธ๋ฅผ ์ปดํ์ผํ์ธ์. ์ด๋ ๊ฒ ํ๋ฉด ft_ping ์คํ ํ์ผ์ด ์์ฑ๋ฉ๋๋ค. ๊ทธ๋ฐ ๋ค์ ๋์ ํธ์คํธ๋ฅผ ์ธ์๋ก ์คํ ํ์ผ์ ์คํํ์ธ์.
๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ ./ft_ping [host]
์์ธ ๋ชจ๋ ์์ธ ์ถ๋ ฅ์ ํ์ฑํํ๋ ค๋ฉด -v ์ต์ ์ ์ฌ์ฉํ์ธ์. ./ft_ping -v [host]
Docker๋ฅผ ์ด์ฉํ ํ ์คํธ Debian 11์ด ์ค์น๋ Docker๋ฅผ ์ฌ์ฉํ์ฌ ft_ping ํ๋ก์ ํธ๋ฅผ ํ ์คํธํ ์ ์์ต๋๋ค. ๋ค์ ์ ธ ์คํฌ๋ฆฝํธ๋ฅผ ์คํํ์ธ์: ./myScript.sh
์ด ์คํฌ๋ฆฝํธ๋ Debian 11์ด ์ค์น๋ Docker ์ปจํ ์ด๋๋ฅผ ์ค์ ํ์ฌ ๊ฒฉ๋ฆฌ๋ ํ๊ฒฝ์์ ํ๋ก์ ํธ๋ฅผ ํ ์คํธํ ์ ์๊ฒ ํด์ค๋๋ค. ๋ค๋ฅธ ์ด์ ์ฒด์ ์ฉ ์ปดํ์ผ ์ ๊ณต๋ Makefile์ ์ฌ์ฉํ๋ฉด MacOS์ Linux๋ฅผ ํฌํจํ ๋ค๋ฅธ ์ด์ ์ฒด์ ์ฉ์ผ๋ก ํ๋ก์ ํธ๋ฅผ ์ปดํ์ผํ ์ ์์ต๋๋ค.
MacOS ์ปดํ์ผ MacOS์ฉ์ผ๋ก ์ปดํ์ผํ๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ธ์: make macos
Linux ์ปดํ์ผ Linux์ฉ์ผ๋ก ์ปดํ์ผํ๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ธ์: make linux
์ด๋ฅผ ํตํด ํ๋ก์ ํธ๋ฅผ ๋ค์ํ ํ๋ซํผ์์ ๋ฌธ์ ์์ด ์ปดํ์ผํ๊ณ ์คํํ ์ ์์ต๋๋ค. ์ด README.md ํ์ผ์๋ ์ด์ Debian 11์ ์ฌ์ฉํ Docker ํ ์คํธ์ Makefile์ ์ฌ์ฉํ ๋ค๋ฅธ ์ด์ ์ฒด์ ์ฉ ์ปดํ์ผ์ ๋ํ ์ถ๊ฐ ์ ๋ณด๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.