changeset 296:d2eb4610ac12 draft

We should use ssize_t here.
author Roy Marples <roy@marples.name>
date Mon, 21 Jan 2008 15:12:31 +0000
parents f41945c6ee87
children 197a1ef06532
files dhcp.c dhcp.h interface.c socket.c socket.h
diffstat 5 files changed, 25 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/dhcp.c	Mon Jan 21 15:10:46 2008 +0000
+++ b/dhcp.c	Mon Jan 21 15:12:31 2008 +0000
@@ -78,9 +78,9 @@
 	return (NULL);
 }
 
-size_t send_message (const interface_t *iface, const dhcp_t *dhcp,
-		     unsigned long xid, char type,
-		     const options_t *options)
+ssize_t send_message (const interface_t *iface, const dhcp_t *dhcp,
+		      unsigned long xid, char type,
+		      const options_t *options)
 {
 	struct udp_dhcp_packet *packet;
 	dhcpmessage_t *message;
@@ -94,7 +94,7 @@
 	uint32_t ul;
 	uint16_t sz;
 	unsigned int message_length;
-	size_t retval;
+	ssize_t retval;
 
 	if (!iface || !options || !dhcp)
 		return -1;
@@ -641,6 +641,7 @@
 
 	return (head);
 }
+
 int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message)
 {
 	const unsigned char *p = message->options;
--- a/dhcp.h	Mon Jan 21 15:10:46 2008 +0000
+++ b/dhcp.h	Mon Jan 21 15:12:31 2008 +0000
@@ -208,9 +208,9 @@
 	dhcpmessage_t dhcp;
 };
 
-size_t send_message (const interface_t *iface, const dhcp_t *dhcp,
-		     unsigned long xid, char type,
-		     const options_t *options);
+ssize_t send_message (const interface_t *iface, const dhcp_t *dhcp,
+		      unsigned long xid, char type,
+		      const options_t *options);
 void free_dhcp (dhcp_t *dhcp);
 int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message);
 
--- a/interface.c	Mon Jan 21 15:10:46 2008 +0000
+++ b/interface.c	Mon Jan 21 15:12:31 2008 +0000
@@ -671,7 +671,7 @@
 	struct msghdr msg;
 	static unsigned int seq;
 	char *buffer;
-	int bytes;
+	ssize_t bytes;
 	union
 	{
 		char *buffer;
--- a/socket.c	Mon Jan 21 15:10:46 2008 +0000
+++ b/socket.c	Mon Jan 21 15:12:31 2008 +0000
@@ -308,10 +308,10 @@
 	return fd;
 }
 
-int send_packet (const interface_t *iface, int type,
-		 const unsigned char *data, int len)
+ssize_t send_packet (const interface_t *iface, int type,
+		     const unsigned char *data, int len)
 {
-	int retval = -1;
+	ssize_t retval = -1;
 	struct iovec iov[2];
 
 	if (iface->family == ARPHRD_ETHER) {
@@ -337,8 +337,8 @@
 
 /* BPF requires that we read the entire buffer.
    So we pass the buffer in the API so we can loop on >1 dhcp packet. */
-int get_packet (const interface_t *iface, unsigned char *data,
-		unsigned char *buffer, int *buffer_len, int *buffer_pos)
+ssize_t get_packet (const interface_t *iface, unsigned char *data,
+		    unsigned char *buffer, int *buffer_len, int *buffer_pos)
 {
 	union
 	{
@@ -364,7 +364,7 @@
 		bpf.buffer += *buffer_pos;
 
 	while (bpf.packet) {
-		int len = -1;
+		ssize_t len = -1;
 		union
 		{
 			unsigned char *buffer;
@@ -478,15 +478,15 @@
 	return fd;
 }
 
-int send_packet (const interface_t *iface, const int type,
-		 const unsigned char *data, const int len)
+ssize_t send_packet (const interface_t *iface, const int type,
+		     const unsigned char *data, const int len)
 {
 	union sockunion {
 		struct sockaddr sa;
 		struct sockaddr_ll sll;
 		struct sockaddr_storage ss;
 	} su;
-	int retval;
+	ssize_t retval;
 
 	if (! iface)
 		return -1;
@@ -511,10 +511,10 @@
 
 /* Linux has no need for the buffer as we can read as much as we want.
    We only have the buffer listed to keep the same API. */
-int get_packet (const interface_t *iface, unsigned char *data,
-		unsigned char *buffer, int *buffer_len, int *buffer_pos)
+ssize_t get_packet (const interface_t *iface, unsigned char *data,
+		    unsigned char *buffer, int *buffer_len, int *buffer_pos)
 {
-	long bytes;
+	ssize_t bytes;
 	union
 	{
 		unsigned char *buffer;
--- a/socket.h	Mon Jan 21 15:10:46 2008 +0000
+++ b/socket.h	Mon Jan 21 15:12:31 2008 +0000
@@ -38,8 +38,8 @@
 		      struct in_addr source, struct in_addr dest);
 
 int open_socket (interface_t *iface, bool arp);
-int send_packet (const interface_t *iface, int type,
-		 const unsigned char *data, int len);
-int get_packet (const interface_t *iface, unsigned char *data,
-		unsigned char *buffer, int *buffer_len, int *buffer_pos);
+ssize_t send_packet (const interface_t *iface, int type,
+		     const unsigned char *data, int len);
+ssize_t get_packet (const interface_t *iface, unsigned char *data,
+		    unsigned char *buffer, int *buffer_len, int *buffer_pos);
 #endif