First commit
This commit is contained in:
16
common/DieWithMessage.c
Normal file
16
common/DieWithMessage.c
Normal 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
12
common/Practical.c
Normal 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
7
common/Practical.h
Normal 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);
|
||||
Reference in New Issue
Block a user