#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <event.h>
#include "bytebuf.h"
#include "hash.h"
#include "slist.h"
#include "pptp.h"
#include "pptp_local.h"
#include "pptp_subr.h"
const char *
pptp_framing_string(uint32_t bits)
{
static char framing_cap_buf[40];
snprintf(framing_cap_buf, sizeof(framing_cap_buf), "%s%s",
(bits & PPTP_CTRL_FRAMING_ASYNC)? ",async" : "",
(bits & PPTP_CTRL_FRAMING_SYNC)? ",sync" : "");
if (strlen(framing_cap_buf) > 0)
return &framing_cap_buf[1];
return "";
}
const char *
pptp_bearer_string(uint32_t bits)
{
static char bearer_cap_buf[40];
snprintf(bearer_cap_buf, sizeof(bearer_cap_buf), "%s%s",
(bits &PPTP_CTRL_BEARER_ANALOG)? ",analog" : "",
(bits &PPTP_CTRL_BEARER_DIGITAL)? ",digital" : "");
if (strlen(bearer_cap_buf) > 0)
return &bearer_cap_buf[1];
return "";
}
void
pptp_init_header(struct pptp_ctrl_header *header, int length, int ctrl_mes_type)
{
header->length = htons(length);
header->pptp_message_type = htons(PPTP_MES_TYPE_CTRL);
header->magic_cookie = htonl(PPTP_MAGIC_COOKIE);
header->control_message_type = htons(ctrl_mes_type);
header->reserved0 = 0;
}
#define NAME_VAL(x) { x, #x }
static struct _label_name {
int label;
const char *name;
} pptp_StopCCRQ_reason_labels[] = {
NAME_VAL(PPTP_StopCCRQ_REASON_NONE),
NAME_VAL(PPTP_StopCCRQ_REASON_STOP_PROTOCOL),
NAME_VAL(PPTP_StopCCRQ_REASON_STOP_LOCAL_SHUTDOWN),
}, pptp_StopCCRP_result_labels[] = {
NAME_VAL(PPTP_StopCCRP_RESULT_OK),
NAME_VAL(PPTP_StopCCRP_RESULT_GENERIC_ERROR),
}, pptp_general_error_labels[] = {
NAME_VAL(PPTP_ERROR_NONE),
NAME_VAL(PPTP_ERROR_NOT_CONNECTED),
NAME_VAL(PPTP_ERROR_BAD_FORMAT),
NAME_VAL(PPTP_ERROR_NO_RESOURCE),
NAME_VAL(PPTP_ERROR_BAD_CALL),
}, pptp_ctrl_mes_type_labels[] = {
NAME_VAL(PPTP_CTRL_MES_CODE_SCCRQ),
NAME_VAL(PPTP_CTRL_MES_CODE_SCCRP),
NAME_VAL(PPTP_CTRL_MES_CODE_StopCCRQ),
NAME_VAL(PPTP_CTRL_MES_CODE_StopCCRP),
NAME_VAL(PPTP_CTRL_MES_CODE_ECHO_RQ),
NAME_VAL(PPTP_CTRL_MES_CODE_ECHO_RP),
NAME_VAL(PPTP_CTRL_MES_CODE_OCRQ),
NAME_VAL(PPTP_CTRL_MES_CODE_OCRP),
NAME_VAL(PPTP_CTRL_MES_CODE_ICRQ),
NAME_VAL(PPTP_CTRL_MES_CODE_ICRP),
NAME_VAL(PPTP_CTRL_MES_CODE_ICCN),
NAME_VAL(PPTP_CTRL_MES_CODE_CCR),
NAME_VAL(PPTP_CTRL_MES_CODE_CDN),
NAME_VAL(PPTP_CTRL_MES_CODE_SLI),
}, pptp_CDN_result_labels[] = {
NAME_VAL(PPTP_CDN_RESULT_LOST_CARRIER),
NAME_VAL(PPTP_CDN_RESULT_GENRIC_ERROR),
NAME_VAL(PPTP_CDN_RESULT_ADMIN_SHUTDOWN),
NAME_VAL(PPTP_CDN_RESULT_REQUEST),
};
#define LABEL_TO_STRING(func_name, label_names, prefix_len) \
const char * \
func_name(int code) \
{ \
int i; \
\
for (i = 0; i < countof(label_names); i++) { \
if (label_names[i].label == code) \
return label_names[i].name + prefix_len;\
} \
\
return "UNKNOWN"; \
}
LABEL_TO_STRING(pptp_StopCCRQ_reason_string, pptp_StopCCRQ_reason_labels, 21)
LABEL_TO_STRING(pptp_StopCCRP_result_string, pptp_StopCCRP_result_labels, 21)
LABEL_TO_STRING(pptp_general_error_string, pptp_general_error_labels, 11)
LABEL_TO_STRING(pptp_ctrl_mes_type_string, pptp_ctrl_mes_type_labels, 19)
LABEL_TO_STRING(pptp_CDN_result_string, pptp_CDN_result_labels, 16)