Use load/store_32/16_be/le functions
authorKen Raeburn <raeburn@mit.edu>
Sat, 2 Aug 2008 06:47:33 +0000 (06:47 +0000)
committerKen Raeburn <raeburn@mit.edu>
Sat, 2 Aug 2008 06:47:33 +0000 (06:47 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20603 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/krb/serialize.c
src/lib/krb5/os/mk_faddr.c
src/lib/krb5/os/sendto_kdc.c

index d3f52581232acdd20359943693c40c74ebd921eb..fc20fb192808e6b9ef15e67dec11acd3b2c7132c 100644 (file)
@@ -181,10 +181,7 @@ krb5_error_code KRB5_CALLCONV
 krb5_ser_pack_int32(krb5_int32 iarg, krb5_octet **bufp, size_t *remainp)
 {
     if (*remainp >= sizeof(krb5_int32)) {
-       (*bufp)[0] = (krb5_octet) ((iarg >> 24) & 0xff);
-       (*bufp)[1] = (krb5_octet) ((iarg >> 16) & 0xff);
-       (*bufp)[2] = (krb5_octet) ((iarg >> 8) & 0xff);
-       (*bufp)[3] = (krb5_octet) (iarg & 0xff);
+       store_32_be(iarg, *bufp);
        *bufp += sizeof(krb5_int32);
        *remainp -= sizeof(krb5_int32);
        return(0);
@@ -233,10 +230,7 @@ krb5_error_code KRB5_CALLCONV
 krb5_ser_unpack_int32(krb5_int32 *intp, krb5_octet **bufp, size_t *remainp)
 {
     if (*remainp >= sizeof(krb5_int32)) {
-       *intp = (((krb5_int32) ((unsigned char) (*bufp)[0]) << 24) |
-                ((krb5_int32) ((unsigned char) (*bufp)[1]) << 16) |
-                ((krb5_int32) ((unsigned char) (*bufp)[2]) << 8) |
-                ((krb5_int32) ((unsigned char) (*bufp)[3])));
+       *intp = load_32_be(*bufp);
        *bufp += sizeof(krb5_int32);
        *remainp -= sizeof(krb5_int32);
        return(0);
index 2184f72206013a73f902f77afc211a599576159d..cd243c0223bf46653e87ba44294cb6b79b639dd5 100644 (file)
@@ -61,10 +61,8 @@ krb5_make_fulladdr(krb5_context context, krb5_address *kaddr, krb5_address *kpor
     *marshal++ = (krb5_octet) ((tmp16 >> 8) & 0xff);
 
     tmp32 = kaddr->length;
-    *marshal++ = (krb5_octet) (tmp32 & 0xff);
-    *marshal++ = (krb5_octet) ((tmp32 >> 8) & 0xff);
-    *marshal++ = (krb5_octet) ((tmp32 >> 16) & 0xff);
-    *marshal++ = (krb5_octet) ((tmp32 >> 24) & 0xff);
+    store_32_le(tmp32, marshal);
+    marshal += 4;
 
     (void) memcpy((char *)marshal, (char *)(kaddr->contents), kaddr->length);
     marshal += kaddr->length;
@@ -72,14 +70,12 @@ krb5_make_fulladdr(krb5_context context, krb5_address *kaddr, krb5_address *kpor
     tmp16 = kport->addrtype;
     *marshal++ = 0x00;
     *marshal++ = 0x00;
-    *marshal++ = (krb5_octet) (tmp16 & 0xff);
-    *marshal++ = (krb5_octet) ((tmp16 >> 8) & 0xff);
+    store_16_le(tmp16, marshal);
+    marshal += 2;
 
     tmp32 = kport->length;
-    *marshal++ = (krb5_octet) (tmp32 & 0xff);
-    *marshal++ = (krb5_octet) ((tmp32 >> 8) & 0xff);
-    *marshal++ = (krb5_octet) ((tmp32 >> 16) & 0xff);
-    *marshal++ = (krb5_octet) ((tmp32 >> 24) & 0xff);
+    store_32_le(tmp32, marshal);
+    marshal += 4;
 
     (void) memcpy((char *)marshal, (char *)(kport->contents), kport->length);
     marshal += kport->length;
index 2063b302fe4d0d6b96b87d9605b3727e6ee0cfcc..48937fd9986de673840fe0aaccee6137750ac3e1 100644 (file)
@@ -587,11 +587,7 @@ set_conn_state_msg_length (struct conn_state *state, const krb5_data *message)
 
     if (!state->is_udp) {
 
-       state->x.out.msg_len_buf[0] = (message->length >> 24) & 0xff;
-       state->x.out.msg_len_buf[1] = (message->length >> 16) & 0xff;
-       state->x.out.msg_len_buf[2] = (message->length >>  8) & 0xff;
-       state->x.out.msg_len_buf[3] =  message->length        & 0xff;
-
+       store_32_be(message->length, state->x.out.msg_len_buf);
        SG_SET(&state->x.out.sgbuf[0], state->x.out.msg_len_buf, 4);
        SG_SET(&state->x.out.sgbuf[1], message->data, message->length);
        state->x.out.sg_count = 2;