From 51a629415834385d11fe0351b2e5b518a381cdfa Mon Sep 17 00:00:00 2001 From: "fredrik@DOLDA2000.COM" Date: Thu, 28 Apr 2005 00:51:09 +0000 Subject: [PATCH] First test version. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/icmp-dn@209 959494ce-11ee-0310-bf91-de5d638817bd --- idnlookup.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 idnlookup.c diff --git a/idnlookup.c b/idnlookup.c new file mode 100644 index 0000000..e2632df --- /dev/null +++ b/idnlookup.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct icmphdr { + u_int8_t type; + u_int8_t code; + u_int16_t checksum; + u_int16_t id; + u_int16_t seq; +}; + +#define ICMP_NAMEREQ 37 +#define ICMP_NAMEREP 38 + +int main(int argc, char **argv) +{ + int ret; + int s; + struct sockaddr_in host; + struct icmphdr data; + + if((s = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) { + perror("could not create raw socket"); + exit(1); + } + + host.sin_family = AF_INET; + inet_aton("192.168.1.254", &host.sin_addr); + + memset(&data, 0, sizeof(data)); + data.type = ICMP_NAMEREQ; + + ret = sendto(s, &data, sizeof(data), 0, (struct sockaddr *)&host, sizeof(host)); + if(ret < 0) { + perror("sendto"); + } else { + printf("%i\n", ret); + } + close(s); + return(0); +} -- 2.11.0