Added two new arguments to epan_init() and proto_init() to
[obnox/wireshark/wip.git] / libpcap-0.5.HPUX.tcpdump.org.patch
1 Index: aclocal.m4
2 ===================================================================
3 RCS file: /tcpdump/master/libpcap/aclocal.m4,v
4 retrieving revision 1.66
5 diff -c -r1.66 aclocal.m4
6 *** aclocal.m4  1999/10/30 04:41:48     1.66
7 --- aclocal.m4  2000/08/13 07:23:45
8 ***************
9 *** 415,420 ****
10 --- 415,454 ----
11       fi])
12   
13   dnl
14 + dnl Checks to see if the dl_hp_ppa_info_t struct has the HP-UX 11.00
15 + dnl dl_module_id_1 member
16 + dnl
17 + dnl usage:
18 + dnl
19 + dnl   AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1
20 + dnl
21 + dnl results:
22 + dnl
23 + dnl   HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1 (defined)
24 + dnl
25 + dnl NOTE: any compile failure means we conclude that it doesn't have
26 + dnl that member, so if we don't have DLPI, don't have a <sys/dlpi_ext.h>
27 + dnl header, or have one that doesn't declare a dl_hp_ppa_info_t type,
28 + dnl we conclude it doesn't have that member (which is OK, as either we
29 + dnl won't be using code that would use that member, or we wouldn't
30 + dnl compile in any case).
31 + dnl
32 + AC_DEFUN(AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1,
33 +     [AC_MSG_CHECKING(if dl_hp_ppa_info_t struct has dl_module_id_1 member)
34 +     AC_CACHE_VAL(ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1,
35 +       AC_TRY_COMPILE([
36 + #     include <sys/types.h>
37 + #     include <sys/dlpi.h>
38 + #     include <sys/dlpi_ext.h>],
39 +       [u_int i = sizeof(((dl_hp_ppa_info_t *)0)->dl_module_id_1)],
40 +       ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=yes,
41 +       ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=no))
42 +     AC_MSG_RESULT($ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1)
43 +     if test $ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1 = yes ; then
44 +           AC_DEFINE(HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1)
45 +     fi])
46
47 + dnl
48   dnl Checks to see if -R is used
49   dnl
50   dnl usage:
51 Index: configure
52 ===================================================================
53 RCS file: /tcpdump/master/libpcap/configure,v
54 retrieving revision 1.5
55 diff -c -r1.5 configure
56 *** configure   1999/11/01 15:56:40     1.5
57 --- configure   2000/08/13 07:23:50
58 ***************
59 *** 1822,1829 ****
60   
61       fi
62   
63   echo $ac_n "checking if unaligned accesses fail""... $ac_c" 1>&6
64 ! echo "configure:1827: checking if unaligned accesses fail" >&5
65       if eval "test \"`echo '$''{'ac_cv_lbl_unaligned_fail'+set}'`\" = set"; then
66     echo $ac_n "(cached) $ac_c" 1>&6
67   else
68 --- 1822,1865 ----
69   
70       fi
71   
72 + echo $ac_n "checking if dl_hp_ppa_info_t struct has dl_module_id_1 member""... $ac_c" 1>&6
73 + echo "configure:1827: checking if dl_hp_ppa_info_t struct has dl_module_id_1 member" >&5
74 +     if eval "test \"`echo '$''{'ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1'+set}'`\" = set"; then
75 +   echo $ac_n "(cached) $ac_c" 1>&6
76 + else
77 +   cat > conftest.$ac_ext <<EOF
78 + #line 1832 "configure"
79 + #include "confdefs.h"
80
81 + #     include <sys/types.h>
82 + #     include <sys/dlpi.h>
83 + #     include <sys/dlpi_ext.h>
84 + int main() {
85 + u_int i = sizeof(((dl_hp_ppa_info_t *)0)->dl_module_id_1)
86 + ; return 0; }
87 + EOF
88 + if { (eval echo configure:1842: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
89 +   rm -rf conftest*
90 +   ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=yes
91 + else
92 +   echo "configure: failed program was:" >&5
93 +   cat conftest.$ac_ext >&5
94 +   rm -rf conftest*
95 +   ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=no
96 + fi
97 + rm -f conftest*
98 + fi
99
100 +     echo "$ac_t""$ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1" 1>&6
101 +     if test $ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1 = yes ; then
102 +           cat >> confdefs.h <<\EOF
103 + #define HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1 1
104 + EOF
105
106 +     fi
107
108   echo $ac_n "checking if unaligned accesses fail""... $ac_c" 1>&6
109 ! echo "configure:1863: checking if unaligned accesses fail" >&5
110       if eval "test \"`echo '$''{'ac_cv_lbl_unaligned_fail'+set}'`\" = set"; then
111     echo $ac_n "(cached) $ac_c" 1>&6
112   else
113 ***************
114 *** 1912,1918 ****
115   # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
116   # ./install, which can be erroneously created by make from ./install.sh.
117   echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
118 ! echo "configure:1916: checking for a BSD compatible install" >&5
119   if test -z "$INSTALL"; then
120   if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
121     echo $ac_n "(cached) $ac_c" 1>&6
122 --- 1948,1954 ----
123   # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
124   # ./install, which can be erroneously created by make from ./install.sh.
125   echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
126 ! echo "configure:1952: checking for a BSD compatible install" >&5
127   if test -z "$INSTALL"; then
128   if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
129     echo $ac_n "(cached) $ac_c" 1>&6
130 Index: configure.in
131 ===================================================================
132 RCS file: /tcpdump/master/libpcap/configure.in,v
133 retrieving revision 1.71
134 diff -c -r1.71 configure.in
135 *** configure.in        1999/11/01 15:56:40     1.71
136 --- configure.in        2000/08/13 07:23:51
137 ***************
138 *** 175,180 ****
139 --- 175,182 ----
140   
141   AC_LBL_SOCKADDR_SA_LEN
142   
143 + AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1
144
145   AC_LBL_UNALIGNED_ACCESS
146   
147   if test -r ${srcdir}/lbl/gnuc.h ; then
148 Index: pcap-dlpi.c
149 ===================================================================
150 RCS file: /tcpdump/master/libpcap/pcap-dlpi.c,v
151 retrieving revision 1.52.1.1
152 diff -c -r1.52.1.1 pcap-dlpi.c
153 *** pcap-dlpi.c 1999/10/07 23:46:40     1.52.1.1
154 --- pcap-dlpi.c 2000/08/13 07:23:52
155 ***************
156 *** 246,255 ****
157         }
158         memset(p, 0, sizeof(*p));
159   
160         /*
161 !       ** Determine device and ppa
162         */
163 !       cp = strpbrk(device, "0123456789");
164         if (cp == NULL) {
165                 sprintf(ebuf, "%s missing unit number", device);
166                 goto bad;
167 --- 246,266 ----
168         }
169         memset(p, 0, sizeof(*p));
170   
171 + #ifdef HAVE_DEV_DLPI
172         /*
173 !       ** Remove any "/dev/" on the front of the device.
174         */
175 !       cp = strrchr(device, '/');
176 !       if (cp == NULL)
177 !               cp = device;
178 !       else
179 !               cp++;
180 !       strcpy(dname, cp);
181
182 !       /*
183 !        * Split the name into a device type and a unit number.
184 !        */
185 !       cp = strpbrk(dname, "0123456789");
186         if (cp == NULL) {
187                 sprintf(ebuf, "%s missing unit number", device);
188                 goto bad;
189 ***************
190 *** 259,281 ****
191                 sprintf(ebuf, "%s bad unit number", device);
192                 goto bad;
193         }
194   
195 !       if (*device == '/')
196 !               strcpy(dname, device);
197 !       else
198 !               sprintf(dname, "%s/%s", PCAP_DEV_PREFIX, device);
199 ! #ifdef HAVE_DEV_DLPI
200 !       /* Map network device to /dev/dlpi unit */
201         cp = "/dev/dlpi";
202         if ((p->fd = open(cp, O_RDWR)) < 0) {
203                 sprintf(ebuf, "%s: %s", cp, pcap_strerror(errno));
204                 goto bad;
205         }
206 !       /* Map network interface to /dev/dlpi unit */
207         ppa = get_dlpi_ppa(p->fd, dname, ppa, ebuf);
208         if (ppa < 0)
209                 goto bad;
210   #else
211         /* Try device without unit number */
212         strcpy(dname2, dname);
213         cp = strchr(dname, *cp);
214 --- 270,321 ----
215                 sprintf(ebuf, "%s bad unit number", device);
216                 goto bad;
217         }
218 +       *cp = '\0';
219   
220 !       /*
221 !        * Use "/dev/dlpi" as the device.
222 !        *
223 !        * XXX - HP's DLPI Programmer's Guide for HP-UX 11.00 says that
224 !        * the "dl_mjr_num" field is for the "major number of interface
225 !        * driver"; that's the major of "/dev/dlpi" on the system on
226 !        * which I tried this, but there may be DLPI devices that
227 !        * use a different driver, in which case we may need to
228 !        * search "/dev" for the appropriate device with that major
229 !        * device number, rather than hardwiring "/dev/dlpi".
230 !        */
231         cp = "/dev/dlpi";
232         if ((p->fd = open(cp, O_RDWR)) < 0) {
233                 sprintf(ebuf, "%s: %s", cp, pcap_strerror(errno));
234                 goto bad;
235         }
236
237 !       /*
238 !        * Get a table of all PPAs for that device, and search that
239 !        * table for the specified device type name and unit number.
240 !        */
241         ppa = get_dlpi_ppa(p->fd, dname, ppa, ebuf);
242         if (ppa < 0)
243                 goto bad;
244   #else
245 +       /*
246 +       ** Determine device and ppa
247 +       */
248 +       cp = strpbrk(device, "0123456789");
249 +       if (cp == NULL) {
250 +               sprintf(ebuf, "%s missing unit number", device);
251 +               goto bad;
252 +       }
253 +       ppa = strtol(cp, &eos, 10);
254 +       if (*eos != '\0') {
255 +               sprintf(ebuf, "%s bad unit number", device);
256 +               goto bad;
257 +       }
258
259 +       if (*device == '/')
260 +               strcpy(dname, device);
261 +       else
262 +               sprintf(dname, "%s/%s", PCAP_DEV_PREFIX, device);
263
264         /* Try device without unit number */
265         strcpy(dname2, dname);
266         cp = strchr(dname, *cp);
267 ***************
268 *** 391,397 ****
269                 break;
270   
271         default:
272 !               sprintf(ebuf, "unknown mac type 0x%lu", infop->dl_mac_type);
273                 goto bad;
274         }
275   
276 --- 431,438 ----
277                 break;
278   
279         default:
280 !               sprintf(ebuf, "unknown mac type 0x%lu",
281 !                   (unsigned long)infop->dl_mac_type);
282                 goto bad;
283         }
284   
285 ***************
286 *** 709,737 ****
287   
288   #ifdef DL_HP_PPA_ACK_OBS
289   /*
290 !  * Under HP-UX 10, we can ask for the ppa
291    */
292   
293   
294 ! /* Determine ppa number that specifies ifname */
295   static int
296   get_dlpi_ppa(register int fd, register const char *device, register int unit,
297       register char *ebuf)
298   {
299         register dl_hp_ppa_ack_t *ap;
300 !       register dl_hp_ppa_info_t *ip;
301         register int i;
302         register u_long majdev;
303 -       dl_hp_ppa_req_t req;
304         struct stat statbuf;
305         bpf_u_int32 buf[MAXDLBUF];
306   
307 -       if (stat(device, &statbuf) < 0) {
308 -               sprintf(ebuf, "stat: %s: %s", device, pcap_strerror(errno));
309 -               return (-1);
310 -       }
311 -       majdev = major(statbuf.st_rdev);
312
313         memset((char *)&req, 0, sizeof(req));
314         req.dl_primitive = DL_HP_PPA_REQ;
315   
316 --- 750,806 ----
317   
318   #ifdef DL_HP_PPA_ACK_OBS
319   /*
320 !  * Under HP-UX 10 and HP-UX 11, we can ask for the ppa
321    */
322   
323   
324 ! /*
325 !  * Determine ppa number that specifies ifname.
326 !  *
327 !  * If the "dl_hp_ppa_info_t" doesn't have a "dl_module_id_1" member,
328 !  * the code that's used here is the old code for HP-UX 10.x.
329 !  *
330 !  * However, HP-UX 10.20, at least, appears to have such a member
331 !  * in its "dl_hp_ppa_info_t" structure, so the new code is used.
332 !  * The new code didn't work on an old 10.20 system on which Rick
333 !  * Jones of HP tried it, but with later patches installed, it
334 !  * worked - it appears that the older system had those members but
335 !  * didn't put anything in them, so, if the search by name fails, we
336 !  * do the old search.
337 !  *
338 !  * Rick suggests that making sure your system is "up on the latest
339 !  * lancommon/DLPI/driver patches" is probably a good idea; it'd fix
340 !  * that problem, as well as allowing libpcap to see packets sent
341 !  * from the system on which the libpcap application is being run.
342 !  * (On 10.20, in addition to getting the latest patches, you need
343 !  * to turn the kernel "lanc_outbound_promisc_flag" flag on with ADB;
344 !  * a posting to "comp.sys.hp.hpux" at
345 !  *
346 !  *    http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=558092266
347 !  *
348 !  * says that, to see the machine's outgoing traffic, you'd need to
349 !  * apply the right patches to your system, and also set that variable
350 !  * with:
351 !  
352 ! echo 'lanc_outbound_promisc_flag/W1' | /usr/bin/adb -w /stand/vmunix /dev/kmem
353
354 !  * which could be put in, for example, "/sbin/init.d/lan".
355 !  *
356 !  * Setting the variable is not necessary on HP-UX 11.x.
357 !  */
358   static int
359   get_dlpi_ppa(register int fd, register const char *device, register int unit,
360       register char *ebuf)
361   {
362         register dl_hp_ppa_ack_t *ap;
363 !       register dl_hp_ppa_info_t *ipstart, *ip;
364         register int i;
365 +       char dname[100];
366         register u_long majdev;
367         struct stat statbuf;
368 +       dl_hp_ppa_req_t req;
369         bpf_u_int32 buf[MAXDLBUF];
370   
371         memset((char *)&req, 0, sizeof(req));
372         req.dl_primitive = DL_HP_PPA_REQ;
373   
374 ***************
375 *** 741,760 ****
376                 return (-1);
377   
378         ap = (dl_hp_ppa_ack_t *)buf;
379 !       ip = (dl_hp_ppa_info_t *)((u_char *)ap + ap->dl_offset);
380   
381 !         for(i = 0; i < ap->dl_count; i++) {
382 !                 if (ip->dl_mjr_num == majdev && ip->dl_instance_num == unit)
383 !                         break;
384   
385 !                 ip = (dl_hp_ppa_info_t *)((u_char *)ip + ip->dl_next_offset);
386 !         }
387           if (i == ap->dl_count) {
388 !                 sprintf(ebuf, "can't find PPA for %s", device);
389                 return (-1);
390           }
391           if (ip->dl_hdw_state == HDW_DEAD) {
392 !                 sprintf(ebuf, "%s: hardware state: DOWN\n", device);
393                 return (-1);
394           }
395           return ((int)ip->dl_ppa);
396 --- 810,887 ----
397                 return (-1);
398   
399         ap = (dl_hp_ppa_ack_t *)buf;
400 !       ipstart = (dl_hp_ppa_info_t *)((u_char *)ap + ap->dl_offset);
401 !       ip = ipstart;
402   
403 ! #ifdef HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1
404 !       /*
405 !        * The "dl_hp_ppa_info_t" structure has a "dl_module_id_1"
406 !        * member that should, in theory, contain the part of the
407 !        * name for the device that comes before the unit number,
408 !        * and should also have a "dl_module_id_2" member that may
409 !        * contain an alternate name (e.g., I think Ethernet devices
410 !        * have both "lan", for "lanN", and "snap", for "snapN", with
411 !        * the former being for Ethernet packets and the latter being
412 !        * for 802.3/802.2 packets).
413 !        *
414 !        * Search for the device that has the specified name and
415 !        * instance number.
416 !        */
417 !       for (i = 0; i < ap->dl_count; i++) {
418 !               if ((strcmp(ip->dl_module_id_1, device) == 0 ||
419 !                    strcmp(ip->dl_module_id_2, device) == 0) &&
420 !                   ip->dl_instance_num == unit)
421 !                       break;
422   
423 !               ip = (dl_hp_ppa_info_t *)((u_char *)ipstart + ip->dl_next_offset);
424 !       }
425 ! #else
426 !       /*
427 !        * We don't have that member, so the search is impossible; make it
428 !        * look as if the search failed.
429 !        */
430 !       i = ap->dl_count;
431 ! #endif
432
433 !       if (i == ap->dl_count) {
434 !               /*
435 !                * Well, we didn't, or can't, find the device by name.
436 !                *
437 !                * HP-UX 10.20, whilst it has "dl_module_id_1" and
438 !                * "dl_module_id_2" fields in the "dl_hp_ppa_info_t",
439 !                * doesn't seem to fill them in unless the system is
440 !                * at a reasonably up-to-date patch level.
441 !                *
442 !                * Older HP-UX 10.x systems might not have those fields
443 !                * at all.
444 !                *
445 !                * Therefore, we'll search for the entry with the major
446 !                * device number of a device with the name "/dev/<dev><unit>",
447 !                * if such a device exists, as the old code did.
448 !                */
449 !               sprintf(dname, "/dev/%s%d", device, unit);
450 !               if (stat(dname, &statbuf) < 0) {
451 !                       sprintf(ebuf, "stat: %s: %s", dname, pcap_strerror(errno));
452 !                       return (-1);
453 !               }
454 !               majdev = major(statbuf.st_rdev);
455
456 !               ip = ipstart;
457
458 !               for (i = 0; i < ap->dl_count; i++) {
459 !                       if (ip->dl_mjr_num == majdev &&
460 !                           ip->dl_instance_num == unit)
461 !                               break;
462
463 !                       ip = (dl_hp_ppa_info_t *)((u_char *)ipstart + ip->dl_next_offset);
464 !               }
465 !       }
466           if (i == ap->dl_count) {
467 !                 sprintf(ebuf, "can't find /dev/dlpi PPA for %s%d", device, unit);
468                 return (-1);
469           }
470           if (ip->dl_hdw_state == HDW_DEAD) {
471 !                 sprintf(ebuf, "%s%d: hardware state: DOWN\n", device, unit);
472                 return (-1);
473           }
474           return ((int)ip->dl_ppa);
475 ***************
476 *** 783,789 ****
477         register int kd;
478         void *addr;
479         struct ifnet ifnet;
480 !       char if_name[sizeof(ifnet.if_name)], tifname[32];
481   
482         cp = strrchr(ifname, '/');
483         if (cp != NULL)
484 --- 910,916 ----
485         register int kd;
486         void *addr;
487         struct ifnet ifnet;
488 !       char if_name[sizeof(ifnet.if_name) + 1];
489   
490         cp = strrchr(ifname, '/');
491         if (cp != NULL)
492 ***************
493 *** 811,823 ****
494                 if (dlpi_kread(kd, (off_t)addr,
495                     &ifnet, sizeof(ifnet), ebuf) < 0 ||
496                     dlpi_kread(kd, (off_t)ifnet.if_name,
497 !                   if_name, sizeof(if_name), ebuf) < 0) {
498                         (void)close(kd);
499                         return (-1);
500                 }
501 !               sprintf(tifname, "%.*s%d",
502 !                   (int)sizeof(if_name), if_name, ifnet.if_unit);
503 !               if (strcmp(tifname, ifname) == 0)
504                         return (ifnet.if_index);
505         }
506   
507 --- 938,949 ----
508                 if (dlpi_kread(kd, (off_t)addr,
509                     &ifnet, sizeof(ifnet), ebuf) < 0 ||
510                     dlpi_kread(kd, (off_t)ifnet.if_name,
511 !                   if_name, sizeof(ifnet.if_name), ebuf) < 0) {
512                         (void)close(kd);
513                         return (-1);
514                 }
515 !               if_name[sizeof(ifnet.if_name)] = '\0';
516 !               if (strcmp(if_name, ifname) == 0 && ifnet.if_unit == unit)
517                         return (ifnet.if_index);
518         }
519