Go to the documentation of this file.
53 DEBUG(
"sending on device: " << dev);
57 DEBUG(
"sending ICMP packets");
62 DEBUG(
"sending ARP packets");
82 ERROR(
"failed to initialize network client for device: " << dev <<
83 ", result = " << (
int) result);
91 ERROR(
"failed to create ARP socket: result = " << (
int) result);
98 ERROR(
"failed to convert to IPV4 address: " << host);
101 printf(
"Sending ARP request to %s\r\n", host);
104 if (::
write(sock, &ipAddr,
sizeof(ipAddr)) < 0)
111 if (::
read(sock, ðAddr,
sizeof(ethAddr)) < 0)
118 printf(
"Received ARP response for: ");
141 ERROR(
"failed to initialize network client for device: " << dev <<
142 ", result = " << (
int) result);
150 ERROR(
"failed to create ICMP socket: result = " << (
int)result);
158 ERROR(
"failed to connect ICMP socket: result = " << (
int) result);
174 if (::
write(sock, &msg,
sizeof(msg)) <= 0)
179 printf(
"Sending ICMP request to %s\r\n", host);
182 if (::
read(sock, &msg,
sizeof(msg)) <= 0)
191 ERROR(
"invalid ICMP code in response: " << (
int) msg.
type);
196 printf(
"Received ICMP response with id=%d sequence=%d\r\n",
const char * get(const char *name) const
Get argument by name.
NetPing(int argc, char **argv)
Class constructor.
virtual Result exec()
Execute the application event loop.
Result initialize()
Perform initialization.
ssize_t write(int fildes, const void *buf, size_t nbyte)
Write on a file.
Result createSocket(const SocketType type, int *socket)
Create new socket.
C int errno
The lvalue errno is used by many functions to return error values.
Result close(const int sock)
Close the socket.
virtual ~NetPing()
Class destructor.
Result icmpPing(const char *dev, const char *host)
Send ICMP ping/pong.
static const u16 checksum(const void *buffer, const Size length)
Calculate IP checksum.
POSIX-compatible application.
const ArgumentContainer & arguments() const
Get program arguments.
void setDescription(const String &desc)
Set program description.
ssize_t read(int fildes, void *buf, size_t nbyte)
Read from a file.
Result connectSocket(const int sock, const IPV4::Address addr, const u16 port=0)
Connect socket to address/port.
#define DEBUG(msg)
Output a debug message to standard output.
Ethernet network address.
int printf(const char *format,...)
Output a formatted string to standard output.
int close(int fildes)
Close a file descriptor.
static const Address toAddress(const char *address)
Convert string to IPV4 address.
char * strerror(int errnum)
The strerror function maps the number in errnum to a message string.
unsigned int Size
Any sane size indicator cannot go negative.
Result registerFlag(char arg, const char *name, const char *description)
Register a flag Argument.
Networking Client implementation.
Result registerPositional(const char *name, const char *description, Size count=1)
Register a positional argument.
ArgumentParser & parser()
Get program arguments parser.
#define ERROR(msg)
Output an error message.
Result arpPing(const char *dev, const char *host)
Send ARP ping/pong.
struct Ethernet::Address Address
Ethernet network address.