snmp.c (310910) | snmp.c (311603) |
---|---|
1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Author: Harti Brandt <harti@freebsd.org> 7 * 8 * Copyright (c) 2010 The FreeBSD Foundation --- 37 unchanged lines hidden (view full) --- 46#include <stddef.h> 47#include <stdarg.h> 48#include <string.h> 49#ifdef HAVE_STDINT_H 50#include <stdint.h> 51#elif defined(HAVE_INTTYPES_H) 52#include <inttypes.h> 53#endif | 1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Author: Harti Brandt <harti@freebsd.org> 7 * 8 * Copyright (c) 2010 The FreeBSD Foundation --- 37 unchanged lines hidden (view full) --- 46#include <stddef.h> 47#include <stdarg.h> 48#include <string.h> 49#ifdef HAVE_STDINT_H 50#include <stdint.h> 51#elif defined(HAVE_INTTYPES_H) 52#include <inttypes.h> 53#endif |
54#include <netinet/in.h> 55#include <arpa/inet.h> |
|
54 55#include "asn1.h" 56#include "snmp.h" 57#include "snmppriv.h" 58 59static void snmp_error_func(const char *, ...); 60static void snmp_printf_func(const char *, ...); 61 --- 1317 unchanged lines hidden (view full) --- 1379 str++; 1380 } 1381 return (0); 1382 } 1383 1384 case SNMP_SYNTAX_IPADDRESS: 1385 { 1386 struct hostent *he; | 56 57#include "asn1.h" 58#include "snmp.h" 59#include "snmppriv.h" 60 61static void snmp_error_func(const char *, ...); 62static void snmp_printf_func(const char *, ...); 63 --- 1317 unchanged lines hidden (view full) --- 1381 str++; 1382 } 1383 return (0); 1384 } 1385 1386 case SNMP_SYNTAX_IPADDRESS: 1387 { 1388 struct hostent *he; |
1387 u_long ip[4]; 1388 int n; | |
1389 | 1389 |
1390 if (sscanf(str, "%lu.%lu.%lu.%lu%n", &ip[0], &ip[1], &ip[2], 1391 &ip[3], &n) == 4 && (size_t)n == strlen(str) && 1392 ip[0] <= 0xff && ip[1] <= 0xff && 1393 ip[2] <= 0xff && ip[3] <= 0xff) { 1394 v->ipaddress[0] = (u_char)ip[0]; 1395 v->ipaddress[1] = (u_char)ip[1]; 1396 v->ipaddress[2] = (u_char)ip[2]; 1397 v->ipaddress[3] = (u_char)ip[3]; | 1390 if (inet_pton(AF_INET, str, &v->ipaddress) == 1) |
1398 return (0); | 1391 return (0); |
1399 } 1400 1401 if ((he = gethostbyname(str)) == NULL) | 1392 if ((he = gethostbyname2(str, AF_INET)) == NULL) |
1402 return (-1); 1403 if (he->h_addrtype != AF_INET) 1404 return (-1); 1405 | 1393 return (-1); 1394 if (he->h_addrtype != AF_INET) 1395 return (-1); 1396 |
1406 v->ipaddress[0] = he->h_addr[0]; 1407 v->ipaddress[1] = he->h_addr[1]; 1408 v->ipaddress[2] = he->h_addr[2]; 1409 v->ipaddress[3] = he->h_addr[3]; | 1397 memcpy(v->ipaddress, he->h_addr, sizeof(v->ipaddress)); 1398 |
1410 return (0); 1411 } 1412 1413 case SNMP_SYNTAX_COUNTER: 1414 case SNMP_SYNTAX_GAUGE: 1415 case SNMP_SYNTAX_TIMETICKS: 1416 { 1417 uint64_t sub; --- 38 unchanged lines hidden --- | 1399 return (0); 1400 } 1401 1402 case SNMP_SYNTAX_COUNTER: 1403 case SNMP_SYNTAX_GAUGE: 1404 case SNMP_SYNTAX_TIMETICKS: 1405 { 1406 uint64_t sub; --- 38 unchanged lines hidden --- |