Skip to content

Commit

Permalink
fixed compilation warning against gcc-4.4
Browse files Browse the repository at this point in the history
* Change arguments of tun_gifindex from:
int tun_gifindex(struct tun_t *this, int *index)
to
int tun_gifindex(struct tun_t *this, __u32 *index)
solves:
../lib/tun.c: In function ‘tun_addaddr’:
../lib/tun.c:265: warning: pointer targets in passing argument 2 of
‘tun_gifindex’ differ in signedness
../lib/tun.c:88: note: expected ‘int *’ but argument is of type ‘__u32
*’

* handle system return code and returns -1 if system failed
solves:
../lib/tun.c: In function ‘tun_runscript’:
../lib/tun.c:895: warning: ignoring return value of ‘system’, declared
with attribute warn_unused_result

* do not dereference a pointer cast and use it as an lvalue
see
http://www.mail-archive.com/[email protected]/msg50931.html
solves:
../lib/tun.c: In function ‘tun_route’:
../lib/tun.c:533: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:533: note: initialized from here
../lib/tun.c:534: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:534: note: initialized from here
../lib/tun.c:535: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:535: note: initialized from here
../lib/tun.c: In function ‘tun_setaddr’:
../lib/tun.c:435: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:435: note: initialized from here
../lib/tun.c:452: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:452: note: initialized from here
../lib/tun.c:465: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:465: note: initialized from here

Signed-off-by: Emmanuel Bretelle <[email protected]>
  • Loading branch information
chantra authored and laf0rge committed Oct 20, 2010
1 parent 91384a4 commit 4e56c83
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int tun_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen)
return 0;
}

int tun_gifindex(struct tun_t *this, int *index) {
int tun_gifindex(struct tun_t *this, __u32 *index) {
struct ifreq ifr;
int fd;

Expand Down Expand Up @@ -432,7 +432,8 @@ int tun_setaddr(struct tun_t *this,

if (addr) { /* Set the interface address */
this->addr.s_addr = addr->s_addr;
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = addr->s_addr;
memcpy(&((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr, addr,
sizeof(*addr));
if (ioctl(fd, SIOCSIFADDR, (void *) &ifr) < 0) {
if (errno != EEXIST) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
Expand All @@ -449,8 +450,8 @@ int tun_setaddr(struct tun_t *this,

if (dstaddr) { /* Set the destination address */
this->dstaddr.s_addr = dstaddr->s_addr;
((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr =
dstaddr->s_addr;
memcpy(&((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr,
dstaddr, sizeof(*dstaddr));
if (ioctl(fd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno,
"ioctl(SIOCSIFDSTADDR) failed");
Expand All @@ -462,8 +463,8 @@ int tun_setaddr(struct tun_t *this,
if (netmask) { /* Set the netmask */
this->netmask.s_addr = netmask->s_addr;
#if defined(__linux__)
((struct sockaddr_in *) &ifr.ifr_netmask)->sin_addr.s_addr =
netmask->s_addr;
memcpy(&((struct sockaddr_in *) &ifr.ifr_netmask)->sin_addr,
netmask, sizeof(*netmask));

#elif defined(__FreeBSD__) || defined (__APPLE__)
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr =
Expand Down Expand Up @@ -530,9 +531,11 @@ int tun_route(struct tun_t *this,
r.rt_dst.sa_family = AF_INET;
r.rt_gateway.sa_family = AF_INET;
r.rt_genmask.sa_family = AF_INET;
((struct sockaddr_in *) &r.rt_dst)->sin_addr.s_addr = dst->s_addr;
((struct sockaddr_in *) &r.rt_gateway)->sin_addr.s_addr = gateway->s_addr;
((struct sockaddr_in *) &r.rt_genmask)->sin_addr.s_addr = mask->s_addr;
memcpy(&((struct sockaddr_in *) &r.rt_dst)->sin_addr, dst, sizeof(*dst));
memcpy(&((struct sockaddr_in *) &r.rt_gateway)->sin_addr, gateway,
sizeof(*gateway));
memcpy(&((struct sockaddr_in *) &r.rt_genmask)->sin_addr, mask,
sizeof(*mask));

if (delete) {
if (ioctl(fd, SIOCDELRT, (void *) &r) < 0) {
Expand Down Expand Up @@ -882,6 +885,7 @@ int tun_runscript(struct tun_t *tun, char* script) {
char buf[TUN_SCRIPTSIZE];
char snet[TUN_ADDRSIZE];
char smask[TUN_ADDRSIZE];
int rc;

strncpy(snet, inet_ntoa(tun->addr), sizeof(snet));
snet[sizeof(snet)-1] = 0;
Expand All @@ -892,6 +896,11 @@ int tun_runscript(struct tun_t *tun, char* script) {
snprintf(buf, sizeof(buf), "%s %s %s %s",
script, tun->devname, snet, smask);
buf[sizeof(buf)-1] = 0;
system(buf);
rc = system(buf);
if (rc == -1) {
sys_err(LOG_ERR, __FILE__, __LINE__, errno, "Error executing command %s",
buf);
return -1;
}
return 0;
}

0 comments on commit 4e56c83

Please sign in to comment.