aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2018-05-09 13:12:40 +0200
committerAlexey Kardashevskiy <aik@ozlabs.ru>2018-05-14 19:56:07 +1000
commit4183816dccb5b2da64cc7f1d5a8239d9d90dd0a6 (patch)
treed33012f130d6d621adee1e070d179aca762cfbad
parentc2a331f275b8e8e6c049eb7d61c03c7dbb39f2a4 (diff)
downloadSLOF-4183816dccb5b2da64cc7f1d5a8239d9d90dd0a6.zip
SLOF-4183816dccb5b2da64cc7f1d5a8239d9d90dd0a6.tar.gz
SLOF-4183816dccb5b2da64cc7f1d5a8239d9d90dd0a6.tar.bz2
libnet: Get rid of unnecessary (char *) casts
For some strange reasons, the libnet code is using int8_t arrays for strings in a couple of places where it really does not make any sense. Therefor a lot of "(char *)" casts are needed when the code is using the string functions from the libc. Let's change the strings to use "char" instead of "int8_t" so we can get rid of a lot of these casts. Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
-rw-r--r--lib/libnet/bootp.c2
-rw-r--r--lib/libnet/dhcp.c43
-rw-r--r--lib/libnet/dhcpv6.c3
-rw-r--r--lib/libnet/netload.c2
-rw-r--r--lib/libnet/tftp.c16
-rw-r--r--lib/libnet/tftp.h2
6 files changed, 35 insertions, 33 deletions
diff --git a/lib/libnet/bootp.c b/lib/libnet/bootp.c
index 6d58cef..464cb66 100644
--- a/lib/libnet/bootp.c
+++ b/lib/libnet/bootp.c
@@ -166,7 +166,7 @@ receive_bootp(filename_ip_t * fn_ip)
fn_ip->own_ip = btph->yiaddr;
fn_ip->server_ip = btph->siaddr;
- strcpy((char *) fn_ip->filename, (char *) btph->file);
+ strcpy(fn_ip->filename, (char *)btph->file);
#if DEBUG
printf("\nThese are the details of the bootp reply:\n");
diff --git a/lib/libnet/dhcp.c b/lib/libnet/dhcp.c
index 0cb4fa4..d3e5170 100644
--- a/lib/libnet/dhcp.c
+++ b/lib/libnet/dhcp.c
@@ -124,8 +124,8 @@ typedef struct {
uint32_t subnet_mask; /**< o. 1 Subnet mask */
uint8_t msg_type; /**< o.53 DHCP-message type */
uint8_t overload; /**< o.52 Overload sname/file fields */
- int8_t tftp_server[256]; /**< o.66 TFTP server name */
- int8_t bootfile[256]; /**< o.67 Boot file name */
+ char tftp_server[256]; /**< o.66 TFTP server name */
+ char bootfile[256]; /**< o.67 Boot file name */
uint16_t client_arch; /**< o.93 Client architecture type */
} dhcp_options_t;
@@ -197,7 +197,7 @@ int32_t dhcpv4(char *ret_buffer, filename_ip_t *fn_ip)
dhcp_siaddr_ip = fn_ip->server_ip;
}
if(fn_ip->filename[0] != 0) {
- strcpy(dhcp_filename, (char *) fn_ip->filename);
+ strcpy(dhcp_filename, fn_ip->filename);
}
// TFTP SERVER
@@ -230,7 +230,7 @@ int32_t dhcpv4(char *ret_buffer, filename_ip_t *fn_ip)
// Store configuration info into filename_ip strucutre
fn_ip -> own_ip = dhcp_own_ip;
fn_ip -> server_ip = dhcp_tftp_ip;
- strcpy((char *) fn_ip -> filename, dhcp_filename);
+ strcpy(fn_ip->filename, dhcp_filename);
return 0;
}
@@ -342,14 +342,14 @@ static int32_t dhcp_encode_options(uint8_t * opt_field, dhcp_options_t * opt_str
if (opt_struct -> flag[DHCP_TFTP_SERVER]) {
options[0] = DHCP_TFTP_SERVER;
- options[1] = strlen((char *) opt_struct -> tftp_server) + 1;
+ options[1] = strlen(opt_struct->tftp_server) + 1;
memcpy(options + 2, opt_struct -> tftp_server, options[1]);
options += options[1] + 2;
}
if (opt_struct -> flag[DHCP_BOOTFILE]) {
options[0] = DHCP_BOOTFILE;
- options[1] = strlen((char *) opt_struct -> bootfile) + 1;
+ options[1] = strlen(opt_struct->bootfile) + 1;
memcpy(options + 2, opt_struct -> bootfile, options[1]);
options += options[1] + 2;
}
@@ -716,7 +716,7 @@ void dhcp_send_release(int fd)
btph -> htype = 1;
btph -> hlen = 6;
btph -> xid = dhcp_xid;
- strcpy((char *) btph -> file, "");
+ btph -> file[0] = 0;
memcpy(btph -> chaddr, get_mac_address(), 6);
btph -> ciaddr = htonl(dhcp_own_ip);
@@ -774,13 +774,14 @@ int8_t handle_dhcp(int fd, uint8_t * packet, int32_t packetsize)
dhcp_server_ip = htonl(iph -> ip_src);
if (strlen((char *) btph -> sname) && !dhcp_siaddr_ip) {
- strncpy((char *) dhcp_tftp_name, (char *) btph -> sname,
- sizeof(btph -> sname));
+ strncpy(dhcp_tftp_name, (char *)btph->sname,
+ sizeof(btph->sname));
dhcp_tftp_name[sizeof(btph -> sname)] = 0;
}
if (strlen((char *) btph -> file)) {
- strncpy((char *) dhcp_filename, (char *) btph -> file, sizeof(btph -> file));
+ strncpy(dhcp_filename, (char *)btph->file,
+ sizeof(btph->file));
dhcp_filename[sizeof(btph -> file)] = 0;
}
@@ -845,12 +846,14 @@ int8_t handle_dhcp(int fd, uint8_t * packet, int32_t packetsize)
dhcp_own_ip = htonl(btph -> yiaddr);
dhcp_siaddr_ip = htonl(btph -> siaddr);
if (strlen((char *) btph -> sname) && !dhcp_siaddr_ip) {
- strncpy((char *) dhcp_tftp_name, (char *) btph -> sname, sizeof(btph -> sname));
+ strncpy(dhcp_tftp_name, (char *)btph->sname,
+ sizeof(btph->sname));
dhcp_tftp_name[sizeof(btph -> sname)] = 0;
}
if (strlen((char *) btph -> file)) {
- strncpy((char *) dhcp_filename, (char *) btph -> file, sizeof(btph -> file));
+ strncpy(dhcp_filename, (char *)btph->file,
+ sizeof(btph->file));
dhcp_filename[sizeof(btph -> file)] = 0;
}
@@ -883,14 +886,14 @@ int8_t handle_dhcp(int fd, uint8_t * packet, int32_t packetsize)
dhcp_server_ip = opt.server_ID;
dhcp_siaddr_ip = htonl(btph -> siaddr);
if (opt.flag[DHCP_TFTP_SERVER]) {
- strcpy((char *) dhcp_tftp_name, (char *) opt.tftp_server);
+ strcpy(dhcp_tftp_name, opt.tftp_server);
}
else {
- strcpy((char *) dhcp_tftp_name, "");
+ dhcp_filename[0] = 0;
if ((opt.overload != DHCP_OVERLOAD_SNAME &&
opt.overload != DHCP_OVERLOAD_BOTH) &&
!dhcp_siaddr_ip) {
- strncpy((char *) dhcp_tftp_name,
+ strncpy(dhcp_tftp_name,
(char *) btph->sname,
sizeof(btph -> sname));
dhcp_tftp_name[sizeof(btph->sname)] = 0;
@@ -898,14 +901,14 @@ int8_t handle_dhcp(int fd, uint8_t * packet, int32_t packetsize)
}
if (opt.flag[DHCP_BOOTFILE]) {
- strcpy((char *) dhcp_filename, (char *) opt.bootfile);
+ strcpy(dhcp_filename, opt.bootfile);
}
else {
- strcpy((char *) dhcp_filename, "");
+ dhcp_filename[0] = 0;
if (opt.overload != DHCP_OVERLOAD_FILE &&
- opt.overload != DHCP_OVERLOAD_BOTH &&
- strlen((char *) btph -> file)) {
- strncpy((char *) dhcp_filename,
+ opt.overload != DHCP_OVERLOAD_BOTH &&
+ strlen((char *)btph->file)) {
+ strncpy(dhcp_filename,
(char *) btph->file,
sizeof(btph->file));
dhcp_filename[sizeof(btph -> file)] = 0;
diff --git a/lib/libnet/dhcpv6.c b/lib/libnet/dhcpv6.c
index 491d540..e92fc0f 100644
--- a/lib/libnet/dhcpv6.c
+++ b/lib/libnet/dhcpv6.c
@@ -176,8 +176,7 @@ static void dhcp6_process_options (uint8_t *option, int32_t option_length)
buffer[option_boot_url->length] = 0;
if (parse_tftp_args(buffer,
(char *)my_fn_ip->server_ip6.addr,
- (char *)my_fn_ip->filename,
- (int)my_fn_ip->fd,
+ my_fn_ip->filename, my_fn_ip->fd,
option_boot_url->length) == -1)
return;
break;
diff --git a/lib/libnet/netload.c b/lib/libnet/netload.c
index 74e3464..5c37fe2 100644
--- a/lib/libnet/netload.c
+++ b/lib/libnet/netload.c
@@ -735,7 +735,7 @@ int netload(char *buffer, int len, int huge_load, int block_size,
***********************************************************/
if (obp_tftp_args.filename[0] != 0) {
- strncpy((char *) fn_ip.filename, obp_tftp_args.filename, sizeof(fn_ip.filename)-1);
+ strncpy(fn_ip.filename, obp_tftp_args.filename, sizeof(fn_ip.filename)-1);
fn_ip.filename[sizeof(fn_ip.filename)-1] = 0;
}
diff --git a/lib/libnet/tftp.c b/lib/libnet/tftp.c
index cda8bf3..1656c27 100644
--- a/lib/libnet/tftp.c
+++ b/lib/libnet/tftp.c
@@ -97,7 +97,7 @@ static void send_rrq(int fd)
int ip_len = 0;
int ip6_payload_len = 0;
unsigned short udp_len = 0;
- unsigned char mode[] = "octet";
+ const char mode[] = "octet";
char *ptr = NULL;
struct iphdr *ip = NULL;
struct ip6hdr *ip6 = NULL;
@@ -110,7 +110,7 @@ static void send_rrq(int fd)
ip = (struct iphdr *) packet;
udph = (struct udphdr *) (ip + 1);
ip_len = sizeof(struct iphdr) + sizeof(struct udphdr)
- + strlen((char *) fn_ip->filename) + strlen((char *) mode) + 4
+ + strlen(fn_ip->filename) + strlen(mode) + 4
+ strlen("blksize") + strlen(blocksize_str) + 2;
fill_iphdr ((uint8_t *) ip, ip_len, IPTYPE_UDP, 0,
fn_ip->server_ip);
@@ -119,7 +119,7 @@ static void send_rrq(int fd)
ip6 = (struct ip6hdr *) packet;
udph = (struct udphdr *) (ip6 + 1);
ip6_payload_len = sizeof(struct udphdr)
- + strlen((char *) fn_ip->filename) + strlen((char *) mode) + 4
+ + strlen(fn_ip->filename) + strlen(mode) + 4
+ strlen("blksize") + strlen(blocksize_str) + 2;
ip_len = sizeof(struct ip6hdr) + ip6_payload_len;
fill_ip6hdr ((uint8_t *) ip6, ip6_payload_len, IPTYPE_UDP, get_ipv6_address(),
@@ -127,7 +127,7 @@ static void send_rrq(int fd)
}
udp_len = htons(sizeof(struct udphdr)
- + strlen((char *) fn_ip->filename) + strlen((char *) mode) + 4
+ + strlen(fn_ip->filename) + strlen(mode) + 4
+ strlen("blksize") + strlen(blocksize_str) + 2);
fill_udphdr ((uint8_t *) udph, udp_len, htons(2001), htons(69));
@@ -135,12 +135,12 @@ static void send_rrq(int fd)
tftp->th_opcode = htons(RRQ);
ptr = (char *) &tftp->th_data;
- memcpy(ptr, fn_ip->filename, strlen((char *) fn_ip->filename) + 1);
+ memcpy(ptr, fn_ip->filename, strlen(fn_ip->filename) + 1);
- ptr += strlen((char *) fn_ip->filename) + 1;
- memcpy(ptr, mode, strlen((char *) mode) + 1);
+ ptr += strlen(fn_ip->filename) + 1;
+ memcpy(ptr, mode, strlen(mode) + 1);
- ptr += strlen((char *) mode) + 1;
+ ptr += strlen(mode) + 1;
memcpy(ptr, "blksize", strlen("blksize") + 1);
ptr += strlen("blksize") + 1;
diff --git a/lib/libnet/tftp.h b/lib/libnet/tftp.h
index b1dbc21..e32e473 100644
--- a/lib/libnet/tftp.h
+++ b/lib/libnet/tftp.h
@@ -28,7 +28,7 @@ struct filename_ip {
uint32_t server_ip;
ip6_addr_t server_ip6;
ip6_addr_t dns_ip6;
- int8_t filename[256];
+ char filename[256];
int fd;
} __attribute__ ((packed));
typedef struct filename_ip filename_ip_t;