From: wessels <> Date: Fri, 6 Mar 1998 03:07:43 +0000 (+0000) Subject: Casting and alignment fixes X-Git-Tag: SQUID_3_0_PRE1~3909 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c8f6c9c732bc245592febcdf0e60c72badd3723f;p=thirdparty%2Fsquid.git Casting and alignment fixes --- diff --git a/src/icp_v2.cc b/src/icp_v2.cc index 609f7ee07b..c5f94bb8f1 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -134,7 +134,6 @@ static void icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len) { icp_common_t header; - icp_common_t *headerp = (icp_common_t *) (void *) buf; StoreEntry *entry = NULL; char *url = NULL; const cache_key *key; @@ -144,18 +143,19 @@ icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len) icp_common_t *reply; int src_rtt = 0; u_num32 flags = 0; - header.opcode = headerp->opcode; - header.version = headerp->version; - header.length = ntohs(headerp->length); - header.reqnum = ntohl(headerp->reqnum); - header.flags = ntohl(headerp->flags); - header.shostid = headerp->shostid; - header.pad = ntohl(headerp->pad); + xmemcpy(&header, buf, sizeof(icp_common_t)); + /* + * Only these fields need to be converted + */ + header.length = ntohs(header.length); + header.reqnum = ntohl(header.reqnum); + header.flags = ntohl(header.flags); + header.pad = ntohl(header.pad); switch (header.opcode) { case ICP_QUERY: /* We have a valid packet */ - url = buf + sizeof(header) + sizeof(u_num32); + url = buf + sizeof(icp_common_t) + sizeof(u_num32); if ((icp_request = urlParse(METHOD_GET, url)) == NULL) { reply = icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0); icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, PROTO_NONE); @@ -223,7 +223,7 @@ icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len) debug(12, 0) ("icpHandleIcpV2: Disabling use of private keys\n"); neighbors_do_private_keys = 0; } - url = buf + sizeof(header); + url = buf + sizeof(icp_common_t); debug(12, 3) ("icpHandleIcpV2: %s from %s for '%s'\n", icp_opcode_str[header.opcode], inet_ntoa(from.sin_addr), @@ -282,7 +282,6 @@ icpHandleUdp(int sock, void *datanotused) int from_len; LOCAL_ARRAY(char, buf, SQUID_UDP_SO_RCVBUF); int len; - icp_common_t *headerp = NULL; int icp_version; commSetSelect(sock, COMM_SELECT_READ, icpHandleUdp, NULL, 0); @@ -320,8 +319,8 @@ icpHandleUdp(int sock, void *datanotused) debug(12, 4) ("icpHandleUdp: Ignoring too-small UDP packet\n"); return; } - headerp = (icp_common_t *) (void *) buf; - if ((icp_version = (int) headerp->version) == ICP_VERSION_2) + icp_version = (int) buf[1]; /* cheat! */ + if (icp_version == ICP_VERSION_2) icpHandleIcpV2(sock, from, buf, len); else if (icp_version == ICP_VERSION_3) icpHandleIcpV3(sock, from, buf, len); diff --git a/src/icp_v3.cc b/src/icp_v3.cc index 037b595830..cbb9d5da49 100644 --- a/src/icp_v3.cc +++ b/src/icp_v3.cc @@ -6,25 +6,25 @@ icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len) { icp_common_t header; icp_common_t *reply; - icp_common_t *headerp = (icp_common_t *) (void *) buf; StoreEntry *entry = NULL; char *url = NULL; const cache_key *key; request_t *icp_request = NULL; int allow = 0; aclCheck_t checklist; - - header.opcode = headerp->opcode; - header.version = headerp->version; - header.length = ntohs(headerp->length); - header.reqnum = ntohl(headerp->reqnum); - header.flags = ntohl(headerp->flags); - header.shostid = headerp->shostid; + xmemcpy(&header, buf, sizeof(icp_common_t)); + /* + * Only these fields need to be converted + */ + header.length = ntohs(header.length); + header.reqnum = ntohl(header.reqnum); + header.flags = ntohl(header.flags); + header.pad = ntohl(header.pad); switch (header.opcode) { case ICP_QUERY: /* We have a valid packet */ - url = buf + sizeof(header) + sizeof(u_num32); + url = buf + sizeof(icp_common_t) + sizeof(u_num32); if ((icp_request = urlParse(METHOD_GET, url)) == NULL) { reply = icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0); icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, PROTO_NONE); @@ -85,7 +85,7 @@ icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len) debug(12, 0) ("icpHandleIcpV3: Disabling use of private keys\n"); neighbors_do_private_keys = 0; } - url = buf + sizeof(header); + url = buf + sizeof(icp_common_t); debug(12, 3) ("icpHandleIcpV3: %s from %s for '%s'\n", icp_opcode_str[header.opcode], inet_ntoa(from.sin_addr), diff --git a/src/pinger.cc b/src/pinger.cc index 783b1de258..33ff093eb6 100644 --- a/src/pinger.cc +++ b/src/pinger.cc @@ -1,6 +1,6 @@ /* - * $Id: pinger.cc,v 1.32 1998/02/10 00:58:43 wessels Exp $ + * $Id: pinger.cc,v 1.33 1998/03/05 20:07:44 wessels Exp $ * * DEBUG: section 42 ICMP Pinger program * AUTHOR: Duane Wessels @@ -175,11 +175,13 @@ pingerRecv(void) int iphdrlen = 20; struct iphdr *ip = NULL; struct icmphdr *icmp = NULL; - LOCAL_ARRAY(char, pkt, MAX_PKT_SZ); + static char *pkt = NULL; struct timeval now; icmpEchoData *echo; static pingerReplyData preply; + if (pkt == NULL) + pkt = xmalloc(MAX_PKT_SZ); fromlen = sizeof(from); n = recvfrom(icmp_sock, pkt,