]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-pptp.c
More UNALIGNED_MEM{CPY,CMP} on IP addresses.
[tcpdump] / print-pptp.c
index 00f5fe5a78a1455de589fd846a13776d684ce6d0..7e8d1d3f6e84415e519c28247d48732a1622cfdf 100644 (file)
  * PPTP support contributed by Motonori Shindo ([email protected])
  */
 
-
-#ifndef lint
-static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-pptp.c,v 1.8 2002-11-09 17:19:29 itojun Exp $";
-#endif
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -36,16 +30,9 @@ static const char rcsid[] =
 #include <stdio.h>
 
 #include "interface.h"
+#include "extract.h"
 
-static char tstr[] = " [|pptp]";
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-#ifndef FALSE
-#define FALSE 0
-#endif
+static const char tstr[] = " [|pptp]";
 
 #define PPTP_MSG_TYPE_CTRL     1       /* Control Message */
 #define PPTP_MSG_TYPE_MGMT     2       /* Management Message (currently not used */
@@ -103,7 +90,7 @@ struct pptp_hdr {
        u_int32_t magic_cookie;
        u_int16_t ctrl_msg_type;
        u_int16_t reserved0;
-} __attribute__((packed));
+};
 
 struct pptp_msg_sccrq {
        u_int16_t proto_ver;
@@ -114,7 +101,7 @@ struct pptp_msg_sccrq {
        u_int16_t firm_rev;
        u_char hostname[64];
        u_char vendor[64];
-} __attribute__((packed));
+};
 
 struct pptp_msg_sccrp {
        u_int16_t proto_ver;
@@ -126,30 +113,30 @@ struct pptp_msg_sccrp {
        u_int16_t firm_rev;
        u_char hostname[64];
        u_char vendor[64];
-} __attribute__((packed));
+};
 
 struct pptp_msg_stopccrq {
        u_int8_t reason;
        u_int8_t reserved1;
        u_int16_t reserved2;
-} __attribute__((packed));
+};
 
 struct pptp_msg_stopccrp {
        u_int8_t result_code;
        u_int8_t err_code;
        u_int16_t reserved1;
-} __attribute__((packed));
+};
 
 struct pptp_msg_echorq {
        u_int32_t id;
-} __attribute__((packed));
+};
 
 struct pptp_msg_echorp {
        u_int32_t id;
        u_int8_t result_code;
        u_int8_t err_code;
        u_int16_t reserved1;
-} __attribute__((packed));
+};
 
 struct pptp_msg_ocrq {
        u_int16_t call_id;
@@ -164,7 +151,7 @@ struct pptp_msg_ocrq {
        u_int16_t reserved1;
        u_char phone_no[64];
        u_char subaddr[64];
-} __attribute__((packed));
+};
 
 struct pptp_msg_ocrp {
        u_int16_t call_id;
@@ -176,7 +163,7 @@ struct pptp_msg_ocrp {
        u_int16_t recv_winsiz;
        u_int16_t pkt_proc_delay;
        u_int32_t phy_chan_id;
-} __attribute__((packed));
+};
 
 struct pptp_msg_icrq {
        u_int16_t call_id;
@@ -188,7 +175,7 @@ struct pptp_msg_icrq {
        u_char dialed_no[64];           /* DNIS */
        u_char dialing_no[64];          /* CLID */
        u_char subaddr[64];
-} __attribute__((packed));
+};
 
 struct pptp_msg_icrp {
        u_int16_t call_id;
@@ -198,7 +185,7 @@ struct pptp_msg_icrp {
        u_int16_t recv_winsiz;
        u_int16_t pkt_proc_delay;
        u_int16_t reserved1;
-} __attribute__((packed));
+};
 
 struct pptp_msg_iccn {
        u_int16_t peer_call_id;
@@ -207,12 +194,12 @@ struct pptp_msg_iccn {
        u_int16_t recv_winsiz;
        u_int16_t pkt_proc_delay;
        u_int32_t framing_type;
-} __attribute__((packed));
+};
 
 struct pptp_msg_ccrq {
        u_int16_t call_id;
        u_int16_t reserved1;
-} __attribute__((packed));
+};
 
 struct pptp_msg_cdn {
        u_int16_t call_id;
@@ -221,7 +208,7 @@ struct pptp_msg_cdn {
        u_int16_t cause_code;
        u_int16_t reserved1;
        u_char call_stats[128];
-} __attribute__((packed));
+};
 
 struct pptp_msg_wen {
        u_int16_t peer_call_id;
@@ -232,14 +219,14 @@ struct pptp_msg_wen {
        u_int32_t buffer_overrun;
        u_int32_t timeout_err;
        u_int32_t align_err;
-} __attribute__((packed));
+};
 
 struct pptp_msg_sli {
        u_int16_t peer_call_id;
        u_int16_t reserved1;
        u_int32_t send_accm;
        u_int32_t recv_accm;
-} __attribute__((packed));
+};
 
 /* attributes that appear more than once in above messages:
 
@@ -286,10 +273,10 @@ static void
 pptp_bearer_cap_print(const u_int32_t *bearer_cap)
 {
        printf(" BEARER_CAP(");
-       if (ntohl(*bearer_cap) & PPTP_BEARER_CAP_DIGITAL_MASK) {
+       if (EXTRACT_32BITS(bearer_cap) & PPTP_BEARER_CAP_DIGITAL_MASK) {
                 printf("D");
         }
-        if (ntohl(*bearer_cap) & PPTP_BEARER_CAP_ANALOG_MASK) {
+        if (EXTRACT_32BITS(bearer_cap) & PPTP_BEARER_CAP_ANALOG_MASK) {
                 printf("A");
         }
        printf(")");
@@ -299,7 +286,7 @@ static void
 pptp_bearer_type_print(const u_int32_t *bearer_type)
 {
        printf(" BEARER_TYPE(");
-       switch (ntohl(*bearer_type)) {
+       switch (EXTRACT_32BITS(bearer_type)) {
        case 1:
                printf("A");    /* Analog */
                break;
