networking · beginner · ~10 min · safe pentest lab
Build a sockaddr_in and call connect() on it.
Implement int connect_local(int port) that opens a TCP socket and connects to 127.0.0.1:port. Returns the connected fd, or -1 on any failure.
The full client prologue: socket → fill sockaddr_in → connect.
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
int connect_local(int port) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.