Project 16: Basic RPC Calculator
A calculator service using Sun RPC with rpcgen-generated stubs.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | C |
| Alternative Languages | N/A |
| Difficulty | Level 3 (Advanced) |
| Time Estimate | See main guide |
| Knowledge Area | Distributed Systems, RPC |
| Tooling | See main guide |
| Prerequisites | See main guide |
What You Will Build
A calculator service using Sun RPC with rpcgen-generated stubs.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- rpcgen syntax → Writing .x interface files
- XDR types → Serializing complex structures
- portmapper → Registering and looking up services
Key Concepts
- Map the project to core concepts before you code.
Real-World Outcome
# Define the interface (calc.x)
$ cat calc.x
program CALC_PROG {
version CALC_VERS {
int ADD(operands) = 1;
int SUBTRACT(operands) = 2;
int MULTIPLY(operands) = 3;
} = 1;
} = 0x31230000;
# Generate stubs
$ rpcgen calc.x
# Creates: calc.h, calc_clnt.c, calc_svc.c, calc_xdr.c
# Start server
$ ./calc_server &
Registered with portmapper: program 0x31230000, version 1
# Run client
$ ./calc_client localhost add 5 3
Result: 8
$ ./calc_client localhost multiply 7 6
Result: 42
# Query portmapper
$ rpcinfo -p localhost | grep 31230000
100000 4 tcp 111 portmapper
0x31230000 1 tcp 45678 calc
Implementation Guide
- Reproduce the simplest happy-path scenario.
- Build the smallest working version of the core feature.
- Add input validation and error handling.
- Add instrumentation/logging to confirm behavior.
- Refactor into clean modules with tests.
Milestones
- Milestone 1: Minimal working program that runs end-to-end.
- Milestone 2: Correct outputs for typical inputs.
- Milestone 3: Robust handling of edge cases.
- Milestone 4: Clean structure and documented usage.
Validation Checklist
- Output matches the real-world outcome example
- Handles invalid inputs safely
- Provides clear errors and exit codes
- Repeatable results across runs
References
- Main guide:
UNIX_IPC_STEVENS_VOL2_MASTERY.md - Primary references are listed in the main guide