Sponsored Content
Top Forums Programming How to program a telnet client? Post 13365 by thinker130 on Wednesday 16th of January 2002 03:43:26 AM
Old 01-16-2002
the source files(the third part)

I have forgotten to include some functions needed in file tel_cli.c, please append the belowed source code to the end of file tel_cli.c.


/*connectsock - allocate & connect a socket using TCP or TCP*/
int connectsock(const char *host,const char *service, const char *transport)
/* arguments:
* host --- name of host to which connection is desired
* service -- service associated with the desired port
* transport --- name of transport protocol to use ("tcp" or "udp")
*/
{
struct hostent *phe; /* pointer to host information entry */
struct servent *pse; /* pointer to service information entry */
struct protoent *ppe; /* pointer to protocol information entry */
struct sockaddr_in sin; /* an Internet endpoint addredd */
int s,type; /* socket descriptor and socket type */

memset(&sin,0,sizeof(sin));
sin.sin_family=AF_INET;

/* Map service name to port number */
if (pse = getservbyname(service,transport))
sin.sin_port = pse->s_port;
else if ((sin.sin_port = htons((u_short)atoi(service))) == 0 )
{
//errexit("can't get \"%s\" service entry\n",service);
printf("can't get \"%s\" service entry\n",service);
return 0;
}

/* Map host name to IP address,allowing for dotted decimal */
if (phe = gethostbyname(host))
memcpy(&sin.sin_addr,phe->h_addr,phe->h_length);
else if ((sin.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE)
{
//errexit("can't get \"%s\" protocol entry\n",transport);
printf("can't get \"%s\" protocol entry\n",transport);
return 0;
}

/* Map transport protocol name to protocol number */
if ((ppe = getprotobyname(transport))==0)
{
//errexit("can't get \"%s\" protocol entry\n",transport);
printf("can't get \"%s\" protocol entry\n",transport);
return 0;
}

/* User protocol to choose a socket type */
if (strcmp(transport,"udp") == 0)
type = SOCK_DGRAM;
else
type = SOCK_STREAM;

/*Allocate a socket */
s = socket(PF_INET, type, ppe->p_proto);
if (s < 0)
{
//errexit("can't create socket:%s\n", strerror(errno));
printf("can't create socket:%s\n", strerror(errno));
return 0;
}
/* connect the socket */
if (connect (s,(struct sockaddr *)&sin,sizeof(sin)) < 0)
{
//errexit("can't connect to %s.%s: %s\n",host,service,strerror(errno));
printf("can't connect to %s.%s: %s\n",host,service,strerror(errno));
return 0;
}
return s;

}


int connectTCP(const char *host, const char *service)
/* arguments:
* host --- name of host to which connection is desired
* service --- service associated with the desired port
*/
{
return connectsock(host,service,"tcp");
}




/* errexit --- print an error mesage and exit */

/*VARARGS1*/

int errexit(const char *format,...)
{
va_list args;
va_start(args,format);
vfprintf(stderr,format,args);
va_end(args);
exit(1);
}
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using telnet client from MacOSX's command line terminal

I'm completely new to Unix, but familiar with Mac OSX. I've just discovered the command line terminal feature of this new OS and I'm trying to learn how to telnet into my host's server to change permissions to allow executable cgi scripts for my website. Is there anyone who might be able to... (2 Replies)
Discussion started by: tylerl
2 Replies

2. Programming

Telnet client IP determination

I have configured my firewall to allow only five remote IP's to connect to my server. Upon connection...i would like to automate the Xsession functions for authorized IP's. Mainly, $DISPLAY of the environment to the client. I understand that the "gethostbyaddr" function is capable of this.... (0 Replies)
Discussion started by: thomas.jones
0 Replies

3. Programming

Does Telnet client library exist ?

Hello, I'm new user in this forum, and i'm french ... so excuse me for my english :) In fact, I've to manage several network equipments which can be only configured with the telnet protocol. But using the standalone telnet tool, it's too long and hard. So I'd like to known if a Telnet... (0 Replies)
Discussion started by: aho
0 Replies

