0% found this document useful (0 votes)
13 views10 pages

SiddharthShah 1032221195 DivC 50 DC LabAssignment3

Description

Uploaded by

1032221195
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views10 pages

SiddharthShah 1032221195 DivC 50 DC LabAssignment3

Description

Uploaded by

1032221195
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

mtech@MITWPUMTECH:~$ rpcbind

Command 'rpcbind' not found, but can be installed with:


sudo apt install rpcbind
mtech@MITWPUMTECH:~$ sudo apt install rpcbind
[sudo] password for mtech:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
rpcbind
0 upgraded, 1 newly installed, 0 to remove and 182 not upgraded.
Need to get 46.6 kB of archives.
After this operation, 160 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 rpcbind amd64 1.2.6-2build1 [46.6 kB]
Fetched 46.6 kB in 1s (58.3 kB/s)
Selecting previously unselected package rpcbind.
(Reading database ... 245672 files and directories currently installed.)
Preparing to unpack .../rpcbind_1.2.6-2build1_amd64.deb ...
Unpacking rpcbind (1.2.6-2build1) ...
Setting up rpcbind (1.2.6-2build1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/rpcbind.service → /l
ib/systemd/system/rpcbind.service.
Created symlink /etc/systemd/system/sockets.target.wants/rpcbind.socket → /lib/s
ystemd/system/rpcbind.socket.
Processing triggers for man-db (2.10.2-1) ...
mtech@MITWPUMTECH:~$ rpcbind
rpcbind: another rpcbind is already running. Aborting
mtech@MITWPUMTECH:~$ gedit add.x

struct numbers{

int a;
int b;

};

program ADD_PROG{

version ADD_VERS{

int add(numbers)=1;

}=1;

}=0x4562877;

mtech@MITWPUMTECH:~/Desktop/rpc50$ rpcgen -a -C add.x


mtech@MITWPUMTECH:~/Desktop/rpc50$ ls
add_client.c add.h add_svc.c add_xdr.c
add_clnt.c add_server.c add.x Makefile.add
mtech@MITWPUMTECH:~/Desktop/rpc50$ gedit add_server.c

/*
* This is sample code generated by rpcgen.
* These are only templates and you can use them
* as a guideline for developing your own functions.
*/

#include "add.h"

int *
add_1_svc(numbers *argp, struct svc_req *rqstp)
{
static int result;

printf("add(%d, %d) is called\n", argp->a, argp->b);

result = argp->a + argp->b;

return &result;
}

mtech@MITWPUMTECH:~/Desktop/rpc50$ gedit add_client.c

#include "add.h"
#include <stdio.h>
#include <stdlib.h>

void
add_prog_1(char *host, int x, int y) //++
{
CLIENT *clnt;
int *result_1;
numbers add_1_arg;

#ifndef DEBUG
clnt = clnt_create(host, ADD_PROG, ADD_VERS, "udp");
if (clnt == NULL) {
clnt_pcreateerror(host);
exit(1);
}
#endif /* DEBUG */

add_1_arg.a = x; //++
add_1_arg.b = y; //++
result_1 = add_1(&add_1_arg, clnt);
if (result_1 == (int *) NULL) {
clnt_perror(clnt, "call failed");
} else {
printf("result: %d\n", *result_1); //++
}
#ifndef DEBUG
clnt_destroy(clnt);
#endif /* DEBUG */
}

int
main(int argc, char *argv[])
{
char *host;

if (argc < 4) {
printf("usage: %s server_host x y\n", argv[0]);
exit(1);
}
host = argv[1];
add_prog_1(host, atoi(argv[2]), atoi(argv[3]));
exit(0);
}

mtech@MITWPUMTECH:~/Desktop/rpc50$ make -f Makefile.add


cc -g -I/usr/include/tirpc -c -o add_clnt.o add_clnt.c
cc -g -I/usr/include/tirpc -c -o add_client.o add_client.c
cc -g -I/usr/include/tirpc -c -o add_xdr.o add_xdr.c
cc -g -I/usr/include/tirpc -o add_client add_clnt.o add_client.o add_xdr.o -ltirpc
cc -g -I/usr/include/tirpc -c -o add_svc.o add_svc.c
cc -g -I/usr/include/tirpc -c -o add_server.o add_server.c
cc -g -I/usr/include/tirpc -o add_server add_svc.o add_server.o add_xdr.o -ltirpc
mtech@MITWPUMTECH:~/Desktop/rpc50$ gedit Makefile.add

# This is a template Makefile generated by rpcgen

# Parameters
CLIENT = add_client
SERVER = add_server

SOURCES_CLNT.c =
SOURCES_CLNT.h =
SOURCES_SVC.c =
SOURCES_SVC.h =
SOURCES.x = add.x

TARGETS_SVC.c = add_svc.c add_server.c add_xdr.c


TARGETS_CLNT.c = add_clnt.c add_client.c add_xdr.c
TARGETS = add.h add_xdr.c add_clnt.c add_svc.c add_client.c add_server.c

OBJECTS_CLNT = $(SOURCES_CLNT.c:%.c=%.o) $(TARGETS_CLNT.c:%.c=%.o)


OBJECTS_SVC = $(SOURCES_SVC.c:%.c=%.o) $(TARGETS_SVC.c:%.c=%.o)
# Compiler flags

CFLAGS += -g -I/usr/include/tirpc #++


LDLIBS += -ltirpc #++
RPCGENFLAGS =

# Targets

all : $(CLIENT) $(SERVER)

$(TARGETS) : $(SOURCES.x)
rpcgen $(RPCGENFLAGS) $(SOURCES.x)

$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) $(TARGETS_CLNT.c)

$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) $(TARGETS_SVC.c)

$(CLIENT) : $(OBJECTS_CLNT)
$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) $(LDLIBS)

$(SERVER) : $(OBJECTS_SVC)
$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)

clean:
$(RM) core $(TARGETS) $(OBJECTS_CLNT) $(OBJECTS_SVC) $(CLIENT) $(SERVER)

mtech@MITWPUMTECH:~/Desktop/rpc50$ sudo ./add_server


add(5, 5) is called

---------------------------------------------------------------------------------------------

mtech@MITWPUMTECH:~$ cd Desktop
mtech@MITWPUMTECH:~/Desktop$ cd rpc50
mtech@MITWPUMTECH:~/Desktop/rpc50$ sudo ./add_client
usage: ./add_client server_host x y
mtech@MITWPUMTECH:~/Desktop/rpc50$ sudo ./add_client 127.0.0.1 5 5
result: 10

----------------------------------------------------------------------------------------------

You might also like