Bad protocol 'tcp'

G

garrett.hennessey

Hello -

I have searched endlessly for a solution to the following problem. I am
trying to use various packages within the perl 'Net' package (ie.
Net::FTP, Net::SMTP, etc). Everytime I try to use these packages I get
the following error: Net::FTP: Bad protocol 'tcp'. I also get this
error when using ppm.

I am using Active Perl and also cygwin perl, and they both exhibit the
same error.

One important thing to note is that I do not have this problem on other
computers on my network. All the computers are running either Windows
200 or XP. Searching through the newsgroups and mailing list archives
at Active Perl, I've found multiple people suggest adding an
environment variable for http_proxy, but I am not behind a proxy. Also
people have suggested checking for the file protocol in
c:\winnt\system32\drivers\etc directory. This file exisits and is the
same as other computers on my netwok where this all works.

One big clue I have is that any call to 'getprotobyname' returns an
empty string. This is also true for 'getprotobynumber'. This same call
on the other computers returns the appropriate values as indicated in
the protocol file.

Here's some example code:
use strict;
use warnings;
use Net::FTP;

my $hostname = '192.168.1.211';
my $username = 'xxxx'; # removed username
my $password = 'xxxxx'; # removed passoword

my $ftp = Net::FTP->new("192.168.1.211", Debug => 1)
or die "Cannot connect to 192.168.1.211: $@";

which produces:
Cannot connect to 192.168.1.211: Net::FTP: Bad protocol 'tcp' at ftp.pl
line 9.

Any help would be greatly appreciated!

Thanks,

Garrett Hennessey
 
M

Mark Clements

Hello -

I have searched endlessly for a solution to the following problem. I am
trying to use various packages within the perl 'Net' package (ie.
Net::FTP, Net::SMTP, etc). Everytime I try to use these packages I get
the following error: Net::FTP: Bad protocol 'tcp'. I also get this
error when using ppm.

I am using Active Perl and also cygwin perl, and they both exhibit the
same error.

One important thing to note is that I do not have this problem on other
computers on my network. All the computers are running either Windows
200 or XP. Searching through the newsgroups and mailing list archives
at Active Perl, I've found multiple people suggest adding an
environment variable for http_proxy, but I am not behind a proxy. Also
people have suggested checking for the file protocol in
c:\winnt\system32\drivers\etc directory. This file exisits and is the
same as other computers on my netwok where this all works.

One big clue I have is that any call to 'getprotobyname' returns an
empty string. This is also true for 'getprotobynumber'. This same call
on the other computers returns the appropriate values as indicated in
the protocol file.

Here's some example code:
use strict;
use warnings;
use Net::FTP;

my $hostname = '192.168.1.211';
my $username = 'xxxx'; # removed username
my $password = 'xxxxx'; # removed passoword

my $ftp = Net::FTP->new("192.168.1.211", Debug => 1)
or die "Cannot connect to 192.168.1.211: $@";

which produces:
Cannot connect to 192.168.1.211: Net::FTP: Bad protocol 'tcp' at ftp.pl
line 9.

Any help would be greatly appreciated!

I can reproduce this error by commenting out the "tcp" line in

c:\WINDOWS\System32\Drivers\Etc\protocol

Mark
 
G

garrett.hennessey

Thanks Mark -

This supports my belief that for whatever reason, my 'protocol' file is
never being used. Any ideas why this may happen?
 
M

Mark Clements

Thanks Mark -

This supports my belief that for whatever reason, my 'protocol' file is
never being used. Any ideas why this may happen?

Pass. What does

use strict;
use warnings;


my $protocolFilePath = q(C:\Windows\System32\Drivers\Etc\Protocol);
my $protocolFH;

open ( $protocolFH, "<", $protocolFilePath )
or die "could not open $protocolFilePath for read: $!";


give you?

Beyond that, I have a few leads in mind but I'm no Windows expert and so
they're little more than conjecture. There are people in here with
vastly more experience than me, although this appears to be more of a
Windows question than Perl.

regards,

Mark
 
D

DJ Stunks

Mark said:
Pass. What does

use strict;
use warnings;


my $protocolFilePath = q(C:\Windows\System32\Drivers\Etc\Protocol);
my $protocolFH;

open ( $protocolFH, "<", $protocolFilePath )
or die "could not open $protocolFilePath for read: $!";

Hey Mark, you can declare your lexical filehandle in the open(). just
FYI :)

open my $lexical_fh, '<', $infile...

-jp
 
G

Garrett

Mark -

You're example code (assuming I change the path to c:\winnt\... from
c:\windows\...) works fine. It prints nothing (as it should).

I don't see how this a windows problem. The other programming languages
I use (c++, java, etc) don't have this problem. And I can use the
network with email, web, ftp, telnet, ssh, nfs, etc fine with other
programs. Perl is the only one who complains.

Garrett
 
D

Dr.Ruud

(e-mail address removed) schreef:
One big clue I have is that any call to 'getprotobyname' returns an
empty string. This is also true for 'getprotobynumber'. This same call
on the other computers returns the appropriate values as indicated in
the protocol file.


What does this print:

perl -wle "$,=qq{,$/}; print getprotobyname q{tcp}"


And this:

perl -V:getpr.*


What are the values of the environment variables "SystemRoot" and
"windir"?
 
B

Ben Morrow

[quoting fixed. please learn to quote properly]

Quoth "Garrett said:
You're example code (assuming I change the path to c:\winnt\... from
c:\windows\...) works fine. It prints nothing (as it should).

