summaryrefslogtreecommitdiff
path: root/proto_ipv4.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2016-12-08 16:05:58 +0100
committerTobias Klauser <tklauser@distanz.ch>2016-12-08 16:05:58 +0100
commit51e487b4b55a69581f2d27cbf148ff98c173eaf7 (patch)
tree4ba19f41b044df39ed4586ee82c377abe50f5813 /proto_ipv4.c
parentf474c5031e5b8c5833342a504c6e33941a5103f0 (diff)
netsniff-ng: proto_ipv4: Move sockaddr_in declarations to narrower scope
Move the sockaddr_in definitions and preparations to the scope where they're used, i.e. only if geoip is enabled and working. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'proto_ipv4.c')
-rw-r--r--proto_ipv4.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/proto_ipv4.c b/proto_ipv4.c
index 9b9e915..edce915 100644
--- a/proto_ipv4.c
+++ b/proto_ipv4.c
@@ -40,7 +40,6 @@ static void ipv4(struct pkt_buff *pkt)
uint8_t *opt, *trailer;
unsigned int trailer_len = 0;
ssize_t opts_len, opt_len;
- struct sockaddr_in sas, sad;
const char *city, *region, *country;
if (!ip)
@@ -88,15 +87,17 @@ static void ipv4(struct pkt_buff *pkt)
csum_expected(ip->h_check, csum), colorize_end());
tprintf(" ]\n");
- memset(&sas, 0, sizeof(sas));
- sas.sin_family = PF_INET;
- sas.sin_addr.s_addr = ip->h_saddr;
+ if (geoip_working()) {
+ struct sockaddr_in sas, sad;
- memset(&sad, 0, sizeof(sad));
- sad.sin_family = PF_INET;
- sad.sin_addr.s_addr = ip->h_daddr;
+ memset(&sas, 0, sizeof(sas));
+ sas.sin_family = PF_INET;
+ sas.sin_addr.s_addr = ip->h_saddr;
+
+ memset(&sad, 0, sizeof(sad));
+ sad.sin_family = PF_INET;
+ sad.sin_addr.s_addr = ip->h_daddr;
- if (geoip_working()) {
tprintf("\t[ Geo (");
if ((country = geoip4_country_name(&sas))) {
tprintf("%s", country);