@@ -319,25 +306,25 @@ pptp_bearer_type_print(const u_int32_t *bearer_type)
 static void
 pptp_call_id_print(const u_int16_t *call_id)
 {
-       printf(" CALL_ID(%u)", ntohs(*call_id));
+       printf(" CALL_ID(%u)", EXTRACT_16BITS(call_id));
 }
 
 static void
 pptp_call_ser_print(const u_int16_t *call_ser)
 {
-       printf(" CALL_SER_NUM(%u)", ntohs(*call_ser));
+       printf(" CALL_SER_NUM(%u)", EXTRACT_16BITS(call_ser));
 }
 
 static void
 pptp_cause_code_print(const u_int16_t *cause_code)
 {
-       printf(" CAUSE_CODE(%u)", ntohs(*cause_code));
+       printf(" CAUSE_CODE(%u)", EXTRACT_16BITS(cause_code));
 }
 
 static void
 pptp_conn_speed_print(const u_int32_t *conn_speed)
 {
-       printf(" CONN_SPEED(%lu)", (unsigned long)ntohl(*conn_speed));
+       printf(" CONN_SPEED(%u)", EXTRACT_32BITS(conn_speed));
 }
 
 static void
@@ -378,17 +365,17 @@ pptp_err_code_print(const u_int8_t *err_code)
 static void
 pptp_firm_rev_print(const u_int16_t *firm_rev)
 {
-       printf(" FIRM_REV(%u)", ntohs(*firm_rev));
+       printf(" FIRM_REV(%u)", EXTRACT_16BITS(firm_rev));
 }
 
 static void
 pptp_framing_cap_print(const u_int32_t *framing_cap)
 {
        printf(" FRAME_CAP(");
-       if (ntohl(*framing_cap) & PPTP_FRAMING_CAP_ASYNC_MASK) {
+       if (EXTRACT_32BITS(framing_cap) & PPTP_FRAMING_CAP_ASYNC_MASK) {
                 printf("A");           /* Async */
         }
-        if (ntohl(*framing_cap) & PPTP_FRAMING_CAP_SYNC_MASK) {
+        if (EXTRACT_32BITS(framing_cap) & PPTP_FRAMING_CAP_SYNC_MASK) {
                 printf("S");           /* Sync */
         }
        printf(")");
@@ -398,7 +385,7 @@ static void
 pptp_framing_type_print(const u_int32_t *framing_type)
 {
        printf(" FRAME_TYPE(");
-       switch (ntohl(*framing_type)) {
+       switch (EXTRACT_32BITS(framing_type)) {
        case 1:
                printf("A");            /* Async */
                break;
@@ -424,44 +411,45 @@ pptp_hostname_print(const u_char *hostname)
 static void
 pptp_id_print(const u_int32_t *id)
 {
-       printf(" ID(%lu)", (unsigned long)ntohl(*id));
+       printf(" ID(%u)", EXTRACT_32BITS(id));
 }
 
 static void
 pptp_max_channel_print(const u_int16_t *max_channel)
 {
-       printf(" MAX_CHAN(%u)", ntohs(*max_channel));
+       printf(" MAX_CHAN(%u)", EXTRACT_16BITS(max_channel));
 }
 
 static void
 pptp_peer_call_id_print(const u_int16_t *peer_call_id)
 {
-       printf(" PEER_CALL_ID(%u)", ntohs(*peer_call_id));
+       printf(" PEER_CALL_ID(%u)", EXTRACT_16BITS(peer_call_id));
 }
 
 static void
 pptp_phy_chan_id_print(const u_int32_t *phy_chan_id)
 {
-       printf(" PHY_CHAN_ID(%lu)", (unsigned long)ntohl(*phy_chan_id));
+       printf(" PHY_CHAN_ID(%u)", EXTRACT_32BITS(phy_chan_id));
 }
 
 static void
 pptp_pkt_proc_delay_print(const u_int16_t *pkt_proc_delay)
 {
-       printf(" PROC_DELAY(%u)", ntohs(*pkt_proc_delay));
+       printf(" PROC_DELAY(%u)", EXTRACT_16BITS(pkt_proc_delay));
 }
 
 static void
 pptp_proto_ver_print(const u_int16_t *proto_ver)
 {
        printf(" PROTO_VER(%u.%u)",     /* Version.Revision */
-              ntohs(*proto_ver) >> 8, ntohs(*proto_ver) & 0xff);
+              EXTRACT_16BITS(proto_ver) >> 8,
+              EXTRACT_16BITS(proto_ver) & 0xff);
 }
 
 static void
 pptp_recv_winsiz_print(const u_int16_t *recv_winsiz)
 {
-       printf(" RECV_WIN(%u)", ntohs(*recv_winsiz));
+       printf(" RECV_WIN(%u)", EXTRACT_16BITS(recv_winsiz));
 }
 
 static void
@@ -741,9 +729,9 @@ pptp_ocrq_print(const u_char *dat)
        TCHECK(ptr->call_ser);
        pptp_call_ser_print(&ptr->call_ser);
        TCHECK(ptr->min_bps);
-       printf(" MIN_BPS(%lu)", (unsigned long)ntohl(ptr->min_bps));
+       printf(" MIN_BPS(%u)", EXTRACT_32BITS(&ptr->min_bps));
        TCHECK(ptr->max_bps);
-       printf(" MAX_BPS(%lu)", (unsigned long)ntohl(ptr->max_bps));
+       printf(" MAX_BPS(%u)", EXTRACT_32BITS(&ptr->max_bps));
        TCHECK(ptr->bearer_type);
        pptp_bearer_type_print(&ptr->bearer_type);
        TCHECK(ptr->framing_type);
@@ -753,7 +741,7 @@ pptp_ocrq_print(const u_char *dat)
        TCHECK(ptr->pkt_proc_delay);
        pptp_pkt_proc_delay_print(&ptr->pkt_proc_delay);
        TCHECK(ptr->phone_no_len);
-       printf(" PHONE_NO_LEN(%u)", ntohs(ptr->phone_no_len));
+       printf(" PHONE_NO_LEN(%u)", EXTRACT_16BITS(&ptr->phone_no_len));
        TCHECK(ptr->reserved1);
        TCHECK(ptr->phone_no);
        printf(" PHONE_NO(%.64s)", ptr->phone_no);
@@ -810,9 +798,9 @@ pptp_icrq_print(const u_char *dat)
        TCHECK(ptr->phy_chan_id);
        pptp_phy_chan_id_print(&ptr->phy_chan_id);
        TCHECK(ptr->dialed_no_len);
-       printf(" DIALED_NO_LEN(%u)", ntohs(ptr->dialed_no_len));
+       printf(" DIALED_NO_LEN(%u)", EXTRACT_16BITS(&ptr->dialed_no_len));
        TCHECK(ptr->dialing_no_len);
-       printf(" DIALING_NO_LEN(%u)", ntohs(ptr->dialing_no_len));
+       printf(" DIALING_NO_LEN(%u)", EXTRACT_16BITS(&ptr->dialing_no_len));
        TCHECK(ptr->dialed_no);
        printf(" DIALED_NO(%.64s)", ptr->dialed_no);
        TCHECK(ptr->dialing_no);
@@ -921,19 +909,17 @@ pptp_wen_print(const u_char *dat)
        pptp_peer_call_id_print(&ptr->peer_call_id);
        TCHECK(ptr->reserved1);
        TCHECK(ptr->crc_err);
-       printf(" CRC_ERR(%lu)", (unsigned long)ntohl(ptr->crc_err));
+       printf(" CRC_ERR(%u)", EXTRACT_32BITS(&ptr->crc_err));
        TCHECK(ptr->framing_err);
-       printf(" FRAMING_ERR(%lu)", (unsigned long)ntohl(ptr->framing_err));
+       printf(" FRAMING_ERR(%u)", EXTRACT_32BITS(&ptr->framing_err));
        TCHECK(ptr->hardware_overrun);
-       printf(" HARDWARE_OVERRUN(%lu)",
-              (unsigned long)ntohl(ptr->hardware_overrun));
+       printf(" HARDWARE_OVERRUN(%u)", EXTRACT_32BITS(&ptr->hardware_overrun));
        TCHECK(ptr->buffer_overrun);
-       printf(" BUFFER_OVERRUN(%lu)",
-              (unsigned long)ntohl(ptr->buffer_overrun));
+       printf(" BUFFER_OVERRUN(%u)", EXTRACT_32BITS(&ptr->buffer_overrun));
        TCHECK(ptr->timeout_err);
-       printf(" TIMEOUT_ERR(%lu)", (unsigned long)ntohl(ptr->timeout_err));
+       printf(" TIMEOUT_ERR(%u)", EXTRACT_32BITS(&ptr->timeout_err));
        TCHECK(ptr->align_err);
-       printf(" ALIGN_ERR(%lu)", (unsigned long)ntohl(ptr->align_err));
+       printf(" ALIGN_ERR(%u)", EXTRACT_32BITS(&ptr->align_err));
 
        return;
 
@@ -950,9 +936,9 @@ pptp_sli_print(const u_char *dat)
        pptp_peer_call_id_print(&ptr->peer_call_id);
        TCHECK(ptr->reserved1);
        TCHECK(ptr->send_accm);
-       printf(" SEND_ACCM(0x%08lx)", (unsigned long)ntohl(ptr->send_accm));
+       printf(" SEND_ACCM(0x%08x)", EXTRACT_32BITS(&ptr->send_accm));
        TCHECK(ptr->recv_accm);
-       printf(" RECV_ACCM(0x%08lx)", (unsigned long)ntohl(ptr->recv_accm));
+       printf(" RECV_ACCM(0x%08x)", EXTRACT_32BITS(&ptr->recv_accm));
 
        return;
 
@@ -973,11 +959,11 @@ pptp_print(const u_char *dat)
 
        TCHECK(hdr->length);
        if (vflag) {
-               printf(" Length=%u", ntohs(hdr->length));
+               printf(" Length=%u", EXTRACT_16BITS(&hdr->length));
        }
        TCHECK(hdr->msg_type);
        if (vflag) {
-               switch(ntohs(hdr->msg_type)) {
+               switch(EXTRACT_16BITS(&hdr->msg_type)) {
                case PPTP_MSG_TYPE_CTRL:
                        printf(" CTRL-MSG");
                        break;
@@ -991,7 +977,7 @@ pptp_print(const u_char *dat)
        }
 
        TCHECK(hdr->magic_cookie);
-       mc = ntohl(hdr->magic_cookie);
+       mc = EXTRACT_32BITS(&hdr->magic_cookie);
        if (mc != PPTP_MAGIC_COOKIE) {
                printf(" UNEXPECTED Magic-Cookie!!(%08x)", mc);
        }
@@ -999,7 +985,7 @@ pptp_print(const u_char *dat)
                printf(" Magic-Cookie=%08x", mc);
        }
        TCHECK(hdr->ctrl_msg_type);
-       ctrl_msg_type = ntohs(hdr->ctrl_msg_type);
+       ctrl_msg_type = EXTRACT_16BITS(&hdr->ctrl_msg_type);
        if (ctrl_msg_type < PPTP_MAX_MSGTYPE_INDEX) {
                printf(" CTRL_MSGTYPE=%s",
                       pptp_message_type_string[ctrl_msg_type]);