pud: remove some strlen's in nettools
authorFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 2 Oct 2013 12:40:25 +0000 (14:40 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Wed, 2 Oct 2013 13:44:42 +0000 (15:44 +0200)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/netTools.c

index b5c6812..f4acb7e 100644 (file)
 unsigned char * getHardwareAddress(const char * ifName, int family,
                struct ifreq *ifr) {
        int fd;
-       int cpySize;
 
        assert(ifName != NULL);
-       assert(strlen(ifName) <= IFNAMSIZ);
+       assert(strlen(ifName) <= sizeof(ifr->ifr_name));
        assert((family == AF_INET) || (family == AF_INET6));
        assert(ifr != NULL);
 
@@ -42,9 +41,7 @@ unsigned char * getHardwareAddress(const char * ifName, int family,
 
        ifr->ifr_addr.sa_family = family;
        memset(ifr->ifr_name, 0, sizeof(ifr->ifr_name));
-       cpySize = (strlen(ifName) < sizeof(ifr->ifr_name)) ? strlen(ifName)
-                       : sizeof(ifr->ifr_name);
-       strncpy(ifr->ifr_name, ifName, cpySize);
+       strncpy(ifr->ifr_name, ifName, sizeof(ifr->ifr_name));
 
        errno = 0;
        if (ioctl(fd, SIOCGIFHWADDR, ifr) < 0) {
@@ -72,10 +69,9 @@ unsigned char * getHardwareAddress(const char * ifName, int family,
  */
 struct in_addr * getIPv4Address(const char * ifName, struct ifreq *ifr) {
        int fd;
-       int cpySize;
 
        assert(ifName != NULL);
-       assert(strlen(ifName) <= IFNAMSIZ);
+       assert(strlen(ifName) <= sizeof(ifr->ifr_name));
        assert(ifr != NULL);
 
        fd = socket(AF_INET, SOCK_DGRAM, 0);
@@ -86,9 +82,7 @@ struct in_addr * getIPv4Address(const char * ifName, struct ifreq *ifr) {
 
        ifr->ifr_addr.sa_family = AF_INET;
        memset(ifr->ifr_name, 0, sizeof(ifr->ifr_name));
-       cpySize = (strlen(ifName) < sizeof(ifr->ifr_name)) ? strlen(ifName)
-                       : sizeof(ifr->ifr_name);
-       strncpy(ifr->ifr_name, ifName, cpySize);
+       strncpy(ifr->ifr_name, ifName, sizeof(ifr->ifr_name));
 
        errno = 0;
        if (ioctl(fd, SIOCGIFADDR, ifr) < 0) {