From patchwork Wed May 9 11:12:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 910759 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40gtxb5RVVz9s3q for ; Wed, 9 May 2018 21:12:51 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40gtxb3ypyzF2Ms for ; Wed, 9 May 2018 21:12:51 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=redhat.com (client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=thuth@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40gtxW5RfGzF2MQ for ; Wed, 9 May 2018 21:12:44 +1000 (AEST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46A884270959 for ; Wed, 9 May 2018 11:12:42 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-117-98.ams2.redhat.com [10.36.117.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2665D1EA7 for ; Wed, 9 May 2018 11:12:41 +0000 (UTC) From: Thomas Huth To: slof@lists.ozlabs.org Date: Wed, 9 May 2018 13:12:40 +0200 Message-Id: <1525864360-13659-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 09 May 2018 11:12:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 09 May 2018 11:12:42 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' Subject: [SLOF] [PATCH] libnet: Get rid of unnecessary (char *) casts X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" 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 --- lib/libnet/tftp.h | 2 +- lib/libnet/bootp.c | 2 +- lib/libnet/dhcp.c | 43 +++++++++++++++++++++++-------------------- lib/libnet/dhcpv6.c | 3 +-- lib/libnet/netload.c | 2 +- lib/libnet/tftp.c | 16 ++++++++-------- 6 files changed, 35 insertions(+), 33 deletions(-) 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; 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;