Formatting for better readability
This commit is contained in:
7
main.c
7
main.c
@@ -20,6 +20,7 @@ uint16_t calculate_checksum(uint16_t *data, int len)
|
||||
double get_timestamp()
|
||||
{
|
||||
struct timeval timestamp;
|
||||
|
||||
gettimeofday(×tamp, NULL);
|
||||
return (timestamp.tv_sec + (double)timestamp.tv_usec / 1000000);
|
||||
}
|
||||
@@ -31,11 +32,13 @@ int ft_ping(int sock, int seq, struct sockaddr_in dst)
|
||||
|
||||
memset(data, 0, sizeof(data));
|
||||
memset(icmp_hdr, 0, sizeof(*icmp_hdr));
|
||||
|
||||
icmp_hdr->type = ICMP_ECHO;
|
||||
icmp_hdr->code = 0;
|
||||
icmp_hdr->id = getpid();
|
||||
icmp_hdr->seq = seq;
|
||||
icmp_hdr->checksum = calculate_checksum((uint16_t *)icmp_hdr, sizeof(icmp_hdr));
|
||||
|
||||
if (sendto(sock, data, sizeof(data), 0, (struct sockaddr *)&dst, sizeof(dst)) == -1)
|
||||
{
|
||||
fprintf(stderr, "ERROR : sendto() failed\n");
|
||||
@@ -67,11 +70,12 @@ char *get_ip_by_hostname(char *hostname)
|
||||
{
|
||||
struct hostent *he;
|
||||
struct in_addr **addr_list;
|
||||
he = gethostbyname(hostname);
|
||||
|
||||
he = gethostbyname(hostname);
|
||||
addr_list = (struct in_addr **)he->h_addr_list;
|
||||
return (inet_ntoa(*addr_list[0]));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int sock;
|
||||
@@ -81,6 +85,7 @@ int main(int argc, char **argv)
|
||||
double start;
|
||||
int n_packet_sent = 0;
|
||||
int n_packet_recv = 0;
|
||||
|
||||
if (argc != 2 || argv[1] == NULL || argv[1][0] == 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR : usage : ping {-v?} [ADRESS]\n");
|
||||
|
||||
Reference in New Issue
Block a user