]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Casting and alignment fixes
authorwessels <>
Fri, 6 Mar 1998 03:07:43 +0000 (03:07 +0000)
committerwessels <>
Fri, 6 Mar 1998 03:07:43 +0000 (03:07 +0000)
src/icp_v2.cc
src/icp_v3.cc
src/pinger.cc

index 609f7ee07bfd9d8859d4a5e803f796402f3c7695..c5f94bb8f1982061fea6be65fe1a1de641c5367b 100644 (file)
@@ -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);
index 037b5958302fe918284e176d7551aaf4db145ee2..cbb9d5da495e84a7198e121a463914d4669fc6ea 100644 (file)
@@ -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),
index 783b1de2584278b985a48384a4714c1f70b1f2dc..33ff093eb63ed19247d10b0707d5316ab4953e18 100644 (file)
@@ -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,