pcap-sita.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. /*
  2. * pcap-sita.c: Packet capture interface additions for SITA ACN devices
  3. *
  4. * Copyright (c) 2007 Fulko Hew, SITA INC Canada, Inc <fulko.hew@sita.aero>
  5. *
  6. * License: BSD
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * 3. The names of the authors may not be used to endorse or promote
  19. * products derived from this software without specific prior
  20. * written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  25. */
  26. #ifdef HAVE_CONFIG_H
  27. #include <config.h>
  28. #endif
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <stdlib.h>
  32. #include <unistd.h>
  33. #include <fcntl.h>
  34. #include <errno.h>
  35. #include <sys/time.h>
  36. #include <sys/socket.h>
  37. #include <netinet/in.h>
  38. #include <arpa/inet.h>
  39. #include "pcap-int.h"
  40. #include "pcap-sita.h"
  41. /* non-configureable manifests follow */
  42. #define IOP_SNIFFER_PORT 49152 /* TCP port on the IOP used for 'distributed pcap' usage */
  43. #define MAX_LINE_SIZE 255 /* max size of a buffer/line in /etc/hosts we allow */
  44. #define MAX_CHASSIS 8 /* number of chassis in an ACN site */
  45. #define MAX_GEOSLOT 8 /* max number of access units in an ACN site */
  46. #define FIND 0
  47. #define LIVE 1
  48. typedef struct iface {
  49. struct iface *next; /* a pointer to the next interface */
  50. char *name; /* this interface's name */
  51. char *IOPname; /* this interface's name on an IOP */
  52. uint32_t iftype; /* the type of interface (DLT values) */
  53. } iface_t;
  54. typedef struct unit {
  55. char *ip; /* this unit's IP address (as extracted from /etc/hosts) */
  56. int fd; /* the connection to this unit (if it exists) */
  57. int find_fd; /* a big kludge to avoid my programming limitations since I could have this unit open for findalldevs purposes */
  58. int first_time; /* 0 = just opened via acn_open_live(), ie. the first time, NZ = nth time */
  59. struct sockaddr_in *serv_addr; /* the address control block for comms to this unit */
  60. int chassis;
  61. int geoslot;
  62. iface_t *iface; /* a pointer to a linked list of interface structures */
  63. char *imsg; /* a pointer to an inbound message */
  64. int len; /* the current size of the inbound message */
  65. } unit_t;
  66. static unit_t units[MAX_CHASSIS+1][MAX_GEOSLOT+1]; /* we use indexes of 1 through 8, but we reserve/waste index 0 */
  67. static fd_set readfds; /* a place to store the file descriptors for the connections to the IOPs */
  68. static int max_fs;
  69. pcap_if_t *acn_if_list; /* pcap's list of available interfaces */
  70. static void dump_interface_list(void) {
  71. pcap_if_t *iff;
  72. pcap_addr_t *addr;
  73. int longest_name_len = 0;
  74. char *n, *d, *f;
  75. int if_number = 0;
  76. iff = acn_if_list;
  77. while (iff) {
  78. if (iff->name && (strlen(iff->name) > longest_name_len)) longest_name_len = strlen(iff->name);
  79. iff = iff->next;
  80. }
  81. iff = acn_if_list;
  82. printf("Interface List:\n");
  83. while (iff) {
  84. n = (iff->name) ? iff->name : "";
  85. d = (iff->description) ? iff->description : "";
  86. f = (iff->flags == PCAP_IF_LOOPBACK) ? "L" : "";
  87. printf("%3d: %*s %s '%s'\n", if_number++, longest_name_len, n, f, d);
  88. addr = iff->addresses;
  89. while (addr) {
  90. printf("%*s ", (5 + longest_name_len), ""); /* add some indentation */
  91. printf("%15s ", (addr->addr) ? inet_ntoa(((struct sockaddr_in *)addr->addr)->sin_addr) : "");
  92. printf("%15s ", (addr->netmask) ? inet_ntoa(((struct sockaddr_in *)addr->netmask)->sin_addr) : "");
  93. printf("%15s ", (addr->broadaddr) ? inet_ntoa(((struct sockaddr_in *)addr->broadaddr)->sin_addr) : "");
  94. printf("%15s ", (addr->dstaddr) ? inet_ntoa(((struct sockaddr_in *)addr->dstaddr)->sin_addr) : "");
  95. printf("\n");
  96. addr = addr->next;
  97. }
  98. iff = iff->next;
  99. }
  100. }
  101. static void dump(unsigned char *ptr, int i, int indent) {
  102. fprintf(stderr, "%*s", indent, " ");
  103. for (; i > 0; i--) {
  104. fprintf(stderr, "%2.2x ", *ptr++);
  105. }
  106. fprintf(stderr, "\n");
  107. }
  108. static void dump_interface_list_p(void) {
  109. pcap_if_t *iff;
  110. pcap_addr_t *addr;
  111. int if_number = 0;
  112. iff = acn_if_list;
  113. printf("Interface Pointer @ %p is %p:\n", &acn_if_list, iff);
  114. while (iff) {
  115. printf("%3d: %p %p next: %p\n", if_number++, iff->name, iff->description, iff->next);
  116. dump((unsigned char *)iff, sizeof(pcap_if_t), 5);
  117. addr = iff->addresses;
  118. while (addr) {
  119. printf(" %p %p %p %p, next: %p\n", addr->addr, addr->netmask, addr->broadaddr, addr->dstaddr, addr->next);
  120. dump((unsigned char *)addr, sizeof(pcap_addr_t), 10);
  121. addr = addr->next;
  122. }
  123. iff = iff->next;
  124. }
  125. }
  126. static void dump_unit_table(void) {
  127. int chassis, geoslot;
  128. iface_t *p;
  129. printf("%c:%c %s %s\n", 'C', 'S', "fd", "IP Address");
  130. for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) {
  131. for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) {
  132. if (units[chassis][geoslot].ip != NULL)
  133. printf("%d:%d %2d %s\n", chassis, geoslot, units[chassis][geoslot].fd, units[chassis][geoslot].ip);
  134. p = units[chassis][geoslot].iface;
  135. while (p) {
  136. char *n = (p->name) ? p->name : "";
  137. char *i = (p->IOPname) ? p->IOPname : "";
  138. p = p->next;
  139. printf(" %12s -> %12s\n", i, n);
  140. }
  141. }
  142. }
  143. }
  144. static int find_unit_by_fd(int fd, int *chassis, int *geoslot, unit_t **unit_ptr) {
  145. int c, s;
  146. for (c = 0; c <= MAX_CHASSIS; c++) {
  147. for (s = 0; s <= MAX_GEOSLOT; s++) {
  148. if (units[c][s].fd == fd || units[c][s].find_fd == fd) {
  149. if (chassis) *chassis = c;
  150. if (geoslot) *geoslot = s;
  151. if (unit_ptr) *unit_ptr = &units[c][s];
  152. return 1;
  153. }
  154. }
  155. }
  156. return 0;
  157. }
  158. static int read_client_nbytes(int fd, int count, unsigned char *buf) {
  159. unit_t *u;
  160. int chassis, geoslot;
  161. int len;
  162. find_unit_by_fd(fd, &chassis, &geoslot, &u);
  163. while (count) {
  164. if ((len = recv(fd, buf, count, 0)) <= 0) return -1; /* read in whatever data was sent to us */
  165. count -= len;
  166. buf += len;
  167. } /* till we have everything we are looking for */
  168. return 0;
  169. }
  170. static void empty_unit_iface(unit_t *u) {
  171. iface_t *p, *cur;
  172. cur = u->iface;
  173. while (cur) { /* loop over all the interface entries */
  174. if (cur->name) free(cur->name); /* throwing away the contents if they exist */
  175. if (cur->IOPname) free(cur->IOPname);
  176. p = cur->next;
  177. free(cur); /* then throw away the structure itself */
  178. cur = p;
  179. }
  180. u->iface = 0; /* and finally remember that there are no remaining structure */
  181. }
  182. static void empty_unit(int chassis, int geoslot) {
  183. unit_t *u = &units[chassis][geoslot];
  184. empty_unit_iface(u);
  185. if (u->imsg) { /* then if an inbound message buffer exists */
  186. void *bigger_buffer;
  187. bigger_buffer = (char *)realloc(u->imsg, 1); /* and re-allocate the old large buffer into a new small one */
  188. if (bigger_buffer == NULL) { /* oops, realloc call failed */
  189. fprintf(stderr, "Warning...call to realloc() failed, value of errno is %d\n", errno);
  190. return;
  191. }
  192. u->imsg = bigger_buffer;
  193. }
  194. }
  195. static void empty_unit_table(void) {
  196. int chassis, geoslot;
  197. for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) {
  198. for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) {
  199. if (units[chassis][geoslot].ip != NULL) {
  200. free(units[chassis][geoslot].ip); /* get rid of the malloc'ed space that holds the IP address */
  201. units[chassis][geoslot].ip = 0; /* then set the pointer to NULL */
  202. }
  203. empty_unit(chassis, geoslot);
  204. }
  205. }
  206. }
  207. static char *find_nth_interface_name(int n) {
  208. int chassis, geoslot;
  209. iface_t *p;
  210. char *last_name = 0;
  211. if (n < 0) n = 0; /* ensure we are working with a valid number */
  212. for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) { /* scan the table... */
  213. for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) {
  214. if (units[chassis][geoslot].ip != NULL) {
  215. p = units[chassis][geoslot].iface;
  216. while (p) { /* and all interfaces... */
  217. if (p->IOPname) last_name = p->name; /* remembering the last name found */
  218. if (n-- == 0) return last_name; /* and if we hit the instance requested */
  219. p = p->next;
  220. }
  221. }
  222. }
  223. }
  224. /* if we couldn't fine the selected entry */
  225. if (last_name) return last_name; /* ... but we did have at least one entry... return the last entry found */
  226. return ""; /* ... but if there wasn't any entry... return an empty string instead */
  227. }
  228. int acn_parse_hosts_file(char *errbuf) { /* returns: -1 = error, 0 = OK */
  229. FILE *fp;
  230. char buf[MAX_LINE_SIZE];
  231. char *ptr, *ptr2;
  232. int pos;
  233. int chassis, geoslot;
  234. unit_t *u;
  235. empty_unit_table();
  236. if ((fp = fopen("/etc/hosts", "r")) == NULL) { /* try to open the hosts file and if it fails */
  237. pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "Cannot open '/etc/hosts' for reading."); /* return the nohostsfile error response */
  238. return -1;
  239. }
  240. while (fgets(buf, MAX_LINE_SIZE-1, fp)) { /* while looping over the file */
  241. pos = strcspn(buf, "#\n\r"); /* find the first comment character or EOL */
  242. *(buf + pos) = '\0'; /* and clobber it and anything that follows it */
  243. pos = strspn(buf, " \t"); /* then find the first non-white space */
  244. if (pos == strlen(buf)) /* if there is nothing but white space on the line */
  245. continue; /* ignore that empty line */
  246. ptr = buf + pos; /* and skip over any of that leading whitespace */
  247. if ((ptr2 = strstr(ptr, "_I_")) == NULL) /* skip any lines that don't have names that look like they belong to IOPs */
  248. continue;
  249. if (*(ptr2 + 4) != '_') /* and skip other lines that have names that don't look like ACN components */
  250. continue;
  251. *(ptr + strcspn(ptr, " \t")) = '\0'; /* null terminate the IP address so its a standalone string */
  252. chassis = *(ptr2 + 3) - '0'; /* extract the chassis number */
  253. geoslot = *(ptr2 + 5) - '0'; /* and geo-slot number */
  254. if (chassis < 1 || chassis > MAX_CHASSIS ||
  255. geoslot < 1 || geoslot > MAX_GEOSLOT) { /* if the chassis and/or slot numbers appear to be bad... */
  256. pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, "Invalid ACN name in '/etc/hosts'."); /* warn the user */
  257. continue; /* and ignore the entry */
  258. }
  259. if ((ptr2 = (char *)malloc(strlen(ptr) + 1)) == NULL) {
  260. pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
  261. errno, "malloc");
  262. continue;
  263. }
  264. strcpy(ptr2, ptr); /* copy the IP address into our malloc'ed memory */
  265. u = &units[chassis][geoslot];
  266. u->ip = ptr2; /* and remember the whole shebang */
  267. u->chassis = chassis;
  268. u->geoslot = geoslot;
  269. }
  270. fclose(fp);
  271. if (*errbuf) return -1;
  272. else return 0;
  273. }
  274. static int open_with_IOP(unit_t *u, int flag) {
  275. int sockfd;
  276. char *ip;
  277. if (u->serv_addr == NULL) {
  278. u->serv_addr = malloc(sizeof(struct sockaddr_in));
  279. /* since we called malloc(), lets check to see if we actually got the memory */
  280. if (u->serv_addr == NULL) { /* oops, we didn't get the memory requested */
  281. fprintf(stderr, "malloc() request for u->serv_addr failed, value of errno is: %d\n", errno);
  282. return 0;
  283. }
  284. }
  285. ip = u->ip;
  286. /* bzero() is deprecated, replaced with memset() */
  287. memset((char *)u->serv_addr, 0, sizeof(struct sockaddr_in));
  288. u->serv_addr->sin_family = AF_INET;
  289. u->serv_addr->sin_addr.s_addr = inet_addr(ip);
  290. u->serv_addr->sin_port = htons(IOP_SNIFFER_PORT);
  291. if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
  292. fprintf(stderr, "pcap can't open a socket for connecting to IOP at %s\n", ip);
  293. return 0;
  294. }
  295. if (connect(sockfd, (struct sockaddr *)u->serv_addr, sizeof(struct sockaddr_in)) < 0) {
  296. fprintf(stderr, "pcap can't connect to IOP at %s\n", ip);
  297. return 0;
  298. }
  299. if (flag == LIVE) u->fd = sockfd;
  300. else u->find_fd = sockfd;
  301. u->first_time = 0;
  302. return sockfd; /* return the non-zero file descriptor as a 'success' indicator */
  303. }
  304. static void close_with_IOP(int chassis, int geoslot, int flag) {
  305. int *id;
  306. if (flag == LIVE) id = &units[chassis][geoslot].fd;
  307. else id = &units[chassis][geoslot].find_fd;
  308. if (*id) { /* this was the last time, so... if we are connected... */
  309. close(*id); /* disconnect us */
  310. *id = 0; /* and forget that the descriptor exists because we are not open */
  311. }
  312. }
  313. static void pcap_cleanup_acn(pcap_t *handle) {
  314. int chassis, geoslot;
  315. unit_t *u;
  316. if (find_unit_by_fd(handle->fd, &chassis, &geoslot, &u) == 0)
  317. return;
  318. close_with_IOP(chassis, geoslot, LIVE);
  319. if (u)
  320. u->first_time = 0;
  321. pcap_cleanup_live_common(handle);
  322. }
  323. static void send_to_fd(int fd, int len, unsigned char *str) {
  324. int nwritten;
  325. int chassis, geoslot;
  326. while (len > 0) {
  327. if ((nwritten = write(fd, str, len)) <= 0) {
  328. find_unit_by_fd(fd, &chassis, &geoslot, NULL);
  329. if (units[chassis][geoslot].fd == fd) close_with_IOP(chassis, geoslot, LIVE);
  330. else if (units[chassis][geoslot].find_fd == fd) close_with_IOP(chassis, geoslot, FIND);
  331. empty_unit(chassis, geoslot);
  332. return;
  333. }
  334. len -= nwritten;
  335. str += nwritten;
  336. }
  337. }
  338. static void acn_freealldevs(void) {
  339. pcap_if_t *iff, *next_iff;
  340. pcap_addr_t *addr, *next_addr;
  341. for (iff = acn_if_list; iff != NULL; iff = next_iff) {
  342. next_iff = iff->next;
  343. for (addr = iff->addresses; addr != NULL; addr = next_addr) {
  344. next_addr = addr->next;
  345. if (addr->addr) free(addr->addr);
  346. if (addr->netmask) free(addr->netmask);
  347. if (addr->broadaddr) free(addr->broadaddr);
  348. if (addr->dstaddr) free(addr->dstaddr);
  349. free(addr);
  350. }
  351. if (iff->name) free(iff->name);
  352. if (iff->description) free(iff->description);
  353. free(iff);
  354. }
  355. }
  356. static void nonUnified_IOP_port_name(char *buf, size_t bufsize, const char *proto, unit_t *u) {
  357. pcap_snprintf(buf, bufsize, "%s_%d_%d", proto, u->chassis, u->geoslot);
  358. }
  359. static void unified_IOP_port_name(char *buf, size_t bufsize, const char *proto, unit_t *u, int IOPportnum) {
  360. int portnum;
  361. portnum = ((u->chassis - 1) * 64) + ((u->geoslot - 1) * 8) + IOPportnum + 1;
  362. pcap_snprintf(buf, bufsize, "%s_%d", proto, portnum);
  363. }
  364. static char *translate_IOP_to_pcap_name(unit_t *u, char *IOPname, bpf_u_int32 iftype) {
  365. iface_t *iface_ptr, *iface;
  366. char *name;
  367. char buf[32];
  368. char *proto;
  369. char *port;
  370. int IOPportnum = 0;
  371. iface = malloc(sizeof(iface_t)); /* get memory for a structure */
  372. if (iface == NULL) { /* oops, we didn't get the memory requested */
  373. fprintf(stderr, "Error...couldn't allocate memory for interface structure...value of errno is: %d\n", errno);
  374. return NULL;
  375. }
  376. memset((char *)iface, 0, sizeof(iface_t)); /* bzero is deprecated(), replaced with memset() */
  377. iface->iftype = iftype; /* remember the interface type of this interface */
  378. name = malloc(strlen(IOPname) + 1); /* get memory for the IOP's name */
  379. if (name == NULL) { /* oops, we didn't get the memory requested */
  380. fprintf(stderr, "Error...couldn't allocate memory for IOPname...value of errno is: %d\n", errno);
  381. return NULL;
  382. }
  383. strcpy(name, IOPname); /* and copy it in */
  384. iface->IOPname = name; /* and stick it into the structure */
  385. if (strncmp(IOPname, "lo", 2) == 0) {
  386. IOPportnum = atoi(&IOPname[2]);
  387. switch (iftype) {
  388. case DLT_EN10MB:
  389. nonUnified_IOP_port_name(buf, sizeof buf, "lo", u);
  390. break;
  391. default:
  392. unified_IOP_port_name(buf, sizeof buf, "???", u, IOPportnum);
  393. break;
  394. }
  395. } else if (strncmp(IOPname, "eth", 3) == 0) {
  396. IOPportnum = atoi(&IOPname[3]);
  397. switch (iftype) {
  398. case DLT_EN10MB:
  399. nonUnified_IOP_port_name(buf, sizeof buf, "eth", u);
  400. break;
  401. default:
  402. unified_IOP_port_name(buf, sizeof buf, "???", u, IOPportnum);
  403. break;
  404. }
  405. } else if (strncmp(IOPname, "wan", 3) == 0) {
  406. IOPportnum = atoi(&IOPname[3]);
  407. switch (iftype) {
  408. case DLT_SITA:
  409. unified_IOP_port_name(buf, sizeof buf, "wan", u, IOPportnum);
  410. break;
  411. default:
  412. unified_IOP_port_name(buf, sizeof buf, "???", u, IOPportnum);
  413. break;
  414. }
  415. } else {
  416. fprintf(stderr, "Error... invalid IOP name %s\n", IOPname);
  417. return NULL;
  418. }
  419. name = malloc(strlen(buf) + 1); /* get memory for that name */
  420. if (name == NULL) { /* oops, we didn't get the memory requested */
  421. fprintf(stderr, "Error...couldn't allocate memory for IOP port name...value of errno is: %d\n", errno);
  422. return NULL;
  423. }
  424. strcpy(name, buf); /* and copy it in */
  425. iface->name = name; /* and stick it into the structure */
  426. if (u->iface == 0) { /* if this is the first name */
  427. u->iface = iface; /* stick this entry at the head of the list */
  428. } else {
  429. iface_ptr = u->iface;
  430. while (iface_ptr->next) { /* othewise scan the list */
  431. iface_ptr = iface_ptr->next; /* till we're at the last entry */
  432. }
  433. iface_ptr->next = iface; /* then tack this entry on the end of the list */
  434. }
  435. return iface->name;
  436. }
  437. static int if_sort(char *s1, char *s2) {
  438. char *s1_p2, *s2_p2;
  439. char str1[MAX_LINE_SIZE], str2[MAX_LINE_SIZE];
  440. int s1_p1_len, s2_p1_len;
  441. int retval;
  442. if ((s1_p2 = strchr(s1, '_'))) { /* if an underscore is found... */
  443. s1_p1_len = s1_p2 - s1; /* the prefix length is the difference in pointers */
  444. s1_p2++; /* the suffix actually starts _after_ the underscore */
  445. } else { /* otherwise... */
  446. s1_p1_len = strlen(s1); /* the prefix length is the length of the string itself */
  447. s1_p2 = 0; /* and there is no suffix */
  448. }
  449. if ((s2_p2 = strchr(s2, '_'))) { /* now do the same for the second string */
  450. s2_p1_len = s2_p2 - s2;
  451. s2_p2++;
  452. } else {
  453. s2_p1_len = strlen(s2);
  454. s2_p2 = 0;
  455. }
  456. strncpy(str1, s1, (s1_p1_len > sizeof(str1)) ? s1_p1_len : sizeof(str1)); *(str1 + s1_p1_len) = 0;
  457. strncpy(str2, s2, (s2_p1_len > sizeof(str2)) ? s2_p1_len : sizeof(str2)); *(str2 + s2_p1_len) = 0;
  458. retval = strcmp(str1, str2);
  459. if (retval != 0) return retval; /* if they are not identical, then we can quit now and return the indication */
  460. return strcmp(s1_p2, s2_p2); /* otherwise we return the result of comparing the 2nd half of the string */
  461. }
  462. static void sort_if_table(void) {
  463. pcap_if_t *p1, *p2, *prev, *temp;
  464. int has_swapped;
  465. if (!acn_if_list) return; /* nothing to do if the list is empty */
  466. while (1) {
  467. p1 = acn_if_list; /* start at the head of the list */
  468. prev = 0;
  469. has_swapped = 0;
  470. while ((p2 = p1->next)) {
  471. if (if_sort(p1->name, p2->name) > 0) {
  472. if (prev) { /* we are swapping things that are _not_ at the head of the list */
  473. temp = p2->next;
  474. prev->next = p2;
  475. p2->next = p1;
  476. p1->next = temp;
  477. } else { /* special treatment if we are swapping with the head of the list */
  478. temp = p2->next;
  479. acn_if_list= p2;
  480. p2->next = p1;
  481. p1->next = temp;
  482. }
  483. p1 = p2;
  484. prev = p1;
  485. has_swapped = 1;
  486. }
  487. prev = p1;
  488. p1 = p1->next;
  489. }
  490. if (has_swapped == 0)
  491. return;
  492. }
  493. return;
  494. }
  495. static int process_client_data (char *errbuf) { /* returns: -1 = error, 0 = OK */
  496. int chassis, geoslot;
  497. unit_t *u;
  498. pcap_if_t *iff, *prev_iff;
  499. pcap_addr_t *addr, *prev_addr;
  500. char *ptr;
  501. int address_count;
  502. struct sockaddr_in *s;
  503. char *newname;
  504. bpf_u_int32 interfaceType;
  505. unsigned char flags;
  506. void *bigger_buffer;
  507. prev_iff = 0;
  508. for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) {
  509. for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) { /* now loop over all the devices */
  510. u = &units[chassis][geoslot];
  511. empty_unit_iface(u);
  512. ptr = u->imsg; /* point to the start of the msg for this IOP */
  513. while (ptr < (u->imsg + u->len)) {
  514. if ((iff = malloc(sizeof(pcap_if_t))) == NULL) {
  515. pcap_fmt_errmsg_for_errno(errbuf,
  516. PCAP_ERRBUF_SIZE, errno, "malloc");
  517. return -1;
  518. }
  519. memset((char *)iff, 0, sizeof(pcap_if_t)); /* bzero() is deprecated, replaced with memset() */
  520. if (acn_if_list == 0) acn_if_list = iff; /* remember the head of the list */
  521. if (prev_iff) prev_iff->next = iff; /* insert a forward link */
  522. if (*ptr) { /* if there is a count for the name */
  523. if ((iff->name = malloc(*ptr + 1)) == NULL) { /* get that amount of space */
  524. pcap_fmt_errmsg_for_errno(errbuf,
  525. PCAP_ERRBUF_SIZE, errno,
  526. "malloc");
  527. return -1;
  528. }
  529. memcpy(iff->name, (ptr + 1), *ptr); /* copy the name into the malloc'ed space */
  530. *(iff->name + *ptr) = 0; /* and null terminate the string */
  531. ptr += *ptr; /* now move the pointer forwards by the length of the count plus the length of the string */
  532. }
  533. ptr++;
  534. if (*ptr) { /* if there is a count for the description */
  535. if ((iff->description = malloc(*ptr + 1)) == NULL) { /* get that amount of space */
  536. pcap_fmt_errmsg_for_errno(errbuf,
  537. PCAP_ERRBUF_SIZE, errno,
  538. "malloc");
  539. return -1;
  540. }
  541. memcpy(iff->description, (ptr + 1), *ptr); /* copy the name into the malloc'ed space */
  542. *(iff->description + *ptr) = 0; /* and null terminate the string */
  543. ptr += *ptr; /* now move the pointer forwards by the length of the count plus the length of the string */
  544. }
  545. ptr++;
  546. interfaceType = ntohl(*(bpf_u_int32 *)ptr);
  547. ptr += 4; /* skip over the interface type */
  548. flags = *ptr++;
  549. if (flags) iff->flags = PCAP_IF_LOOPBACK; /* if this is a loopback style interface, lets mark it as such */
  550. address_count = *ptr++;
  551. prev_addr = 0;
  552. while (address_count--) {
  553. if ((addr = malloc(sizeof(pcap_addr_t))) == NULL) {
  554. pcap_fmt_errmsg_for_errno(errbuf,
  555. PCAP_ERRBUF_SIZE, errno,
  556. "malloc");
  557. return -1;
  558. }
  559. memset((char *)addr, 0, sizeof(pcap_addr_t)); /* bzero() is deprecated, replaced with memset() */
  560. if (iff->addresses == 0) iff->addresses = addr;
  561. if (prev_addr) prev_addr->next = addr; /* insert a forward link */
  562. if (*ptr) { /* if there is a count for the address */
  563. if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) { /* get that amount of space */
  564. pcap_fmt_errmsg_for_errno(errbuf,
  565. PCAP_ERRBUF_SIZE,
  566. errno, "malloc");
  567. return -1;
  568. }
  569. memset((char *)s, 0, sizeof(struct sockaddr_in)); /* bzero() is deprecated, replaced with memset() */
  570. addr->addr = (struct sockaddr *)s;
  571. s->sin_family = AF_INET;
  572. s->sin_addr.s_addr = *(bpf_u_int32 *)(ptr + 1); /* copy the address in */
  573. ptr += *ptr; /* now move the pointer forwards according to the specified length of the address */
  574. }
  575. ptr++; /* then forwards one more for the 'length of the address' field */
  576. if (*ptr) { /* process any netmask */
  577. if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) {
  578. pcap_fmt_errmsg_for_errno(errbuf,
  579. PCAP_ERRBUF_SIZE,
  580. errno, "malloc");
  581. return -1;
  582. }
  583. /* bzero() is deprecated, replaced with memset() */
  584. memset((char *)s, 0, sizeof(struct sockaddr_in));
  585. addr->netmask = (struct sockaddr *)s;
  586. s->sin_family = AF_INET;
  587. s->sin_addr.s_addr = *(bpf_u_int32*)(ptr + 1);
  588. ptr += *ptr;
  589. }
  590. ptr++;
  591. if (*ptr) { /* process any broadcast address */
  592. if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) {
  593. pcap_fmt_errmsg_for_errno(errbuf,
  594. PCAP_ERRBUF_SIZE,
  595. errno, "malloc");
  596. return -1;
  597. }
  598. /* bzero() is deprecated, replaced with memset() */
  599. memset((char *)s, 0, sizeof(struct sockaddr_in));
  600. addr->broadaddr = (struct sockaddr *)s;
  601. s->sin_family = AF_INET;
  602. s->sin_addr.s_addr = *(bpf_u_int32*)(ptr + 1);
  603. ptr += *ptr;
  604. }
  605. ptr++;
  606. if (*ptr) { /* process any destination address */
  607. if ((s = malloc(sizeof(struct sockaddr_in))) == NULL) {
  608. pcap_fmt_errmsg_for_errno(errbuf,
  609. PCAP_ERRBUF_SIZE,
  610. errno, "malloc");
  611. return -1;
  612. }
  613. /* bzero() is deprecated, replaced with memset() */
  614. memset((char *)s, 0, sizeof(struct sockaddr_in));
  615. addr->dstaddr = (struct sockaddr *)s;
  616. s->sin_family = AF_INET;
  617. s->sin_addr.s_addr = *(bpf_u_int32*)(ptr + 1);
  618. ptr += *ptr;
  619. }
  620. ptr++;
  621. prev_addr = addr;
  622. }
  623. prev_iff = iff;
  624. newname = translate_IOP_to_pcap_name(u, iff->name, interfaceType); /* add a translation entry and get a point to the mangled name */
  625. bigger_buffer = realloc(iff->name, strlen(newname) + 1));
  626. if (bigger_buffer == NULL) { /* we now re-write the name stored in the interface list */
  627. pcap_fmt_errmsg_for_errno(errbuf,
  628. PCAP_ERRBUF_SIZE, errno, "realloc");
  629. return -1;
  630. }
  631. iff->name = bigger_buffer;
  632. strcpy(iff->name, newname); /* to this new name */
  633. }
  634. }
  635. }
  636. return 0;
  637. }
  638. static int read_client_data (int fd) {
  639. unsigned char buf[256];
  640. int chassis, geoslot;
  641. unit_t *u;
  642. int len;
  643. find_unit_by_fd(fd, &chassis, &geoslot, &u);
  644. if ((len = recv(fd, buf, sizeof(buf), 0)) <= 0) return 0; /* read in whatever data was sent to us */
  645. if ((u->imsg = realloc(u->imsg, (u->len + len))) == NULL) /* extend the buffer for the new data */
  646. return 0;
  647. memcpy((u->imsg + u->len), buf, len); /* append the new data */
  648. u->len += len;
  649. return 1;
  650. }
  651. static void wait_for_all_answers(void) {
  652. int retval;
  653. struct timeval tv;
  654. int fd;
  655. int chassis, geoslot;
  656. tv.tv_sec = 2;
  657. tv.tv_usec = 0;
  658. while (1) {
  659. int flag = 0;
  660. fd_set working_set;
  661. for (fd = 0; fd <= max_fs; fd++) { /* scan the list of descriptors we may be listening to */
  662. if (FD_ISSET(fd, &readfds)) flag = 1; /* and see if there are any still set */
  663. }
  664. if (flag == 0) return; /* we are done, when they are all gone */
  665. memcpy(&working_set, &readfds, sizeof(readfds)); /* otherwise, we still have to listen for more stuff, till we timeout */
  666. retval = select(max_fs + 1, &working_set, NULL, NULL, &tv);
  667. if (retval == -1) { /* an error occured !!!!! */
  668. return;
  669. } else if (retval == 0) { /* timeout occured, so process what we've got sofar and return */
  670. printf("timeout\n");
  671. return;
  672. } else {
  673. for (fd = 0; fd <= max_fs; fd++) { /* scan the list of things to do, and do them */
  674. if (FD_ISSET(fd, &working_set)) {
  675. if (read_client_data(fd) == 0) { /* if the socket has closed */
  676. FD_CLR(fd, &readfds); /* and descriptors we listen to for errors */
  677. find_unit_by_fd(fd, &chassis, &geoslot, NULL);
  678. close_with_IOP(chassis, geoslot, FIND); /* and close out connection to him */
  679. }
  680. }
  681. }
  682. }
  683. }
  684. }
  685. static char *get_error_response(int fd, char *errbuf) { /* return a pointer on error, NULL on no error */
  686. char byte;
  687. int len = 0;
  688. while (1) {
  689. recv(fd, &byte, 1, 0); /* read another byte in */
  690. if (errbuf && (len++ < PCAP_ERRBUF_SIZE)) { /* and if there is still room in the buffer */
  691. *errbuf++ = byte; /* stick it in */
  692. *errbuf = '\0'; /* ensure the string is null terminated just in case we might exceed the buffer's size */
  693. }
  694. if (byte == '\0') {
  695. if (len > 1) { return errbuf; }
  696. else { return NULL; }
  697. }
  698. }
  699. }
  700. int acn_findalldevs(char *errbuf) { /* returns: -1 = error, 0 = OK */
  701. int chassis, geoslot;
  702. unit_t *u;
  703. FD_ZERO(&readfds);
  704. max_fs = 0;
  705. for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) {
  706. for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) {
  707. u = &units[chassis][geoslot];
  708. if (u->ip && (open_with_IOP(u, FIND))) { /* connect to the remote IOP */
  709. send_to_fd(u->find_fd, 1, (unsigned char *)"\0");
  710. if (get_error_response(u->find_fd, errbuf))
  711. close_with_IOP(chassis, geoslot, FIND);
  712. else {
  713. if (u->find_fd > max_fs)
  714. max_fs = u->find_fd; /* remember the highest number currently in use */
  715. FD_SET(u->find_fd, &readfds); /* we are going to want to read this guy's response to */
  716. u->len = 0;
  717. send_to_fd(u->find_fd, 1, (unsigned char *)"Q"); /* this interface query request */
  718. }
  719. }
  720. }
  721. }
  722. wait_for_all_answers();
  723. if (process_client_data(errbuf))
  724. return -1;
  725. sort_if_table();
  726. return 0;
  727. }
  728. static int pcap_stats_acn(pcap_t *handle, struct pcap_stat *ps) {
  729. unsigned char buf[12];
  730. send_to_fd(handle->fd, 1, (unsigned char *)"S"); /* send the get_stats command to the IOP */
  731. if (read_client_nbytes(handle->fd, sizeof(buf), buf) == -1) return -1; /* try reading the required bytes */
  732. ps->ps_recv = ntohl(*(uint32_t *)&buf[0]); /* break the buffer into its three 32 bit components */
  733. ps->ps_drop = ntohl(*(uint32_t *)&buf[4]);
  734. ps->ps_ifdrop = ntohl(*(uint32_t *)&buf[8]);
  735. return 0;
  736. }
  737. static int acn_open_live(const char *name, char *errbuf, int *linktype) { /* returns 0 on error, else returns the file descriptor */
  738. int chassis, geoslot;
  739. unit_t *u;
  740. iface_t *p;
  741. pcap_if_list_t devlist;
  742. pcap_platform_finddevs(&devlist, errbuf);
  743. for (chassis = 0; chassis <= MAX_CHASSIS; chassis++) { /* scan the table... */
  744. for (geoslot = 0; geoslot <= MAX_GEOSLOT; geoslot++) {
  745. u = &units[chassis][geoslot];
  746. if (u->ip != NULL) {
  747. p = u->iface;
  748. while (p) { /* and all interfaces... */
  749. if (p->IOPname && p->name && (strcmp(p->name, name) == 0)) { /* and if we found the interface we want... */
  750. *linktype = p->iftype;
  751. open_with_IOP(u, LIVE); /* start a connection with that IOP */
  752. send_to_fd(u->fd, strlen(p->IOPname)+1, (unsigned char *)p->IOPname); /* send the IOP's interface name, and a terminating null */
  753. if (get_error_response(u->fd, errbuf)) {
  754. return -1;
  755. }
  756. return u->fd; /* and return that open descriptor */
  757. }
  758. p = p->next;
  759. }
  760. }
  761. }
  762. }
  763. return -1; /* if the interface wasn't found, return an error */
  764. }
  765. static void acn_start_monitor(int fd, int snaplen, int timeout, int promiscuous, int direction) {
  766. unsigned char buf[8];
  767. unit_t *u;
  768. //printf("acn_start_monitor()\n"); // fulko
  769. find_unit_by_fd(fd, NULL, NULL, &u);
  770. if (u->first_time == 0) {
  771. buf[0] = 'M';
  772. *(uint32_t *)&buf[1] = htonl(snaplen);
  773. buf[5] = timeout;
  774. buf[6] = promiscuous;
  775. buf[7] = direction;
  776. //printf("acn_start_monitor() first time\n"); // fulko
  777. send_to_fd(fd, 8, buf); /* send the start monitor command with its parameters to the IOP */
  778. u->first_time = 1;
  779. }
  780. //printf("acn_start_monitor() complete\n"); // fulko
  781. }
  782. static int pcap_inject_acn(pcap_t *p, const void *buf _U_, size_t size _U_) {
  783. strlcpy(p->errbuf, "Sending packets isn't supported on ACN adapters",
  784. PCAP_ERRBUF_SIZE);
  785. return (-1);
  786. }
  787. static int pcap_setfilter_acn(pcap_t *handle, struct bpf_program *bpf) {
  788. int fd = handle->fd;
  789. int count;
  790. struct bpf_insn *p;
  791. uint16_t shortInt;
  792. uint32_t longInt;
  793. send_to_fd(fd, 1, (unsigned char *)"F"); /* BPF filter follows command */
  794. count = bpf->bf_len;
  795. longInt = htonl(count);
  796. send_to_fd(fd, 4, (unsigned char *)&longInt); /* send the instruction sequence count */
  797. p = bpf->bf_insns;
  798. while (count--) { /* followed by the list of instructions */
  799. shortInt = htons(p->code);
  800. longInt = htonl(p->k);
  801. send_to_fd(fd, 2, (unsigned char *)&shortInt);
  802. send_to_fd(fd, 1, (unsigned char *)&p->jt);
  803. send_to_fd(fd, 1, (unsigned char *)&p->jf);
  804. send_to_fd(fd, 4, (unsigned char *)&longInt);
  805. p++;
  806. }
  807. if (get_error_response(fd, NULL))
  808. return -1;
  809. return 0;
  810. }
  811. static int pcap_setdirection_acn(pcap_t *handle, pcap_direction_t d) {
  812. pcap_snprintf(handle->errbuf, sizeof(handle->errbuf),
  813. "Setting direction is not supported on ACN adapters");
  814. return -1;
  815. }
  816. static int acn_read_n_bytes_with_timeout(pcap_t *handle, int count) {
  817. struct timeval tv;
  818. int retval, fd;
  819. fd_set r_fds;
  820. fd_set w_fds;
  821. u_char *bp;
  822. int len = 0;
  823. int offset = 0;
  824. tv.tv_sec = 5;
  825. tv.tv_usec = 0;
  826. fd = handle->fd;
  827. FD_ZERO(&r_fds);
  828. FD_SET(fd, &r_fds);
  829. memcpy(&w_fds, &r_fds, sizeof(r_fds));
  830. bp = handle->bp;
  831. while (count) {
  832. retval = select(fd + 1, &w_fds, NULL, NULL, &tv);
  833. if (retval == -1) { /* an error occured !!!!! */
  834. // fprintf(stderr, "error during packet data read\n");
  835. return -1; /* but we need to return a good indication to prevent unneccessary popups */
  836. } else if (retval == 0) { /* timeout occured, so process what we've got sofar and return */
  837. // fprintf(stderr, "timeout during packet data read\n");
  838. return -1;
  839. } else {
  840. if ((len = recv(fd, (bp + offset), count, 0)) <= 0) {
  841. // fprintf(stderr, "premature exit during packet data rx\n");
  842. return -1;
  843. }
  844. count -= len;
  845. offset += len;
  846. }
  847. }
  848. return 0;
  849. }
  850. static int pcap_read_acn(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user) {
  851. #define HEADER_SIZE (4 * 4)
  852. unsigned char packet_header[HEADER_SIZE];
  853. struct pcap_pkthdr pcap_header;
  854. //printf("pcap_read_acn()\n"); // fulko
  855. acn_start_monitor(handle->fd, handle->snapshot, handle->opt.timeout, handle->opt.promisc, handle->direction); /* maybe tell him to start monitoring */
  856. //printf("pcap_read_acn() after start monitor\n"); // fulko
  857. handle->bp = packet_header;
  858. if (acn_read_n_bytes_with_timeout(handle, HEADER_SIZE) == -1) return 0; /* try to read a packet header in so we can get the sizeof the packet data */
  859. pcap_header.ts.tv_sec = ntohl(*(uint32_t *)&packet_header[0]); /* tv_sec */
  860. pcap_header.ts.tv_usec = ntohl(*(uint32_t *)&packet_header[4]); /* tv_usec */
  861. pcap_header.caplen = ntohl(*(uint32_t *)&packet_header[8]); /* caplen */
  862. pcap_header.len = ntohl(*(uint32_t *)&packet_header[12]); /* len */
  863. handle->bp = (u_char *)handle->buffer + handle->offset; /* start off the receive pointer at the right spot */
  864. if (acn_read_n_bytes_with_timeout(handle, pcap_header.caplen) == -1) return 0; /* then try to read in the rest of the data */
  865. callback(user, &pcap_header, handle->bp); /* call the user supplied callback function */
  866. return 1;
  867. }
  868. static int pcap_activate_sita(pcap_t *handle) {
  869. int fd;
  870. if (handle->opt.rfmon) {
  871. /*
  872. * No monitor mode on SITA devices (they're not Wi-Fi
  873. * devices).
  874. */
  875. return PCAP_ERROR_RFMON_NOTSUP;
  876. }
  877. /* Initialize some components of the pcap structure. */
  878. handle->inject_op = pcap_inject_acn;
  879. handle->setfilter_op = pcap_setfilter_acn;
  880. handle->setdirection_op = pcap_setdirection_acn;
  881. handle->set_datalink_op = NULL; /* can't change data link type */
  882. handle->getnonblock_op = pcap_getnonblock_fd;
  883. handle->setnonblock_op = pcap_setnonblock_fd;
  884. handle->cleanup_op = pcap_cleanup_acn;
  885. handle->read_op = pcap_read_acn;
  886. handle->stats_op = pcap_stats_acn;
  887. fd = acn_open_live(handle->opt.device, handle->errbuf,
  888. &handle->linktype);
  889. if (fd == -1)
  890. return PCAP_ERROR;
  891. /*
  892. * Turn a negative snapshot value (invalid), a snapshot value of
  893. * 0 (unspecified), or a value bigger than the normal maximum
  894. * value, into the maximum allowed value.
  895. *
  896. * If some application really *needs* a bigger snapshot
  897. * length, we should just increase MAXIMUM_SNAPLEN.
  898. */
  899. if (handle->snapshot <= 0 || handle->snapshot > MAXIMUM_SNAPLEN)
  900. handle->snapshot = MAXIMUM_SNAPLEN;
  901. handle->fd = fd;
  902. handle->bufsize = handle->snapshot;
  903. /* Allocate the buffer */
  904. handle->buffer = malloc(handle->bufsize + handle->offset);
  905. if (!handle->buffer) {
  906. pcap_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
  907. errno, "malloc");
  908. pcap_cleanup_acn(handle);
  909. return PCAP_ERROR;
  910. }
  911. /*
  912. * "handle->fd" is a socket, so "select()" and "poll()"
  913. * should work on it.
  914. */
  915. handle->selectable_fd = handle->fd;
  916. return 0;
  917. }
  918. pcap_t *pcap_create_interface(const char *device _U_, char *ebuf) {
  919. pcap_t *p;
  920. p = pcap_create_common(ebuf, 0);
  921. if (p == NULL)
  922. return (NULL);
  923. p->activate_op = pcap_activate_sita;
  924. return (p);
  925. }
  926. int pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf) {
  927. //printf("pcap_findalldevs()\n"); // fulko
  928. *alldevsp = 0; /* initialize the returned variables before we do anything */
  929. strcpy(errbuf, "");
  930. if (acn_parse_hosts_file(errbuf)) /* scan the hosts file for potential IOPs */
  931. {
  932. //printf("pcap_findalldevs() returning BAD after parsehosts\n"); // fulko
  933. return -1;
  934. }
  935. //printf("pcap_findalldevs() got hostlist now finding devs\n"); // fulko
  936. if (acn_findalldevs(errbuf)) /* then ask the IOPs for their monitorable devices */
  937. {
  938. //printf("pcap_findalldevs() returning BAD after findalldevs\n"); // fulko
  939. return -1;
  940. }
  941. devlistp->beginning = acn_if_list;
  942. acn_if_list = 0; /* then forget our list head, because someone will call pcap_freealldevs() to empty the malloc'ed stuff */
  943. //printf("pcap_findalldevs() returning ZERO OK\n"); // fulko
  944. return 0;
  945. }
  946. /*
  947. * Libpcap version string.
  948. */
  949. const char *
  950. pcap_lib_version(void)
  951. {
  952. return PCAP_VERSION_STRING " (SITA-only)";
  953. }