package list_modules; # $Id$ use MDK::Common; our @ISA = qw(Exporter); our @EXPORT = qw(load_dependencies dependencies_closure category2modules module2category sub_categories); # the categories have 2 purposes # - choosing modules to include on stage1's (cf update_kernel and mdk-stage1/pci-resource/update-pci-ids.pl) # - performing a load_category or probe_category (detect_devices.pm and many files in perl-install) our %l = ( ################################################################################ network => { atm => [ qw(ambassador eni firestream fore_200e he horizon idt77252 iphase lanai nicstar solos-pci zatm) ], main => [ if_(arch() =~ /ppc/, qw(bmac fec_mpc52xx ibm_emac mace oaknet sungem)), if_(arch() =~ /^sparc/, qw(sunbmac sunhme sunqe)), if_(arch() !~ /alpha|sparc/, qw(3c501 3c503 3c505 3c507 3c509 3c515 3c990 3c990fx), qw(82596 ac3200 acenic aironet4500_card amd8111e at1700 atl2 atp), qw(bcm4400 cassini cs89x0 de600 de620), qw(depca dmfe e2100 eepro eexpress enic eth16i), qw(ewrk3 hp hp-plus hp100), qw(iph5526), #- fibre channel qw(jme lance ne ni5010 ni52 ni65 nvnet), qw(prism2_plx qlge r6040 rcpci rhineget), qw(sb1000 sc92031 smc-ultra smc9194 smsc9420 smsc95xx), qw(tc35815 tlan uli526x), ), if_(arch() !~ /alpha/, qw(b44 com20020-pci de2104x), qw(defxx), # most unused qw(dgrs e100 eepro100 epic100 fealnx hamachi natsemi), qw(ne2k-pci pcnet32 plip sis900 skfp starfire tulip), qw(typhoon via-rhine winbond-840 forcedeth), qw(sungem sunhme), # drivers for ultrasparc, but compiled in ix86 kernels... ), qw(3c59x 8139too 8139cp cpmac niu sundance), #rtl8139 ], firewire => [ qw(eth1394 pcilynx) ], gigabit => [ qw(atl1 atl1c atl1e be2net bnx2 bnx2x cxgb cxgb3 dl2k e1000 e1000e et131x igb ipg ixgb ixgbe myri_sbus netxen_nic ns83820 qla3xxx r8169 s2io sfc sxg_nic sis190 sk98lin skge sky2 slicoss spidernet tehuti tg3 via-velocity virtio_net vxge yellowfin), qw(bcm5820 bcm5700), #- encrypted ], raw => [ qw(ppp_generic ppp_async ppp_deflate bsd_comp), ], pcmcia => [ qw(3c574_cs 3c589_cs axnet_cs fmvj18x_cs), qw(ibmtr_cs libertas_cs nmclan_cs pcnet_cs smc91c92_cs), qw(xirc2ps_cs xircom_cb xircom_tulip_cb), ], #- generic NIC detection for USB seems broken (class, subclass, #- protocol reported are not accurate) so we match network adapters against #- known drivers :-( usb => [ qw(asix catc cdc_ether kaweth pegasus rtl8150 usbnet), ], wireless => [ qw(acx-pci acx-usb adm8211 agnx airo airo_cs aironet4500_cs aironet_cs ar9170usb arlan arusb_lnx), qw(at76_usb ath_pci ath5k ath9k atmel_cs atmel_pci b43 b43legacy bcm43xx com20020_cs dyc_ar5), qw(hostap_cs hostap_pci hostap_plx i2400m-usb ipw2100 ipw2200 ipw3945 iwl3945 iwl4965 iwlagn iwlwifi), qw(madwifi_pci mwl8k netwave_cs ndiswrapper orinoco orinoco_cs orinoco_nortel orinoco_pci orinoco_plx orinoco_tmd), qw(p54pci p54usb prism2_cs prism2_pci prism2_usb prism54 r8180 r8192s_usb ray_cs rndis_wlan), qw(rt2400 rt2500 rt2570 rt2860 rt2860sta rt2800usb rt2870 rt2870sta rt3070sta rt61 rt73 rtusb), qw(rt2400pci rt2500pci rt2500usb rt61pci rt73usb rtl8180 rtl8187se), qw(spectrum_cs usbvnet_rfmd vt_ar5k w35und wavelan_cs wl wl3501_cs wvlan_cs zd1201 zd1211rw), if_(arch() =~ /ppc/, qw(airport)), ], isdn => [ qw(avmfritz c4 cdc-acm b1pci divas hfc4s8s_l1 hfc_usb hfc4s8s_l1 hisax hisax_st5481 hisax_fcpcipnp hysdn sedlfax t1pci tpam w6692pci), qw(hfcpci hfcmulti hfcsusb), # mISDN qw(fcpci fcdsl fcdsl fcdsl2 fcdslsl fcdslslusb fcdslusb fcdslusba fcusb fcusb2 fxusb fxusb_CZ) ], cellular => [ qw(hso nozomi option sierra), ], modem => [ qw(ltmodem mwave sm56), ], slmodem => [ qw(slamr slusb snd-ali5451 snd-atiixp-modem snd-intel8x0m snd-via82xx-modem), ], tokenring => [ qw(3c359 abyss ibmtr lanstreamer olympic proteon skisa smctr tms380tr tmspci) ], wan => [ qw(c101 cosa cyclomx cycx_drv dlci dscc4 farsync hdlc hostess_sv11 lapbether lmc n2 pc300 pci200syn sbni sdla sdladrv sealevel syncppp wanxl z85230) ], usb_dsl => [ qw(cxacru speedtch ueagle-atm usbatm xusbatm) ], }, ################################################################################ disk => { # ide drivers compiled as modules: ide => [ qw(aec62xx ali14xx alim15x3 amd74xx atiixp cmd64x cy82c693 cs5520 cs5530 cs5535 cs5536), qw(delkin_cb dtc2278 hpt34x hpt366 ns87415 ht6560b it8172 it8213 it821x jmicron), qw(opti621 pdc202xx_new pdc202xx_old piix qd65xx rz1000 sc1200 serverworks siimage sis5513 slc90e66), qw(tc86c001 triflex trm290 tx4938ide tx4939ide umc8672 via82cxxx ide-pci-generic ide-generic), ], scsi => [ if_(arch() =~ /ppc/, qw(mesh mac53c94)), if_(arch() =~ /^sparc/, qw(qlogicpti)), if_(arch() !~ /alpha/ && arch() !~ /sparc/, '53c7,8xx', qw(AM53C974 BusLogic NCR53c406a a100u2w advansys aha152x aha1542 aha1740), qw(atp870u dc395x dc395x_trm dmx3191d dtc g_NCR5380 in2000 initio mvsas pas16 pci2220i psi240i fdomain), qw(qla1280 qla2x00 qla2xxx qlogicfas qlogicfc ), qw(seagate wd7000 shasta sim710 stex sym53c416 t128 tmscsim u14-34f ultrastor), qw(eata eata_pio eata_dma nsp32), ), qw(aic7xxx aic7xxx_old aic79xx pci2000 qlogicfas408 sym53c8xx lpfc lpfcdd), # ncr53c8xx ], sata => [ # note that ata_piix manage RAID devices on ICH6R qw(ahci aic94xx ata_adma ata_piix pata_pdc2027x pdc_adma sata_fsl sata_inic162x sata_mv sata_nv sata_promise sata_qstor sata_sil sata_sil24 sata_sis sata_svw sata_sx4 sata_uli sata_via sata_vsc sx8), # new drivers: old ide drivers ported over libata: qw(mv-ahci pata_ali pata_amd pata_artop pata_atiixp pata_bf54x pata_cmd64x pata_cmd640 pata_cs5520 pata_cs5530 pata_cs5535 pata_cs5536 pata_cypress), qw(pata_efar pata_hpt366 pata_hpt37x pata_hpt3x2n pata_hpt3x3 pata_isapnp pata_it821x pata_it8172 pata_it8213 pata_jmicron), qw(pata_legacy pata_marvell pata_mpiix pata_netcell pata_ninja32 pata_ns87410 pata_ns87415 pata_oldpiix pata_opti pata_optidma), qw(pata_pdc2027x pata_pdc202xx_old pata_platform pata_qdi pata_radisys pata_rz1000), qw(pata_sc1200 pata_sch pata_serverworks pata_sil680 pata_sis pata_sl82c105 pata_triflex pata_via pata_winbond ata_generic), if_(arch() =~ /ppc/, 'sata_fsl'), qw(pata_acpi), ], hardware_raid => [ if_(arch() =~ /^sparc/, qw(pluto)), if_(arch() !~ /alpha/ && arch() !~ /sparc/, # 3w-xxxx drives ATA-RAID, 3w-9xxx and arcmsr drive SATA-RAID qw(a320raid megaide), qw(3w-9xxx 3w-xxxx aacraid arcmsr cciss cpqfc cpqarray DAC960 dpt_i2o gdth hptiop i2o_block ipr it821x it8212), qw(iteraid megaraid megaraid_mbox megaraid_sas mptfc mptsas mptspi mptscsih qla2100 qla2200 qla2300 qla2322 qla4xxx qla6312 qla6322 pdc-ultra), qw(ips ppa imm), ), ], virtual => [ qw(xenblk virtio_blk) ], pcmcia => [ qw(aha152x_cs fdomain_cs nsp_cs qlogic_cs ide-cs pata_pcmcia sym53c500_cs) ], raw => [ qw(ide-gd_mod sd_mod) ], usb => [ qw(usb-storage) ], firewire => [ qw(sbp2) ], cdrom => [ qw(ide-cd_mod sr_mod) ], card_reader => [ qw(sdhci tifm_sd tifm_7xx1) ], }, ################################################################################ bus => { usb => [ qw(ehci-hcd hwa-hc isp116x-hcd isp1760 ohci-hcd r8a66597-hcd sl811_cs sl811-hcd uhci-hcd u132-hcd usb-uhci usb-ohci whci-hcd) ], bluetooth => [ qw(bcm203x bfusb bpa10x btusb) ], firewire => [ qw(ohci1394) ], i2c => [ qw(i2c-ali1535 i2c-ali1563 i2c-ali15x3 i2c-amd756 i2c-amd8111 i2c-i801 i2c-i810 i2c-nforce2), qw(i2c-piix4 i2c-prosavage i2c-savage4 i2c-sis5595 i2c-sis630 i2c-sis96x i2c-via i2c-viapro i2c-voodoo3), if_(arch() !~ /^ppc/, qw(i2c-hydra i2c-ibm_iic i2c-mpc)), ], pcmcia => [ if_(arch() !~ /^sparc/, qw(au1x00_ss i82365 i82092 pd6729 tcic vrc4171_card vrc4173_cardu yenta_socket)), # cb_enabler ], hid => [ qw(hid-a4tech hid-apple hid-belkin hid-cherry hid-chicony hid-cypress hid-drff hid-ezkey hid-gaff hid-gyration hid-kensington hid-kye hid-logitech hid-microsoft hid-monterey hid-multilaser hid-ntrig hid-petalynx hid-pl hid-samsung hid-sjoy hid-sony hid-sunplus hid-tmff hid-topseed hid-zpff hid-wacom ff-memless)], #serial_cs #ftl_cs 3c575_cb apa1480_cb epic_cb serial_cb tulip_cb iflash2+_mtd iflash2_mtd #cb_enabler }, fs => { network => [ qw(af_packet nfs smbfs) ], cdrom => [ qw(isofs) ], loopback => [ qw(isofs loop squashfs) ], local => [ if_(arch() =~ /^ppc/, qw(hfs)), qw(reiserfs reiser4 jfs xfs ntfs vfat ext3 ext4), ], various => [ qw(romfs ufs unionfs) ], }, ################################################################################ multimedia => { sound => [ if_(arch() =~ /ppc/, qw(dmasound_pmac snd-aoa snd-powermac)), if_(arch() =~ /sparc/, qw(snd-sun-amd7930 snd-sun-cs4231 snd-sun-dbri)), if_(arch() !~ /^sparc/, qw(ad1816 ad1848 ad1889 ali5455 audigy audio awe_wave cmpci cs4232 cs4281 cs46xx cx88-alsa), qw(emu10k1 es1370 es1371 esssolo1 forte gus i810_audio ice1712 kahlua mad16 maestro), qw(maestro3 mpu401 msnd_pinnacle nm256_audio nvaudio opl3 opl3sa opl3sa2 pas2 pss), qw(rme96xx sam9407 sb sgalaxy snd-ad1816a snd-ad1848 snd-ad1889 snd-ali5451 snd-als100 snd-als300), qw(snd-als4000 snd-atiixp snd-au8810 snd-au8820 snd-au8830 snd-audigyls snd-aw2 snd-azt2316 snd-azt2320 snd-azt3328 snd-azx), qw(snd-asihpi snd-at73c213 snd-bt87x snd-ca0106 snd-cmi8330 snd-cmi8788 snd-cmipci), qw(snd-cs4231 snd-cs4232 snd-cs4236 snd-cs4281 snd-cs46xx snd-cs5530 snd-cs5535audio), qw(snd_ctxfi), qw(snd-darla20 snd-darla24 snd-dt019x snd-echo3g snd-emu10k1 snd-emu10k1x), qw(snd-ens1370 snd-ens1371 snd-es1688 snd-es18xx snd-es1938 snd-es1968 snd-es968), qw(snd-fm801 snd-gina20 snd-gina24 snd-gina3g), qw(snd-gusclassic snd-gusextreme snd-gusmax), qw(snd-hda-intel snd-hdsp snd-hdspm snd-ice1712 snd-ice1724), qw(snd-indi snd-indigo snd-indigodj snd-indigodjx snd-indigoio snd-indigoiox snd-intel8x0 snd-interwave), qw(snd-interwave-stb snd-korg1212 snd-layla20 snd-layla24 snd-layla3g snd-lx6464es), qw(snd-maestro3 snd-mia snd-mixart snd-mona snd-mpu401 snd-nm256), qw(snd-opl3sa2 snd-opti92x-ad1848 snd-opti92x-cs4231 snd-opti93x snd-oxygen snd-pcsp snd-pcxhr snd-riptide snd-rme32), qw(snd-rme96 snd-rme9652 snd-sb16 snd-sb8 snd-sbawe snd-sc6000 snd-sgalaxy snd-sis7019 snd-sonicvibes), qw(snd-sscape snd-trident snd-via82xx snd-virtuoso snd-vx222 snd-vxp440 snd-vxpocket snd-wavefront), qw(snd-ymfpci sonicvibes sscape trident via82cxxx_audio wavefront ymfpci), ), ], tv => [ qw(bt878 bttv cx23885 cx8800 cx8802 cx88-blackbird dpc7146 ivtv mxb pvrusb2 saa7134 zr36067) ], dvb => [ qw(b2c2-flexcop-pci b2c2-flexcop-usb budget budget-av budget-ci cinergyT2 dm1105), qw(dvb-dibusb dvb-ttpci dvb-ttusb-budget dvb-usb-a800 dvb-usb-af9015), qw(dvb-usb-ce6230 dvb-usb-cinergyT2 dvb-usb-cxusb), qw(dvb-usb-dib0700 dvb-usb-dibusb-mb dvb-usb-dibusb-mc dvb-usb-digitv dvb-usb-dtt200u dvb-usb-dtv5100), qw(dvb-usb-gp8ps dvb-usb-nova-t-usb2 dvb-usb-ttusb2 dvb-usb-umt-010 dvb-usb-vp702x dvb-usb-vp7045), qw(firedtv hexium_gemini hexium_orion pluto2 skystar2 ttusb_dec smsusb), ], photo => [ qw(dc2xx mdc800) ], radio => [ qw(radio-gemtek-pci radio-maestro radio-maxiradio) ], scanner => [ qw(scanner microtek) ], gameport => [ qw(cs461x ns558 emu10k1-gp fm801-gp lightning ns558 vortex) ], usb_sound => [ qw(audio dabusb dsbr100 snd-usb-audio snd-usb-caiaq snd-usb-usx2y usb-midi) ], webcam => [ qw(cafe_ccic cpia_usb cpia2 cyber2000fb em28xx et61x251 gspca ibmcam konicawc mod_quickcam ov511 ov511-alt ov518_decomp ov51x-jpeg ovfx2 pwc qc-usb-messenger quickcam quickcam_messenger se401 stv680 sn9c102 tcm825x ultracam usbvideo usbvision vicam w9968cf zc0301) ], }, # USB input stuff get automagically loaded by hotplug and thus # magically work through /dev/input/mice multiplexing: input => { joystick => [ qw(iforce xpad), # there're more drivers in drivers/input/joystick but they support non USB or PCI devices # and thus cannot be detected but by slow (and maybe dangerous?) load_category: qw(a3d adi analog cobra db9 gamecon gf2k grip grip_mp guillemot interact), qw(joydump magellan sidewinder spaceball spaceorb stinger tmdc turbografx warrior) ], remote => [ qw(ati_remote) ], # USB tablets and touchscreens: tablet => [ qw(acecad aiptek wacom kbtab) ], touchscreen => [ qw(ads7846_ts gunze hp680_ts_input itmtouch mk712 mtouch usbtouchscreen) ], }, various => # just here for classification, unused categories (nor auto-detect, nor load_thiskind) { raid => [ qw(dm-crypt dm-mirror dm-mod dm-zero linear lvm-mod multipath raid0 raid1 raid10 raid456 raid5 raid6), qw(dm-delay dm-log dm-mem-cache dm-message dm-raid4-5 dm-region_hash faulty md-mod), ], mouse => [ qw(atixlmouse busmouse generic_serial inport ioc3_serial logibm logibusmouse msbusmouse pcips2 qpmouse synclinkmp), if_(arch() =~ /ppc/, 'macserial'), qw(mousedev usbhid usbmouse), ], char => [ if_(arch() =~ /ia64/, qw(efivars)), qw(applicom n_r3964 nvram pc110pad ppdev), qw(wdt_pci i810-tco sx), #- what are these??? ], crypto => [ qw(sha256_generic cbc amd768_rng amd7xx_tco i810_rng hw_random leedslite padlock), ], laptop => [ qw(i8k sonypi toshiba), ], serial => [ qw(8250_pci 8250 epca esp isicom istallion jsm moxa mxser mxser_new stallion sx synclink synclinkmp), ], other => [ qw(defxx ide-floppy ide-scsi ide-tape loop lp nbd sg st), qw(parport_pc parport_serial), qw(btaudio mmc_block), 'cryptoloop', 'aes-i586', 'aes-x86_64', 'aes_generic', if_(arch() =~ /sparc/, 'openprom'), qw(evdev), qw(usblp printer), 'floppy', #- these need checking qw(rrunner meye), qw(virtio_pci virtio_balloon), ], agpgart => [ if_(arch() =~ /alpha/, qw(alpha-agp)), if_(arch() =~ /ia64/, qw(hp-agp i460-agp)), if_(arch() =~ /ppc/, qw(uninorth-agp)), qw(ali-agp amd64-agp amd-k7-agp ati-agp efficeon-agp intel-agp), qw(k7-agp mch-agp nvidia-agp sis-agp sworks-agp via-agp), ], }, ); my %moddeps; sub load_dependencies { my ($file, $o_root) = @_; %moddeps = (); foreach (cat_($o_root . $file)) { my ($m, $d) = split ':'; my $path = $m; my ($filename, @fdeps) = map { s![^ ]*/!!g; s!\.ko!!g; s!\.gz!!g; $_; } $m, split(' ', $d); my ($modname, @deps) = map { filename2modname($_) } $filename, @fdeps; $moddeps{$modname}{deps} = \@deps; $moddeps{$modname}{filename} = $filename; if (!begins_with($path, "/")) { #- with newer module-init-tools, modules.dep can contain #- relative paths $path = dirname($file) . '/' . $path; } $moddeps{$modname}{path} = $path; } } sub dependencies_closure { my @l = map { dependencies_closure($_) } @{exists $moddeps{$_[0]} && $moddeps{$_[0]}{deps} || []}; (@l, $_[0]); } sub filename2modname { my ($modname) = @_; $modname =~ s/-/_/g; $modname; } sub load_default_moddeps() { require c; load_dependencies('/lib/modules/' . c::kernel_version() . '/modules.dep'); } sub modname2filename { load_default_moddeps() if !%moddeps; $moddeps{$_[0]}{filename}; } sub modname2path { load_default_moddeps() if !%moddeps; $moddeps{$_[0]}{path}; } sub category2modules { map { my ($t1, $t2s) = m|(.*)/(.*)|; my @sub = $t2s eq '*' ? keys %{$l{$t1}} : split('\|', $t2s); map { my $l = $l{$t1}{$_} or die "bad category $t1/$_\n" . backtrace(); map { filename2modname($_) } @$l; } @sub; } split(' ', $_[0]); } sub all_modules() { map { @$_ } map { values %$_ } values %l; } sub module2category { my ($module) = @_; $module = filename2modname($module); foreach my $t1 (keys %l) { my $h = $l{$t1}; foreach my $t2 (keys %$h) { $module eq filename2modname($_) and return "$t1/$t2" foreach @{$h->{$t2}}; } } return; } sub ethernet_categories() { 'network/main|gigabit|pcmcia|tokenring|usb|wireless|firewire'; } sub sub_categories { my ($t1) = @_; keys %{$l{$t1}}; } 1; 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
#define _(x) x
/* @(#)rpcinfo.c 2.2 88/08/11 4.0 RPCSRC */
#if !defined(lint) && defined (SCCSID)
static char sccsid[] = "@(#)rpcinfo.c 1.22 87/08/12 SMI";
#endif
/*
* Copyright (C) 1986, Sun Microsystems, Inc.
*/
/*
* rpcinfo: ping a particular rpc program
* or dump the portmapper
*/
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
#include <getopt.h>
#include <string.h>
#include <unistd.h>
#include <rpc/rpc.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <rpc/pmap_prot.h>
#include <rpc/pmap_clnt.h>
#include <signal.h>
#include <ctype.h>
#include <locale.h>
#include <libintl.h>
#define MAXHOSTLEN 256
#define MIN_VERS ((u_long) 0)
#define MAX_VERS ((u_long) 4294967295UL)
static void udpping (u_short portflag, int argc, char **argv);
static void tcpping (u_short portflag, int argc, char **argv);
static int pstatus (CLIENT *client, u_long prognum, u_long vers);
static void pmapdump (int argc, char **argv);
static bool_t reply_proc (void *res, struct sockaddr_in *who);
static void brdcst (int argc, char **argv) __attribute__ ((noreturn));
static void deletereg (int argc, char **argv);
static void usage (void);
static u_long getprognum (char *arg);
static u_long getvers (char *arg);
static void get_inet_address (struct sockaddr_in *addr, char *host);
/*
* Functions to be performed.
*/
#define NONE 0 /* no function */
#define PMAPDUMP 1 /* dump portmapper registrations */
#define TCPPING 2 /* ping TCP service */
#define UDPPING 3 /* ping UDP service */
#define BRDCST 4 /* ping broadcast UDP service */
#define DELETES 5 /* delete registration for the service */
int
main (int argc, char **argv)
{
register int c;
int errflg;
int function;
u_short portnum;
setlocale (LC_ALL, "");
function = NONE;
portnum = 0;
errflg = 0;
while ((c = getopt (argc, argv, "ptubdn:")) != -1)
{
switch (c)
{
case 'p':
if (function != NONE)
errflg = 1;
else
function = PMAPDUMP;
break;
case 't':
if (function != NONE)
errflg = 1;
else
function = TCPPING;
break;
case 'u':
if (function != NONE)
errflg = 1;
else
function = UDPPING;
break;
case 'b':
if (function != NONE)
errflg = 1;
else
function = BRDCST;
break;
case 'n':
portnum = (u_short) atoi (optarg); /* hope we don't get bogus # */
break;
case 'd':
if (function != NONE)
errflg = 1;
else
function = DELETES;
break;
case '?':
errflg = 1;
}
}
if (errflg || function == NONE)
{
usage ();
return 1;
}
switch (function)
{
case PMAPDUMP:
if (portnum != 0)
{
usage ();
return 1;
}
pmapdump (argc - optind, argv + optind);
break;
case UDPPING:
udpping (portnum, argc - optind, argv + optind);
break;
case TCPPING:
tcpping (portnum, argc - optind, argv + optind);
break;
case BRDCST:
if (portnum != 0)
{
usage ();
return 1;
}
brdcst (argc - optind, argv + optind);
break;
case DELETES:
deletereg (argc - optind, argv + optind);
break;
}
return 0;
}
static void
udpping (portnum, argc, argv)
u_short portnum;
int argc;
char **argv;
{
struct timeval to;
struct sockaddr_in addr;
enum clnt_stat rpc_stat;
CLIENT *client;
u_long prognum, vers, minvers, maxvers;
int sock = RPC_ANYSOCK;
struct rpc_err rpcerr;
int failure;
if (argc < 2 || argc > 3)
{
usage ();
exit (1);
}
prognum = getprognum (argv[1]);
get_inet_address (&addr, argv[0]);
/* Open the socket here so it will survive calls to clnt_destroy */
sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0)
{
perror ("rpcinfo: socket");
exit (1);
}
failure = 0;
if (argc == 2)
{
/*
* A call to version 0 should fail with a program/version
* mismatch, and give us the range of versions supported.
*/
addr.sin_port = htons (portnum);
to.tv_sec = 5;
to.tv_usec = 0;
if ((client = clntudp_create (&addr, prognum, (u_long) 0,
to, &sock)) == NULL)
{
clnt_pcreateerror ("rpcinfo");
printf (_("program %lu is not available\n"), prognum);
exit (1);
}
to.tv_sec = 10;
to.tv_usec = 0;
rpc_stat = clnt_call (client, NULLPROC, (xdrproc_t) xdr_void,
(char *) NULL, (xdrproc_t) xdr_void,
(char *) NULL, to);
if (rpc_stat == RPC_PROGVERSMISMATCH)
{
clnt_geterr (client, &rpcerr);
minvers = rpcerr.re_vers.low;
maxvers = rpcerr.re_vers.high;
}
else if (rpc_stat == RPC_SUCCESS)
{
/*
* Oh dear, it DOES support version 0.
* Let's try version MAX_VERS.
*/
addr.sin_port = htons (portnum);
to.tv_sec = 5;
to.tv_usec = 0;
if ((client = clntudp_create (&addr, prognum, MAX_VERS,
to, &sock)) == NULL)
{
clnt_pcreateerror ("rpcinfo");
printf (_("program %lu version %lu is not available\n"),
prognum, MAX_VERS);
exit (1);
}
to.tv_sec = 10;
to.tv_usec = 0;
rpc_stat = clnt_call (client, NULLPROC, (xdrproc_t) xdr_void,
NULL, (xdrproc_t) xdr_void, NULL, to);
if (rpc_stat == RPC_PROGVERSMISMATCH)
{
clnt_geterr (client, &rpcerr);
minvers = rpcerr.re_vers.low;
maxvers = rpcerr.re_vers.high;
}
else if (rpc_stat == RPC_SUCCESS)
{
/*
* It also supports version MAX_VERS.
* Looks like we have a wise guy.
* OK, we give them information on all
* 4 billion versions they support...
*/
minvers = 0;
maxvers = MAX_VERS;
}
else
{
(void) pstatus (client, prognum, MAX_VERS);
exit (1);
}
}
else
{
(void) pstatus (client, prognum, (u_long) 0);
exit (1);
}
clnt_destroy (client);
for (vers = minvers; vers <= maxvers; vers++)
{
addr.sin_port = htons (portnum);
to.tv_sec = 5;
to.tv_usec = 0;
if ((client = clntudp_create (&addr, prognum, vers,
to, &sock)) == NULL)
{
clnt_pcreateerror ("rpcinfo");
printf (_("program %lu version %lu is not available\n"),
prognum, vers);
exit (1);
}
to.tv_sec = 10;
to.tv_usec = 0;
rpc_stat = clnt_call (client, NULLPROC, (xdrproc_t) xdr_void,
NULL, (xdrproc_t) xdr_void, NULL, to);
if (pstatus (client, prognum, vers) < 0)
failure = 1;
clnt_destroy (client);
}
}
else
{
vers = getvers (argv[2]);
addr.sin_port = htons (portnum);
to.tv_sec = 5;
to.tv_usec = 0;
if ((client = clntudp_create (&addr, prognum, vers,
to, &sock)) == NULL)
{
clnt_pcreateerror ("rpcinfo");
printf (_("program %lu version %lu is not available\n"),
prognum, vers);
exit (1);
}
to.tv_sec = 10;
to.tv_usec = 0;
rpc_stat = clnt_call (client, 0, (xdrproc_t) xdr_void, NULL,
(xdrproc_t) xdr_void, NULL, to);
if (pstatus (client, prognum, vers) < 0)
failure = 1;
}
(void) close (sock); /* Close it up again */
if (failure)
exit (1);
}
static void
tcpping (portnum, argc, argv)
u_short portnum;
int argc;
char **argv;
{
struct timeval to;
struct sockaddr_in addr;
enum clnt_stat rpc_stat;
CLIENT *client;
u_long prognum, vers, minvers, maxvers;
int sock = RPC_ANYSOCK;
struct rpc_err rpcerr;
int failure;
if (argc < 2 || argc > 3)
{
usage ();
exit (1);
}
prognum = getprognum (argv[1]);
get_inet_address (&addr, argv[0]);
failure = 0;
if (argc == 2)
{
/*
* A call to version 0 should fail with a program/version
* mismatch, and give us the range of versions supported.
*/
addr.sin_port = htons (portnum);
if ((client = clnttcp_create (&addr, prognum, MIN_VERS,
&sock, 0, 0)) == NULL)
{
clnt_pcreateerror ("rpcinfo");
printf (_("program %lu is not available\n"), prognum);
exit (1);
}
to.tv_sec = 10;
to.tv_usec = 0;
rpc_stat = clnt_call (client, NULLPROC, (xdrproc_t) xdr_void, NULL,
(xdrproc_t) xdr_void, NULL, to);
if (rpc_stat == RPC_PROGVERSMISMATCH)
{
clnt_geterr (client, &rpcerr);
minvers = rpcerr.re_vers.low;
maxvers = rpcerr.re_vers.high;
}
else if (rpc_stat == RPC_SUCCESS)
{
/*
* Oh dear, it DOES support version 0.
* Let's try version MAX_VERS.
*/
addr.sin_port = htons (portnum);
if ((client = clnttcp_create (&addr, prognum, MAX_VERS,
&sock, 0, 0)) == NULL)
{
clnt_pcreateerror ("rpcinfo");
printf (_("program %lu version %lu is not available\n"),
prognum, MAX_VERS);
exit (1);
}
to.tv_sec = 10;
to.tv_usec = 0;
rpc_stat = clnt_call (client, NULLPROC, (xdrproc_t) xdr_void,
NULL, (xdrproc_t) xdr_void, NULL, to);
if (rpc_stat == RPC_PROGVERSMISMATCH)
{
clnt_geterr (client, &rpcerr);
minvers = rpcerr.re_vers.low;
maxvers = rpcerr.re_vers.high;
}
else if (rpc_stat == RPC_SUCCESS)
{
/*
* It also supports version MAX_VERS.
* Looks like we have a wise guy.
* OK, we give them information on all
* 4 billion versions they support...
*/
minvers = 0;
maxvers = MAX_VERS;
}
else
{
(void) pstatus (client, prognum, MAX_VERS);
exit (1);
}
}
else
{
(void) pstatus (client, prognum, MIN_VERS);
exit (1);
}
clnt_destroy (client);
(void) close (sock);
sock = RPC_ANYSOCK; /* Re-initialize it for later */
for (vers = minvers; vers <= maxvers; vers++)
{
addr.sin_port = htons (portnum);
if ((client = clnttcp_create (&addr, prognum, vers,
&sock, 0, 0)) == NULL)
{
clnt_pcreateerror ("rpcinfo");
printf (_("program %lu version %lu is not available\n"),
prognum, vers);
exit (1);
}
to.tv_usec = 0;
to.tv_sec = 10;
rpc_stat = clnt_call (client, 0, (xdrproc_t) xdr_void, NULL,
(xdrproc_t) xdr_void, NULL, to);
if (pstatus (client, prognum, vers) < 0)
failure = 1;
clnt_destroy (client);
(void) close (sock);
sock = RPC_ANYSOCK;
}
}
else
{
vers = getvers (argv[2]);
addr.sin_port = htons (portnum);
if ((client = clnttcp_create (&addr, prognum, vers, &sock,
0, 0)) == NULL)
{
clnt_pcreateerror ("rpcinfo");
printf (_("program %lu version %lu is not available\n"),
prognum, vers);
exit (1);
}
to.tv_usec = 0;
to.tv_sec = 10;
rpc_stat = clnt_call (client, 0, (xdrproc_t) xdr_void, NULL,
(xdrproc_t) xdr_void, NULL, to);
if (pstatus (client, prognum, vers) < 0)
failure = 1;
}
if (failure)
exit (1);
}
/*
* This routine should take a pointer to an "rpc_err" structure, rather than
* a pointer to a CLIENT structure, but "clnt_perror" takes a pointer to
* a CLIENT structure rather than a pointer to an "rpc_err" structure.
* As such, we have to keep the CLIENT structure around in order to print
* a good error message.
*/
static int
pstatus (client, prognum, vers)
register CLIENT *client;
u_long prognum;
u_long vers;
{
struct rpc_err rpcerr;
clnt_geterr (client, &rpcerr);
if (rpcerr.re_status != RPC_SUCCESS)
{
clnt_perror (client, "rpcinfo");
printf (_("program %lu version %lu is not available\n"), prognum, vers);
return -1;
}
else
{