First test version.
authorfredrik@DOLDA2000.COM <fredrik@DOLDA2000.COM@959494ce-11ee-0310-bf91-de5d638817bd>
Thu, 28 Apr 2005 00:51:09 +0000 (00:51 +0000)
committerfredrik@DOLDA2000.COM <fredrik@DOLDA2000.COM@959494ce-11ee-0310-bf91-de5d638817bd>
Thu, 28 Apr 2005 00:51:09 +0000 (00:51 +0000)
git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/icmp-dn@209 959494ce-11ee-0310-bf91-de5d638817bd

idnlookup.c [new file with mode: 0644]

diff --git a/idnlookup.c b/idnlookup.c
new file mode 100644 (file)
index 0000000..e2632df
--- /dev/null
@@ -0,0 +1,48 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/types.h>
+
+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);
+}