Commit | Line | Data |
---|---|---|
51a62941 DC |
1 | #include <stdlib.h> |
2 | #include <unistd.h> | |
3 | #include <stdio.h> | |
4 | #include <string.h> | |
5 | #include <errno.h> | |
6 | #include <sys/socket.h> | |
7 | #include <netinet/in.h> | |
8 | #include <arpa/inet.h> | |
9 | #include <sys/types.h> | |
10 | ||
11 | struct icmphdr { | |
12 | u_int8_t type; | |
13 | u_int8_t code; | |
14 | u_int16_t checksum; | |
15 | u_int16_t id; | |
16 | u_int16_t seq; | |
17 | }; | |
18 | ||
19 | #define ICMP_NAMEREQ 37 | |
20 | #define ICMP_NAMEREP 38 | |
21 | ||
22 | int main(int argc, char **argv) | |
23 | { | |
24 | int ret; | |
25 | int s; | |
26 | struct sockaddr_in host; | |
27 | struct icmphdr data; | |
28 | ||
29 | if((s = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) { | |
30 | perror("could not create raw socket"); | |
31 | exit(1); | |
32 | } | |
33 | ||
34 | host.sin_family = AF_INET; | |
35 | inet_aton("192.168.1.254", &host.sin_addr); | |
36 | ||
37 | memset(&data, 0, sizeof(data)); | |
38 | data.type = ICMP_NAMEREQ; | |
39 | ||
40 | ret = sendto(s, &data, sizeof(data), 0, (struct sockaddr *)&host, sizeof(host)); | |
41 | if(ret < 0) { | |
42 | perror("sendto"); | |
43 | } else { | |
44 | printf("%i\n", ret); | |
45 | } | |
46 | close(s); | |
47 | return(0); | |
48 | } |