-
Notifications
You must be signed in to change notification settings - Fork 0
/
UDPcommon.c
32 lines (26 loc) · 870 Bytes
/
UDPcommon.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include "UDPcommon.h"
// Print last windows error and message
DWORD GetLastErrorAndPrint(void) {
DWORD out = GetLastError();
LPSTR lpBuffer = NULL;
DWORD dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM;
FormatMessage(dwFlags, NULL, out, LANG_SYSTEM_DEFAULT,
(LPSTR)&lpBuffer, 0, NULL);
printf_s("ErrCode: %d\n", out);
printf_s("ErrMsg : %s\n", lpBuffer);
return out;
}
// Print last WSA error number and message
DWORD WSAGetLastErrorAndPrint(void) {
DWORD out = WSAGetLastError();
LPSTR lpBuffer = NULL;
DWORD dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM;
FormatMessage(dwFlags, NULL, out, LANG_SYSTEM_DEFAULT,
(LPSTR)&lpBuffer, 0, NULL);
printf_s("ErrCode: %d\n", out);
printf_s("ErrMsg : %s\n", lpBuffer);
return out;
}