| 3 | 4 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,70 @@ |
| 1 |
+/*! |
|
| 2 |
+ * @file address.c |
|
| 3 |
+ * @author HiSEON (ikseon@nepirity.com) |
|
| 4 |
+ * |
|
| 5 |
+ * @internal |
|
| 6 |
+ * Created: 2018년 03월 20일 |
|
| 7 |
+ * Copyright: Copyright (c) 2018, Kang IkSeon |
|
| 8 |
+ */ |
|
| 9 |
+ |
|
| 10 |
+#include <stdio.h> |
|
| 11 |
+#include <string.h> |
|
| 12 |
+ |
|
| 13 |
+#include <sys/types.h> |
|
| 14 |
+#include <sys/socket.h> |
|
| 15 |
+#include <netinet/in.h> |
|
| 16 |
+#include <arpa/inet.h> |
|
| 17 |
+ |
|
| 18 |
+#include <pcap.h> |
|
| 19 |
+ |
|
| 20 |
+int main(void) {
|
|
| 21 |
+ pcap_if_t *alldevs; |
|
| 22 |
+ pcap_if_t *d; |
|
| 23 |
+ struct pcap_addr *a; |
|
| 24 |
+ int i = 0; |
|
| 25 |
+ int no; |
|
| 26 |
+ |
|
| 27 |
+ char errbuf[PCAP_ERRBUF_SIZE]; |
|
| 28 |
+ |
|
| 29 |
+ if (pcap_findalldevs(&alldevs, errbuf) < 0) {
|
|
| 30 |
+ printf("pcap_findalldevs error\n");
|
|
| 31 |
+ return 1; |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ for (d=alldevs; d; d=d->next) {
|
|
| 35 |
+ printf("%d : %s\n", ++i, d->name);
|
|
| 36 |
+ } |
|
| 37 |
+ |
|
| 38 |
+ printf("number : ");
|
|
| 39 |
+ scanf("%d", &no);
|
|
| 40 |
+ |
|
| 41 |
+ if (!(no > 0 && no <= i)) {
|
|
| 42 |
+ printf("number error\n");
|
|
| 43 |
+ return 1; |
|
| 44 |
+ } |
|
| 45 |
+ |
|
| 46 |
+ for (d=alldevs, i=0; d; d=d->next) {
|
|
| 47 |
+ if (no == ++i) break; |
|
| 48 |
+ } |
|
| 49 |
+ |
|
| 50 |
+ printf("name : %s\n", d->name);
|
|
| 51 |
+ |
|
| 52 |
+ if (d->description) |
|
| 53 |
+ printf("description : %s\n", d->description);
|
|
| 54 |
+ |
|
| 55 |
+ for (a = d->addresses; a; a=a->next) {
|
|
| 56 |
+ struct sockaddr_in *in_addr |
|
| 57 |
+ = (struct sockaddr_in *)a->addr; |
|
| 58 |
+ |
|
| 59 |
+ switch (a->addr->sa_family) {
|
|
| 60 |
+ case AF_INET: |
|
| 61 |
+ printf("address : %s\n", inet_ntoa(in_addr->sin_addr));
|
|
| 62 |
+ break; |
|
| 63 |
+ } |
|
| 64 |
+ } |
|
| 65 |
+ |
|
| 66 |
+ pcap_freealldevs(alldevs); |
|
| 67 |
+ |
|
| 68 |
+ return 0; |
|
| 69 |
+} |
|
| 70 |
+ |