First commit

This commit is contained in:
2026-09-06 17:43:06 +03:00
commit 0fe9114117
10 changed files with 278 additions and 0 deletions

16
common/DieWithMessage.c Normal file
View File

@@ -0,0 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
void DieWithUserMessage(const char *msg, const char *detail) {
fputs(msg, stderr);
fputs(": ", stderr);
fputs(detail, stderr);
fputc('\n', stderr);
exit(1);
}
void DieWithSystemMessage(const char *msg) {
perror(msg);
exit(1);
}

12
common/Practical.c Normal file
View File

@@ -0,0 +1,12 @@
#include <netdb.h>
#include <stddef.h>
#include "Practical.h"
int proto_get_num(const char *name) {
struct protoent *protoent = getprotobyname(name);
if (protoent == NULL) {
DieWithSystemMessage("getprotobyname");
}
return protoent->p_proto;
}

7
common/Practical.h Normal file
View File

@@ -0,0 +1,7 @@
#pragma once
#define BUFSIZE 512
void DieWithUserMessage(const char *msg, const char *detail);
void DieWithSystemMessage(const char *msg);
int proto_get_num(const char *name);