| 1 | #!/usr/bin/perl | ||
| 2 | # | ||
| 3 | # Copyright 1997 - 2019 by IXIA Keysight | ||
| 4 | # | ||
| 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 6 | # of this software and associated documentation files (the "Software"), | ||
| 7 | # to deal in the Software without restriction, including without limitation | ||
| 8 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
| 9 | # and/or sell copies of the Software, and to permit persons to whom the | ||
| 10 | # Software is furnished to do so, subject to the following conditions: | ||
| 11 | # | ||
| 12 | # The above copyright notice and this permission notice shall be included in | ||
| 13 | # all copies or substantial portions of the Software. | ||
| 14 | # | ||
| 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 21 | # THE SOFTWARE. | ||
| 22 | |||
| 23 | use File::Spec; | ||
| 24 | my $dependenciespath = undef; | ||
| 25 | my $ipv6Path = undef; | ||
| 26 | my $ipv6ModuleExists = undef; | ||
| 27 | BEGIN { | ||
| 28 | #---------------------------------------------------------------------------- | ||
| 29 | # Since we are trying to load Socket6.dll Socket6.so there may be a | ||
| 30 | # segmentation handle that gracefully | ||
| 31 | #---------------------------------------------------------------------------- | ||
| 32 | our $ipv6LoadError = undef; | ||
| 33 | $SIG{SEGV} = \&handler; | ||
| 34 | sub handler { | ||
| 35 | $SIG{SEGV} = 0; | ||
| 36 | $checkDependencies::ipv6LoadError = 1; | ||
| 37 | die "unable to load IPv6 Module"; | ||
| 38 | } | ||
| 39 | |||
| 40 | my ($volume, $directory, $file) = File::Spec->splitpath(__FILE__); | ||
| 41 | $dependenciespath = File::Spec->catdir((File::Spec->rel2abs($directory), 'dependencies')); | ||
| 42 | $ipv6Path = File::Spec->catdir((File::Spec->rel2abs($dependenciespath), 'IPv6Sock')); | ||
| 43 | $ipv6ModuleExists = eval {require Socket6; 1;}; | ||
| 44 | } | ||
| 45 | use lib $dependenciespath; | ||
| 46 | if ($ipv6ModuleExists != 1) { | ||
| 47 | print "WARNING Default IPv6 Module Does not exist "; | ||
| 48 | print "Loading IXIA specific IPv6 Module\n"; | ||
| 49 | use lib $ipv6Path; | ||
| 50 | }; | ||
| 51 | |||
| 52 | package checkDependencies; | ||
| 53 | |||
| 54 | sub checkDeps { | ||
| 55 | my @missingDependencies = (); | ||
| 56 | my $ret = eval { | ||
| 57 | require IO::Socket::SSL; | ||
| 58 | IO::Socket::SSL->import(); | ||
| 59 | 1; | ||
| 60 | }; | ||
| 61 | if (!$ret and $@) { | ||
| 62 | push(@missingDependencies, "IO::Socket::SSL"); | ||
| 63 | } | ||
| 64 | my $ret = eval { | ||
| 65 | require LWP::UserAgent; | ||
| 66 | LWP::UserAgent->import(); | ||
| 67 | 1; | ||
| 68 | }; | ||
| 69 | if (!$ret and $@) { | ||
| 70 | push(@missingDependencies, "LWP::UserAgent"); | ||
| 71 | } | ||
| 72 | my $ret = eval { | ||
| 73 | require Protocol::WebSocket::Client; | ||
| 74 | Protocol::WebSocket::Client->import(); | ||
| 75 | 1; | ||
| 76 | }; | ||
| 77 | if (!$ret and $@) { | ||
| 78 | push(@missingDependencies, "Protocol::WebSocket::Client"); | ||
| 79 | } | ||
| 80 | my $ret = eval { | ||
| 81 | require JSON::PP; | ||
| 82 | JSON::PP->import(); | ||
| 83 | 1; | ||
| 84 | }; | ||
| 85 | if (!$ret and $@) { | ||
| 86 | push(@missingDependencies, "JSON::PP"); | ||
| 87 | } | ||
| 88 | my $ret = eval { | ||
| 89 | require URI::Escape; | ||
| 90 | URI::Escape->import(); | ||
| 91 | 1; | ||
| 92 | }; | ||
| 93 | if (!$ret and $@) { | ||
| 94 | push(@missingDependencies, "URI::Escape"); | ||
| 95 | } | ||
| 96 | my $ret = eval { | ||
| 97 | require Net::SSLeay; | ||
| 98 | Net::SSLeay->import(); | ||
| 99 | 1; | ||
| 100 | }; | ||
| 101 | if (!$ret and $@) { | ||
| 102 | push(@missingDependencies, "Net::SSLeay"); | ||
| 103 | } | ||
| 104 | my $ret = eval { | ||
| 105 | require LWP::Protocol::https; | ||
| 106 | LWP::Protocol::https->import(); | ||
| 107 | 1; | ||
| 108 | }; | ||
| 109 | if (!$ret and $@) { | ||
| 110 | push(@missingDependencies, "LWP::Protocol::https"); | ||
| 111 | } | ||
| 112 | my $ret = eval { | ||
| 113 | require Time::Seconds; | ||
| 114 | Time::Seconds->import(); | ||
| 115 | 1; | ||
| 116 | }; | ||
| 117 | if (!$ret and $@) { | ||
| 118 | push(@missingDependencies, "Time::Seconds"); | ||
| 119 | } | ||
| 120 | my $ret = eval { | ||
| 121 | require Socket6; | ||
| 122 | Socket6->import(); | ||
| 123 | 1; | ||
| 124 | }; | ||
| 125 | if (!$ret and $@) { | ||
| 126 | push(@missingDependencies, "Socket6"); | ||
| 127 | } | ||
| 128 | |||
| 129 | if (scalar(@missingDependencies) > 0) { | ||
| 130 | my $enumeratedDependencies = join(', ', @missingDependencies); | ||
| 131 | die 'Cannot load required dependencies: '.$enumeratedDependencies.". \nPlease consult documentation for installing required dependencies.\n"; | ||
| 132 | } | ||
| 133 | }; | ||
| 134 | |||
| 135 | 1; | ||
| 136 | |||
| 137 |