From: Roy Marples Date: Mon, 31 Mar 2008 10:23:59 +0000 (+0000) Subject: read(2) works on ssize_t so we should use this rather than size_t for our buffers... X-Git-Tag: v4.0.2~512 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=211da073490c5decd1deb46034385437a54ca977;p=thirdparty%2Fdhcpcd.git read(2) works on ssize_t so we should use this rather than size_t for our buffers. A DHCP or ARP packet still easily fits into this. --- diff --git a/arp.c b/arp.c index 3db15580..160acf19 100644 --- a/arp.c +++ b/arp.c @@ -126,8 +126,8 @@ arp_claim(struct interface *iface, struct in_addr address) { -1, POLLIN, 0 }, { -1, POLLIN, 0 } }; - size_t bufpos = 0; - size_t buflen = iface->buffer_length; + ssize_t bufpos = 0; + ssize_t buflen = iface->buffer_length; int bytes; int s = 0; struct timeval stopat; diff --git a/bpf.c b/bpf.c index 5e978ecd..0266b696 100644 --- a/bpf.c +++ b/bpf.c @@ -115,7 +115,7 @@ open_socket(struct interface *iface, int protocol) ssize_t send_packet(const struct interface *iface, int type, - const unsigned char *data, size_t len) + const unsigned char *data, ssize_t len) { struct iovec iov[2]; struct ether_header hw; @@ -135,7 +135,7 @@ send_packet(const struct interface *iface, int type, * So we pass the buffer in the API so we can loop on >1 dhcp packet. */ ssize_t get_packet(const struct interface *iface, unsigned char *data, - unsigned char *buffer, size_t *buffer_len, size_t *buffer_pos) + unsigned char *buffer, ssize_t *buffer_len, ssize_t *buffer_pos) { union { @@ -153,7 +153,7 @@ get_packet(const struct interface *iface, unsigned char *data, struct udp_dhcp_packet *packet; } pay; struct timespec ts; - size_t len; + ssize_t len; unsigned char *payload; bool have_data; @@ -204,7 +204,7 @@ get_packet(const struct interface *iface, unsigned char *data, /* Update the buffer_pos pointer */ bpf.buffer += BPF_WORDALIGN(bpf.packet->bh_hdrlen + bpf.packet->bh_caplen); - if ((unsigned)(bpf.buffer - buffer) < *buffer_len) + if (bpf.buffer - buffer < *buffer_len) *buffer_pos = bpf.buffer - buffer; else *buffer_pos = 0; diff --git a/client.c b/client.c index 23d7cc0f..68afa712 100644 --- a/client.c +++ b/client.c @@ -123,8 +123,8 @@ struct if_state { bool daemonised; bool persistent; unsigned char *buffer; - size_t buffer_len; - size_t buffer_pos; + ssize_t buffer_len; + ssize_t buffer_pos; }; static pid_t diff --git a/socket.c b/socket.c index 3bd765ac..b9862a65 100644 --- a/socket.c +++ b/socket.c @@ -182,7 +182,7 @@ eexit: ssize_t send_packet(const struct interface *iface, int type, - const unsigned char *data, size_t len) + const unsigned char *data, ssize_t len) { union sockunion { struct sockaddr sa; @@ -214,7 +214,7 @@ send_packet(const struct interface *iface, int type, * We only have the buffer listed to keep the same API. */ ssize_t get_packet(const struct interface *iface, unsigned char *data, - unsigned char *buffer, size_t *buffer_len, size_t *buffer_pos) + unsigned char *buffer, ssize_t *buffer_len, ssize_t *buffer_pos) { ssize_t bytes; union diff --git a/socket.h b/socket.h index 67366da8..90922f8c 100644 --- a/socket.h +++ b/socket.h @@ -39,7 +39,7 @@ void setup_packet_filters(void); int open_socket(struct interface *, int); ssize_t send_packet(const struct interface *, int, - const unsigned char *, size_t); + const unsigned char *, ssize_t); ssize_t get_packet(const struct interface *, unsigned char *, - unsigned char *, size_t *, size_t *); + unsigned char *, ssize_t *, ssize_t *); #endif