Right... good. Does your c:\windows\system32\drivers\etc\protocol have a
line like

tcp 6 tcp # Transmission control protocol

? If not, it should have.
I don't see how this a windows problem. The other programming languages
I use (c++, java, etc) don't have this problem. And I can use the
network with email, web, ftp, telnet, ssh, nfs, etc fine with other
programs. Perl is the only one who complains.

It's possible that other programs don't request the TCP protocol by
name, but either hardcode the number (in practice it's always 6) or use
the default protocol (which, again in practice, is always TCP for
AF_INET/SOCK_STREAM sockets). This doesn't mean Perl is in the wrong:
it's just following the specs to potentially cope with odd systems where
things aren't the way they usually are.

Ben
 
M

Mark Clements

Garrett said:
Mark -

You're example code (assuming I change the path to c:\winnt\... from
c:\windows\...) works fine. It prints nothing (as it should). OK.


I don't see how this a windows problem. The other programming languages
I use (c++, java, etc) don't have this problem. And I can use the
network with email, web, ftp, telnet, ssh, nfs, etc fine with other
programs. Perl is the only one who complains.
What does a small C program calling getprotobyname give you?
(NB: my C is pretty weak. Do not use this as an example of how to write
C. Have probably made a host of security and stylistic errors).


#include <stdio.h>
#include <netdb.h>

#define MAXPROTOLENGTH 82

int main(int argc, char* argv[]){
char* protocolName;
struct protoent* protocol;

protocolName =(char*)malloc(MAXPROTOLENGTH);

if(argc != 2){
printf("Usage: %s protocol\n",argv[0]);
return 1;
}
sscanf(argv[1],"%s",protocolName);

printf("lookup protocol: %s\n",protocolName);

protocol = getprotobyname( protocolName );

if(protocol == NULL ){
printf("could not find protocol\n");
}else{
printf("name: %s number: %d\n",protocol->p_name,
protocol->p_proto);
}

return 0;
}

Mark
 
G

Garrett

Thanks you so much to everyone. I have solved the problem. I believe my
computer may have at one time been effected by a virus. The registry
key:
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters"
value had been corrupted. The value should be
%SystemRoot%\System32\drivers\etc but it was %nsdb1%, and this
environment variable didn't exist. Thanks again to everyone for your
help, and Mark, you were right, it was a windows problem!

Mark said:
Garrett said:
Mark -

You're example code (assuming I change the path to c:\winnt\... from
c:\windows\...) works fine. It prints nothing (as it should). OK.


I don't see how this a windows problem. The other programming languages
I use (c++, java, etc) don't have this problem. And I can use the
network with email, web, ftp, telnet, ssh, nfs, etc fine with other
programs. Perl is the only one who complains.
What does a small C program calling getprotobyname give you?
(NB: my C is pretty weak. Do not use this as an example of how to write
C. Have probably made a host of security and stylistic errors).


#include <stdio.h>
#include <netdb.h>

#define MAXPROTOLENGTH 82

int main(int argc, char* argv[]){
char* protocolName;
struct protoent* protocol;

protocolName =(char*)malloc(MAXPROTOLENGTH);

if(argc != 2){
printf("Usage: %s protocol\n",argv[0]);
return 1;
}
sscanf(argv[1],"%s",protocolName);

printf("lookup protocol: %s\n",protocolName);

protocol = getprotobyname( protocolName );

if(protocol == NULL ){
printf("could not find protocol\n");
}else{
printf("name: %s number: %d\n",protocol->p_name,
protocol->p_proto);
}

return 0;
}

Mark
 
G

Garrett

Just an update for future people with this problem: the registry
name/value I mentioned before should be "DataBasePath" with value
"%SystemRoot%\system32\drivers\etc". Thanks again.

Garrett Hennessey
Thanks you so much to everyone. I have solved the problem. I believe my
computer may have at one time been effected by a virus. The registry
key:
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters"
value had been corrupted. The value should be
%SystemRoot%\System32\drivers\etc but it was %nsdb1%, and this
environment variable didn't exist. Thanks again to everyone for your
help, and Mark, you were right, it was a windows problem!

Mark said:
Garrett said:
Mark -

You're example code (assuming I change the path to c:\winnt\... from
c:\windows\...) works fine. It prints nothing (as it should). OK.


I don't see how this a windows problem. The other programming languages
I use (c++, java, etc) don't have this problem. And I can use the
network with email, web, ftp, telnet, ssh, nfs, etc fine with other
programs. Perl is the only one who complains.
What does a small C program calling getprotobyname give you?
(NB: my C is pretty weak. Do not use this as an example of how to write
C. Have probably made a host of security and stylistic errors).


#include <stdio.h>
#include <netdb.h>

#define MAXPROTOLENGTH 82

int main(int argc, char* argv[]){
char* protocolName;
struct protoent* protocol;

protocolName =(char*)malloc(MAXPROTOLENGTH);

if(argc != 2){
printf("Usage: %s protocol\n",argv[0]);
return 1;
}
sscanf(argv[1],"%s",protocolName);

printf("lookup protocol: %s\n",protocolName);

protocol = getprotobyname( protocolName );

if(protocol == NULL ){
printf("could not find protocol\n");
}else{
printf("name: %s number: %d\n",protocol->p_name,
protocol->p_proto);
}

return 0;
}

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,156
Latest member
KetoBurnSupplement
Top