4. UNIX for Dummies Questions & Answers

IP address of telnet client

Hi, I am using the telnet client on windowsNT to access the Unix system. I want to find out the IP address of the telnet client from the server side. The reason is I want to set the DISPLAY environment variable when the user is logged on. Is there anyway that the the Unix server can... (1 Reply)
Discussion started by: vtran4270
1 Replies

5. UNIX for Dummies Questions & Answers

how to launch program though telnet

I have launched telnet on nt and have connected to a unix server, I'm trying to run a program on the unix server which will launch a gui, but when I try to launch it I get the message "display not set\n" "By default set it to 0.0" I can sit down at the unix machine and launch the program with... (3 Replies)
Discussion started by: cbachman
3 Replies

6. Programming

Client - server program

i came acors this coding when surfin the net.this code works perfectly.but as i am new to this socket programming i need sm coments quoted on it or explanation regarding this source code. i have prb understanding the server.c i have posted it below can u guys help me !!!! cheerZ The... (4 Replies)
Discussion started by: mathu
4 Replies

7. Programming

Server client program

hi guys, I need the code for a server client registration form.The server must ask for authentication .Then the client would send in data. This is stored in a file .The server sends back a receipt to the client as part of the payment done. plz can some 1 get me the code... (9 Replies)
Discussion started by: pip3r
9 Replies

8. Programming

SFTP client program

can u help me? i need the program code in C to perform Simple File Transfer in linux.in this forum i found the server program,inw i need the client program ASAP. Thanx. (1 Reply)
Discussion started by: harshi
1 Replies

9. UNIX for Advanced & Expert Users

difference between logging into unix through f-secure ssh client and telnet

hi, what is the difference between logging into unix through f-secure ssh client and telnet is there any more security check is involved can any one explain thanks in advance (1 Reply)
Discussion started by: trichyselva
1 Replies

10. Linux

telnet client and logs

Hello everyone. I have a script that telnets into a linux workstation and restarts a service, while logging the session to a file. I'm kind of new to linux so when I was using windows I would capture something like windows cli: telnet xxx.xxx.xxx.xxx -f c:/capture.log ... # /sbin/service... (3 Replies)
Discussion started by: Elyas_cr
3 Replies
RPCINFO(8)						    BSD System Manager's Manual 						RPCINFO(8)

NAME
rpcinfo -- report RPC information SYNOPSIS
rpcinfo [-m | -s] [host] rpcinfo [host] rpcinfo -T transport host prognum [versnum] rpcinfo -l [-T transport] host prognum [versnum] rpcinfo [-n portnum] -u host prognum [versnum] rpcinfo [-n portnum] [-t] host prognum [versnum] rpcinfo -a serv_address -T transport prognum [versnum] rpcinfo -b [-T transport] prognum versnum rpcinfo -d [-T transport] prognum versnum DESCRIPTION
The rpcinfo utility makes an RPC call to an RPC server and reports what it finds. In the first synopsis, rpcinfo lists all the registered RPC services with rpcbind on host. If host is not specified, the local host is the default. If -s is used, the information is displayed in a concise format. In the second synopsis, rpcinfo lists all the RPC services registered with rpcbind, version 2. Also note that the format of the information is different in the first and the second synopsis. This is because the second synopsis is an older protocol used to collect the information displayed (version 2 of the rpcbind protocol). The third synopsis makes an RPC call to procedure 0 of prognum and versnum on the specified host and reports whether a response was received. transport is the transport which has to be used for contacting the given service. The remote address of the service is obtained by making a call to the remote rpcbind. The prognum argument is a number that represents an RPC program number If a versnum is specified, rpcinfo attempts to call that version of the specified prognum. Otherwise, rpcinfo attempts to find all the registered version numbers for the specified prognum by calling version 0, which is presumed not to exist; if it does exist, rpcinfo attempts to obtain this information by calling an extremely high version number instead, and attempts to call each registered version. Note: the version number is required for -b and -d options. OPTIONS
-T transport Specify the transport on which the service is required. If this option is not specified, rpcinfo uses the transport specified in the NETPATH environment variable, or if that is unset or empty, the transport in the netconfig(5) database is used. This is a generic option, and can be used in conjunction with other options as shown in the SYNOPSIS. -a serv_address Use serv_address as the (universal) address for the service on transport to ping procedure 0 of the specified prognum and report whether a response was received. The -T option is required with the -a option. If versnum is not specified, rpcinfo tries to ping all available version numbers for that program number. This option avoids calls to remote rpcbind to find the address of the service. The serv_address is specified in universal address format of the given trans- port. -b Make an RPC broadcast to procedure 0 of the specified prognum and versnum and report all hosts that respond. If transport is speci- fied, it broadcasts its request only on the specified transport. If broadcasting is not supported by any transport, an error message is printed. Use of broadcasting should be limited because of the potential for adverse effect on other systems. -d Delete registration for the RPC service of the specified prognum and versnum. If transport is specified, unregister the service on only that transport, otherwise unregister the service on all the transports on which it was registered. Only the owner of a service can delete a registration, except the super-user who can delete any service. -l Display a list of entries with a given prognum and versnum on the specified host. Entries are returned for all transports in the same protocol family as that used to contact the remote rpcbind. -m Display a table of statistics of rpcbind operations on the given host. The table shows statistics for each version of rpcbind (ver- sions 2, 3 and 4), giving the number of times each procedure was requested and successfully serviced, the number and type of remote call requests that were made, and information about RPC address lookups that were handled. This is useful for monitoring RPC activi- ties on host. -n portnum Use portnum as the port number for the -t and -u options instead of the port number given by rpcbind. Use of this option avoids a call to the remote rpcbind to find out the address of the service. This option is made obsolete by the -a option. -p Probe rpcbind on host using version 2 of the rpcbind protocol, and display a list of all registered RPC programs. If host is not specified, it defaults to the local host. Note: Version 2 of the rpcbind protocol was previously known as the portmapper protocol. -s Display a concise list of all registered RPC programs on host. If host is not specified, it defaults to the local host. -t Make an RPC call to procedure 0 of prognum on the specified host using TCP, and report whether a response was received. This option is made obsolete by the -T option as shown in the third synopsis. -u Make an RPC call to procedure 0 of prognum on the specified host using UDP, and report whether a response was received. This option is made obsolete by the -T option as shown in the third synopsis. EXAMPLES
To show all of the RPC services registered on the local machine use: example% rpcinfo To show all of the RPC services registered with rpcbind on the machine named ``klaxon'' use: example% rpcinfo klaxon The information displayed by the above commands can be quite lengthy. Use the -s option to display a more concise list: example$ rpcinfo -s klaxon program version(s) netid(s) service owner 100000 2,3,4 unix,tcp,udp,tcp6,udp6 rpcbind super-user 100008 1 udp,tcp,udp6,tcp6 walld super-user 100002 2,1 udp,udp6 rusersd super-user 100001 2,3,4 udp,udp6 rstatd super-user 100012 1 udp,tcp sprayd super-user 100007 3 udp,tcp ypbind super-user To show whether the RPC service with program number prognum and version versnum is registered on the machine named ``klaxon'' for the trans- port TCP use: example% rpcinfo -T tcp klaxon prognum versnum To show all RPC services registered with version 2 of the rpcbind protocol on the local machine use: example% rpcinfo -p To delete the registration for version 1 of the walld (program number 100008) service for all transports use: example# rpcinfo -d 100008 1 or example# rpcinfo -d walld 1 SEE ALSO
rpc(3), netconfig(5), rpc(5), rpcbind(8) BSD
August 18, 1992 BSD
All times are GMT -4. The time now is 02:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy