mirror of
https://github.com/kanjitalk755/macemu.git
synced 2025-01-12 16:30:44 +00:00
Packet headers can be examined through unaligned addresses. This patch
fixes this, especially for MIPS & SPARC platforms. [Initial patch from Brian J. Johnson]
This commit is contained in:
parent
998e1f7f7b
commit
5ee0a6741b
@ -90,6 +90,10 @@
|
||||
#define BOOTP_VENDOR_LEN 64
|
||||
#define DHCP_OPT_LEN 312
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct bootp_t {
|
||||
struct ip ip;
|
||||
struct udphdr udp;
|
||||
@ -108,6 +112,10 @@ struct bootp_t {
|
||||
uint8_t bp_sname[64];
|
||||
uint8_t bp_file[128];
|
||||
uint8_t bp_vend[DHCP_OPT_LEN];
|
||||
};
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(0)
|
||||
#endif
|
||||
|
||||
void bootp_input(struct mbuf *m);
|
||||
|
@ -80,6 +80,10 @@ typedef u_int32_t n_long; /* long as received from the net */
|
||||
* pragmatically since otherwise unsigned comparisons can result
|
||||
* against negative integers quite easily, and fail in subtle ways.
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct ip {
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
u_int ip_v:4, /* version */
|
||||
@ -99,7 +103,11 @@ struct ip {
|
||||
u_int8_t ip_p; /* protocol */
|
||||
u_int16_t ip_sum; /* checksum */
|
||||
struct in_addr ip_src,ip_dst; /* source and dest address */
|
||||
};
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(0)
|
||||
#endif
|
||||
|
||||
#define IP_MAXPACKET 65535 /* maximum packet size */
|
||||
|
||||
@ -143,6 +151,10 @@ struct ip {
|
||||
/*
|
||||
* Time stamp option structure.
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct ip_timestamp {
|
||||
u_int8_t ipt_code; /* IPOPT_TS */
|
||||
u_int8_t ipt_len; /* size of structure (variable) */
|
||||
@ -161,7 +173,11 @@ struct ip_timestamp {
|
||||
n_long ipt_time;
|
||||
} ipt_ta[1];
|
||||
} ipt_timestamp;
|
||||
};
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(0)
|
||||
#endif
|
||||
|
||||
/* flag bits for ipt_flg */
|
||||
#define IPOPT_TS_TSONLY 0 /* timestamps only */
|
||||
@ -208,6 +224,10 @@ typedef caddr32_t ipasfragp_32;
|
||||
/*
|
||||
* Overlay for ip header used by other protocols (tcp, udp).
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct ipovly {
|
||||
caddr32_t ih_next, ih_prev; /* for protocol sequence q's */
|
||||
u_int8_t ih_x1; /* (unused) */
|
||||
@ -215,7 +235,11 @@ struct ipovly {
|
||||
int16_t ih_len; /* protocol length */
|
||||
struct in_addr ih_src; /* source internet address */
|
||||
struct in_addr ih_dst; /* destination internet address */
|
||||
};
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Ip reassembly queue structure. Each fragment
|
||||
|
@ -47,6 +47,10 @@ typedef u_int32_t n_time;
|
||||
/*
|
||||
* Structure of an icmp header.
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct icmp {
|
||||
u_char icmp_type; /* type of message, see below */
|
||||
u_char icmp_code; /* type sub code */
|
||||
@ -92,7 +96,11 @@ struct icmp {
|
||||
#define icmp_ip icmp_dun.id_ip.idi_ip
|
||||
#define icmp_mask icmp_dun.id_mask
|
||||
#define icmp_data icmp_dun.id_data
|
||||
};
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Lower bounds on packet lengths for various types.
|
||||
|
@ -595,7 +595,7 @@ void slirp_input(const uint8_t *pkt, int pkt_len)
|
||||
if (pkt_len < ETH_HLEN)
|
||||
return;
|
||||
|
||||
proto = ntohs(*(uint16_t *)(pkt + 12));
|
||||
proto = (pkt[12] << 8) | pkt[13];
|
||||
switch(proto) {
|
||||
case ETH_P_ARP:
|
||||
arp_input(pkt, pkt_len);
|
||||
|
@ -195,6 +195,15 @@ int inet_aton _P((const char *cp, struct in_addr *ia));
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#if defined __GNUC__
|
||||
#define PACKED__ __attribute__ ((packed))
|
||||
#elif defined __sgi
|
||||
#define PRAGMA_PACK_SUPPORTED 1
|
||||
#define PACKED__
|
||||
#else
|
||||
#error "Packed attribute or pragma shall be supported"
|
||||
#endif
|
||||
|
||||
#include "ip.h"
|
||||
#include "tcp.h"
|
||||
#include "tcp_timer.h"
|
||||
|
@ -53,6 +53,10 @@ extern struct socket *tcp_last_so;
|
||||
* TCP header.
|
||||
* Per RFC 793, September, 1981.
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct tcphdr {
|
||||
u_int16_t th_sport; /* source port */
|
||||
u_int16_t th_dport; /* destination port */
|
||||
@ -75,7 +79,11 @@ struct tcphdr {
|
||||
u_int16_t th_win; /* window */
|
||||
u_int16_t th_sum; /* checksum */
|
||||
u_int16_t th_urp; /* urgent pointer */
|
||||
};
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(0)
|
||||
#endif
|
||||
|
||||
#include "tcp_var.h"
|
||||
|
||||
|
@ -12,6 +12,10 @@
|
||||
|
||||
#define TFTP_FILENAME_MAX 512
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct tftp_t {
|
||||
struct ip ip;
|
||||
struct udphdr udp;
|
||||
@ -27,6 +31,10 @@ struct tftp_t {
|
||||
} tp_error;
|
||||
u_int8_t tp_buf[512 + 2];
|
||||
} x;
|
||||
};
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(0)
|
||||
#endif
|
||||
|
||||
void tftp_input(struct mbuf *m);
|
||||
|
@ -46,12 +46,20 @@ extern struct socket *udp_last_so;
|
||||
* Udp protocol header.
|
||||
* Per RFC 768, September, 1981.
|
||||
*/
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
||||
struct udphdr {
|
||||
u_int16_t uh_sport; /* source port */
|
||||
u_int16_t uh_dport; /* destination port */
|
||||
int16_t uh_ulen; /* udp length */
|
||||
u_int16_t uh_sum; /* udp checksum */
|
||||
};
|
||||
} PACKED__;
|
||||
|
||||
#ifdef PRAGMA_PACK_SUPPORTED
|
||||
#pragma pack(0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* UDP kernel structures and variables.
|
||||
|
Loading…
x
Reference in New Issue
Block a user