Skip to content

Instantly share code, notes, and snippets.

@andreybleme
Created February 11, 2021 00:07
Show Gist options
  • Save andreybleme/efbe192266a40141242f2ffd46d42073 to your computer and use it in GitHub Desktop.
Save andreybleme/efbe192266a40141242f2ffd46d42073 to your computer and use it in GitHub Desktop.
Send ping request using Caladan - Advanced Operating Systems DCC/UFMG (Lucas Andrey Caldeira Bleme)
/*
* test_ping.c - sends ping echo requests
*/
#include <stdio.h>
#include <base/log.h>
#include <net/ping.h>
#include <runtime/runtime.h>
#include <runtime/timer.h>
#define N_PINGS 20
#define DEST_IP_ADDR 3232235779 // 192.168.1.3
static void main_handler(void *arg)
{
int i, ret;
ret = net_ping_init();
if (ret) {
log_err("failed to init ping");
return;
}
for (i = 0; i < N_PINGS; i++) {
net_send_ping(i, DEST_IP_ADDR);
log_info("ping sent to %u", DEST_IP_ADDR);
// no need to wait 1 second before sending next ping
// timer_sleep(1000*1000);
}
}
int main(int argc, char *argv[])
{
int ret;
if (argc < 2) {
printf("arg must be config file\n");
return -EINVAL;
}
ret = runtime_init(argv[1], main_handler, NULL);
if (ret) {
printf("failed to start runtime\n");
return ret;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment