I have a very simple program to do in C using Unix.

The following is what is required by the program:

A key server exists on the bs47c. The server may be accessed at port 10000
using the TCP protocol. You may therefore interact with the server using
the Telnet application (e.g. telnet localhost 10000).

On connecting to the server, it will respond with an identification message
and request your username. You should type your username. The server will
then respond with two pieces of information:
a) an integer value (called the key).
b) a port number.

Simultaneously, the key server has started a new application (we will call
it the verifier, which resides at the port number given by the server).
The verifier will wait (for a maximum of 10 minutes) for you to contact it
to undertake a small dialogue. To achieve this, you should write an application
on bs47c using the socket programming interface to undertake this dialogue.
The steps of the dialogue are:

a) Connect to the verifier at the port number returned by the server.
b) Send the verifier your username as a string (in the C sense, that is with
the null terminating character).
Send the verifier the key supplied by the server
d) Read from the verifier a new integer, called the result. If this value
is less than zero then an error has occurred. -1 indicates an error reading
the data sent to the verifier; -2 means that the username supplied does not
agree and -3 that the supplied key does not agree.
Terminate the connection to the verifier.

The following is pseudo coe for the prgram which i hope someone can help
me with:

Socket Address structure

struct sockaddr_in{

unsigned short sin_faminly: /*AF_INET*/
unsigned short sin_port: /*protocol port*/
struct in_addr sin_addr: /*IP address*/
sin_zero[8]: /*not used*/


Pointer to host table entry:

struct hostent *host;

Structure to hold an IP address:

struct sockaddr_in soc_add;

Pointer to host name or a host array:

char hostname[20];

Pointer to user name or a username array:

char username[20];

Integer variables for portno, key, result,sd, answer….

Clear sockaddr structure

Use memset….

Initialise socket address structure

/* set family to INTERNET */

soc_add.sin_family = AF_INET;

/* convert host name to IP address and copy to soc_addr */

host = gethostbyname (hostname);
bcopy(host -> h_addr, &soc_addr.sin_addrs, 4); /* can use ‘memcopy’ too!*/

/*initialise protocol port number*/

soc_add.sin_port = htons(portno); /*you may read portno from keyboard*/

Create a socket

sd = socket (AF_INET, SOCK_STREAM, 0);
/*parameters: protocol family, comms type : connection based, 0 for TCP)


/* connect your socket to the server */

res= connect (sd, &soc_add, sizeof(soc_add));

Send Info

/* send username and key

res= send (sd, username, 9, 0);
res= send (sd, &key, sizeof (key), 0);

Receive info

Result = recv(sd, &answer, sizeof(answer), 0);

Check results

If answer < 0 then /* print appropriate error massages …*/


/* close socket and print the answer *?

res= close (sd);

I'm pretty desperate for help so if you can help me plese do
Thanks in advance