cpack.c (146774) | cpack.c (235530) |
---|---|
1/*- 2 * Copyright (c) 2003, 2004 David Young. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 24 unchanged lines hidden (view full) --- 33 34#include <stdlib.h> 35#include <string.h> 36#include <tcpdump-stdinc.h> 37 38#include "cpack.h" 39#include "extract.h" 40 | 1/*- 2 * Copyright (c) 2003, 2004 David Young. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 24 unchanged lines hidden (view full) --- 33 34#include <stdlib.h> 35#include <string.h> 36#include <tcpdump-stdinc.h> 37 38#include "cpack.h" 39#include "extract.h" 40 |
41static u_int8_t * | 41u_int8_t * |
42cpack_next_boundary(u_int8_t *buf, u_int8_t *p, size_t alignment) 43{ 44 size_t misalignment = (size_t)(p - buf) % alignment; 45 46 if (misalignment == 0) 47 return p; 48 49 return p + (alignment - misalignment); 50} 51 52/* Advance to the next wordsize boundary. Return NULL if fewer than 53 * wordsize bytes remain in the buffer after the boundary. Otherwise, 54 * return a pointer to the boundary. 55 */ | 42cpack_next_boundary(u_int8_t *buf, u_int8_t *p, size_t alignment) 43{ 44 size_t misalignment = (size_t)(p - buf) % alignment; 45 46 if (misalignment == 0) 47 return p; 48 49 return p + (alignment - misalignment); 50} 51 52/* Advance to the next wordsize boundary. Return NULL if fewer than 53 * wordsize bytes remain in the buffer after the boundary. Otherwise, 54 * return a pointer to the boundary. 55 */ |
56static u_int8_t * | 56u_int8_t * |
57cpack_align_and_reserve(struct cpack_state *cs, size_t wordsize) 58{ 59 u_int8_t *next; 60 61 /* Ensure alignment. */ 62 next = cpack_next_boundary(cs->c_buf, cs->c_next, wordsize); 63 64 /* Too little space for wordsize bytes? */ --- 80 unchanged lines hidden --- | 57cpack_align_and_reserve(struct cpack_state *cs, size_t wordsize) 58{ 59 u_int8_t *next; 60 61 /* Ensure alignment. */ 62 next = cpack_next_boundary(cs->c_buf, cs->c_next, wordsize); 63 64 /* Too little space for wordsize bytes? */ --- 80 unchanged lines hidden --- |