Replaced inet_addr() with inet_pton.

master
Fabian Eckermann 3 years ago committed by Fabian Eckermann
parent 5d051d8832
commit dd8db1a929

@ -49,9 +49,11 @@ uint32_t mac_pcap_net::open(std::string client_ip_addr_,
client_udp_port_,
bind_addr_str.c_str(),
bind_udp_port_);
client_addr.sin_family = AF_INET;
client_addr.sin_addr.s_addr = inet_addr(client_ip_addr_.c_str());
client_addr.sin_port = htons(client_udp_port_);
if (not net_utils::set_sockaddr(&client_addr, client_ip_addr_.c_str(), client_udp_port_)) {
logger.error("Invalid client_ip_addr: %s", client_ip_addr_.c_str());
return SRSRAN_ERROR;
}
running = true;
ue_id = ue_id_;
// start writer thread

@ -30,7 +30,7 @@ int srsran_netsink_init(srsran_netsink_t* q, const char* address, uint16_t port,
q->sockfd = socket(AF_INET, type == SRSRAN_NETSINK_TCP ? SOCK_STREAM : SOCK_DGRAM, 0);
if (q->sockfd < 0) {
perror("socket");
return -1;
return SRSRAN_ERROR;
}
int enable = 1;
@ -44,12 +44,15 @@ int srsran_netsink_init(srsran_netsink_t* q, const char* address, uint16_t port,
#endif
q->servaddr.sin_family = AF_INET;
q->servaddr.sin_addr.s_addr = inet_addr(address);
if (inet_pton(q->servaddr.sin_family, address, &q->servaddr.sin_addr) != 1) {
perror("inet_pton");
return SRSRAN_ERROR;
}
q->servaddr.sin_port = htons(port);
q->connected = false;
q->type = type;
return 0;
return SRSRAN_SUCCESS;
}
void srsran_netsink_free(srsran_netsink_t* q)
@ -64,9 +67,9 @@ int srsran_netsink_set_nonblocking(srsran_netsink_t* q)
{
if (fcntl(q->sockfd, F_SETFL, O_NONBLOCK)) {
perror("fcntl");
return -1;
return SRSRAN_ERROR;
}
return 0;
return SRSRAN_SUCCESS;
}
int srsran_netsink_write(srsran_netsink_t* q, void* buffer, int nof_bytes)
@ -74,11 +77,11 @@ int srsran_netsink_write(srsran_netsink_t* q, void* buffer, int nof_bytes)
if (!q->connected) {
if (connect(q->sockfd, &q->servaddr, sizeof(q->servaddr)) < 0) {
if (errno == ECONNREFUSED || errno == EINPROGRESS) {
return 0;
return SRSRAN_SUCCESS;
} else {
perror("connect");
exit(-1);
return -1;
return SRSRAN_ERROR;
}
} else {
q->connected = true;
@ -93,10 +96,10 @@ int srsran_netsink_write(srsran_netsink_t* q, void* buffer, int nof_bytes)
q->sockfd = socket(AF_INET, q->type == SRSRAN_NETSINK_TCP ? SOCK_STREAM : SOCK_DGRAM, 0);
if (q->sockfd < 0) {
perror("socket");
return -1;
return SRSRAN_ERROR;
}
q->connected = false;
return 0;
return SRSRAN_SUCCESS;
}
}
}

@ -30,7 +30,7 @@ int srsran_netsource_init(srsran_netsource_t* q, const char* address, uint16_t p
if (q->sockfd < 0) {
perror("socket");
return -1;
return SRSRAN_ERROR;
}
// Make sockets reusable
@ -46,16 +46,19 @@ int srsran_netsource_init(srsran_netsource_t* q, const char* address, uint16_t p
q->type = type;
q->servaddr.sin_family = AF_INET;
q->servaddr.sin_addr.s_addr = inet_addr(address);
if (inet_pton(q->servaddr.sin_family, address, &q->servaddr.sin_addr) != 1) {
perror("inet_pton");
return SRSRAN_ERROR;
}
q->servaddr.sin_port = htons(port);
if (bind(q->sockfd, (struct sockaddr*)&q->servaddr, sizeof(struct sockaddr_in))) {
perror("bind");
return -1;
return SRSRAN_ERROR;
}
q->connfd = 0;
return 0;
return SRSRAN_SUCCESS;
}
void srsran_netsource_free(srsran_netsource_t* q)
@ -73,9 +76,9 @@ int srsran_netsource_read(srsran_netsource_t* q, void* buffer, int nbytes)
if (n == -1) {
if (errno == EAGAIN) {
return 0;
return SRSRAN_SUCCESS;
} else {
return -1;
return SRSRAN_ERROR;
}
} else {
return n;
@ -88,7 +91,7 @@ int srsran_netsource_read(srsran_netsource_t* q, void* buffer, int nbytes)
q->connfd = accept(q->sockfd, (struct sockaddr*)&q->cliaddr, &clilen);
if (q->connfd < 0) {
perror("accept");
return -1;
return SRSRAN_ERROR;
}
}
int n = read(q->connfd, buffer, nbytes);
@ -96,7 +99,7 @@ int srsran_netsource_read(srsran_netsource_t* q, void* buffer, int nbytes)
printf("Connection closed\n");
close(q->connfd);
q->connfd = 0;
return 0;
return SRSRAN_SUCCESS;
}
if (n == -1) {
perror("read");
@ -127,7 +130,7 @@ int srsran_netsource_set_nonblocking(srsran_netsource_t* q)
perror("fcntl");
return -1;
}
return 0;
return SRSRAN_SUCCESS;
}
int srsran_netsource_set_timeout(srsran_netsource_t* q, uint32_t microseconds)
@ -137,7 +140,7 @@ int srsran_netsource_set_timeout(srsran_netsource_t* q, uint32_t microseconds)
t.tv_usec = microseconds;
if (setsockopt(q->sockfd, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(struct timeval))) {
perror("setsockopt");
return -1;
return SRSRAN_ERROR;
}
return 0;
return SRSRAN_SUCCESS;
}

@ -52,7 +52,10 @@ asn1::bounded_bitstring<1, 160, true, true> addr_to_asn1(const char* addr_str)
{
asn1::bounded_bitstring<1, 160, true, true> transport_layer_addr(32);
uint8_t addr[4];
inet_pton(AF_INET, addr_str, addr);
if (inet_pton(AF_INET, addr_str, addr) != 1) {
srsran::console("Invalid addr_str: %s\n", addr_str);
perror("inet_pton");
}
for (uint32_t j = 0; j < 4; ++j) {
transport_layer_addr.data()[j] = addr[3 - j];
}
@ -1726,9 +1729,17 @@ void s1ap::ue::get_erab_addr(uint16_t erab_id, transp_addr_t& transp_addr, asn1:
transp_addr.resize(32);
uint8_t addr[4];
if (!s1ap_ptr->args.gtp_advertise_addr.empty()) {
inet_pton(AF_INET, s1ap_ptr->args.gtp_advertise_addr.c_str(), addr);
if (inet_pton(AF_INET, s1ap_ptr->args.gtp_advertise_addr.c_str(), addr) != 1) {
logger.error("Invalid gtp_advertise_addr: %s", s1ap_ptr->args.gtp_advertise_addr.c_str());
srsran::console("Invalid gtp_advertise_addr: %s\n", s1ap_ptr->args.gtp_advertise_addr.c_str());
perror("inet_pton");
}
} else {
inet_pton(AF_INET, s1ap_ptr->args.gtp_bind_addr.c_str(), addr);
if (inet_pton(AF_INET, s1ap_ptr->args.gtp_bind_addr.c_str(), addr) != 1) {
logger.error("Invalid gtp_bind_addr: %s", s1ap_ptr->args.gtp_bind_addr.c_str());
srsran::console("Invalid gtp_bind_addr: %s\n", s1ap_ptr->args.gtp_bind_addr.c_str());
perror("inet_pton");
}
}
for (uint32_t j = 0; j < 4; ++j) {
transp_addr.data()[j] = addr[3 - j];

@ -394,13 +394,9 @@ int gtpu::init(const gtpu_args_t& gtpu_args, pdcp_interface_gtpu* pdcp_)
struct sockaddr_in bindaddr;
bzero(&bindaddr, sizeof(struct sockaddr_in));
bindaddr.sin_family = AF_INET;
bindaddr.sin_addr.s_addr = inet_addr(gtp_bind_addr.c_str());
bindaddr.sin_port = htons(GTPU_PORT);
if (bind(fd, (struct sockaddr*)&bindaddr, sizeof(struct sockaddr_in))) {
// Bind socket
if (not net_utils::bind_addr(fd, gtp_bind_addr.c_str(), GTPU_PORT, &bindaddr)) {
snprintf(errbuf, sizeof(errbuf), "%s", strerror(errno));
logger.error("Failed to bind on address %s, port %d: %s", gtp_bind_addr.c_str(), int(GTPU_PORT), errbuf);
srsran::console("Failed to bind on address %s, port %d: %s\n", gtp_bind_addr.c_str(), int(GTPU_PORT), errbuf);
return SRSRAN_ERROR;
}
@ -925,8 +921,20 @@ bool gtpu::m1u_handler::init(std::string m1u_multiaddr_, std::string m1u_if_addr
/* Send an ADD MEMBERSHIP message via setsockopt */
struct ip_mreq mreq {};
mreq.imr_multiaddr.s_addr = inet_addr(m1u_multiaddr.c_str()); // Multicast address of the service
mreq.imr_interface.s_addr = inet_addr(m1u_if_addr.c_str()); // Address of the IF the socket will listen to.
// Multicast address of the service
if (inet_pton(AF_INET, m1u_multiaddr.c_str(), &mreq.imr_multiaddr) != 1) {
logger.error("Invalid m1u_multiaddr: %s", m1u_multiaddr.c_str());
srsran::console("Invalid m1u_multiaddr: %s\n", m1u_multiaddr.c_str());
perror("inet_pton");
return false;
}
// Address of the IF the socket will listen to.
if (inet_pton(AF_INET, m1u_if_addr.c_str(), &mreq.imr_interface) != 1) {
logger.error("Invalid m1u_if_addr: %s", m1u_if_addr.c_str());
srsran::console("Invalid m1u_if_addr: %s\n", m1u_if_addr.c_str());
perror("inet_pton");
return false;
}
if (setsockopt(m1u_sd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
logger.error("Register musticast group for M1-U");
logger.error("M1-U infterface IP: %s, M1-U Multicast Address %s", m1u_if_addr.c_str(), m1u_multiaddr.c_str());

@ -12,6 +12,7 @@
#include "srsepc/hdr/mbms-gw/mbms-gw.h"
#include "srsran/common/standard_streams.h"
#include "srsran/common/network_utils.h"
#include "srsran/upper/gtpu.h"
#include <algorithm>
#include <fcntl.h>
@ -152,9 +153,12 @@ int mbms_gw::init_sgi_mb_if(mbms_gw_args_t* args)
// Set IP of the interface
struct sockaddr_in* addr = (struct sockaddr_in*)&ifr.ifr_addr;
addr->sin_family = AF_INET;
addr->sin_addr.s_addr = inet_addr(args->sgi_mb_if_addr.c_str());
addr->sin_port = 0;
if (not srsran::net_utils::set_sockaddr(addr, args->sgi_mb_if_addr.c_str(), 0)) {
m_logger.error("Invalid sgi_mb_if_addr: %s", args->sgi_mb_if_addr.c_str());
srsran::console("Invalid sgi_mb_if_addr: %s\n", args->sgi_mb_if_addr.c_str());
return SRSRAN_ERROR_CANT_START;
}
if (ioctl(sgi_mb_sock, SIOCSIFADDR, &ifr) < 0) {
m_logger.error(
@ -165,7 +169,12 @@ int mbms_gw::init_sgi_mb_if(mbms_gw_args_t* args)
}
ifr.ifr_netmask.sa_family = AF_INET;
((struct sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr(args->sgi_mb_if_mask.c_str());
if (inet_pton(ifr.ifr_netmask.sa_family, args->sgi_mb_if_mask.c_str(), &((struct sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr ) != 1) {
m_logger.error("Invalid sgi_mb_if_mask: %s", args->sgi_mb_if_mask.c_str());
srsran::console("Invalid sgi_mb_if_mask: %s\n", args->sgi_mb_if_mask.c_str());
perror("inet_pton");
return SRSRAN_ERROR_CANT_START;
}
if (ioctl(sgi_mb_sock, SIOCSIFNETMASK, &ifr) < 0) {
m_logger.error("Failed to set TUN interface Netmask. Error: %s", strerror(errno));
close(m_sgi_mb_if);
@ -201,7 +210,12 @@ int mbms_gw::init_m1_u(mbms_gw_args_t* args)
/* Set local interface for outbound multicast packets*/
/* The IP must be associated with a local multicast capable interface */
struct in_addr local_if;
local_if.s_addr = inet_addr(args->m1u_multi_if.c_str());
if (inet_pton(AF_INET, args->m1u_multi_if.c_str(), &local_if.s_addr) != 1) {
m_logger.error("Invalid m1u_multi_if: %s", args->m1u_multi_if.c_str());
srsran::console("Invalid m1u_multi_if: %s\n", args->m1u_multi_if.c_str());
perror("inet_pton");
return SRSRAN_ERROR_CANT_START;
}
if (setsockopt(m_m1u, IPPROTO_IP, IP_MULTICAST_IF, (char*)&local_if, sizeof(struct in_addr)) < 0) {
m_logger.error("Error %s setting multicast interface %s.", strerror(errno), args->m1u_multi_if.c_str());
return SRSRAN_ERROR_CANT_START;
@ -218,7 +232,12 @@ int mbms_gw::init_m1_u(mbms_gw_args_t* args)
bzero(&m_m1u_multi_addr, sizeof(m_m1u_multi_addr));
m_m1u_multi_addr.sin_family = AF_INET;
m_m1u_multi_addr.sin_port = htons(GTPU_RX_PORT + 1);
m_m1u_multi_addr.sin_addr.s_addr = inet_addr(args->m1u_multi_addr.c_str());
if (inet_pton(m_m1u_multi_addr.sin_family, args->m1u_multi_addr.c_str(), &m_m1u_multi_addr.sin_addr.s_addr) != 1) {
m_logger.error("Invalid m1u_multi_addr: %s", args->m1u_multi_addr.c_str());
srsran::console("Invalid m1u_multi_addr: %s\n", args->m1u_multi_addr.c_str());
perror("inet_pton");
return SRSRAN_ERROR_CANT_START;
}
m_logger.info("Initialized M1-U");
return SRSRAN_SUCCESS;

@ -1538,7 +1538,12 @@ bool nas::pack_attach_accept(srsran::byte_buffer_t* nas_buffer)
act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].len = 4;
struct sockaddr_in dns_addr;
inet_pton(AF_INET, m_dns.c_str(), &(dns_addr.sin_addr));
if (inet_pton(AF_INET, m_dns.c_str(), &(dns_addr.sin_addr)) != 1) {
m_logger.error("Invalid m_dns: %s", m_dns.c_str());
srsran::console("Invalid m_dns: %s\n", m_dns.c_str());
perror("inet_pton");
return false;
}
memcpy(act_def_eps_bearer_context_req.protocol_cnfg_opts.opt[0].contents, &dns_addr.sin_addr.s_addr, 4);
// Make sure all unused options are set to false

@ -14,6 +14,7 @@
#include "srsran/asn1/gtpc.h"
#include "srsran/common/bcd_helpers.h"
#include "srsran/common/liblte_security.h"
#include "srsran/common/network_utils.h"
#include <cmath>
#include <inttypes.h> // for printing uint64_t
#include <random>
@ -86,7 +87,7 @@ int s1ap::init(const s1ap_args_t& s1ap_args)
m_pcap.open(s1ap_args.pcap_filename.c_str());
}
m_logger.info("S1AP Initialized");
return 0;
return SRSRAN_SUCCESS;
}
void s1ap::stop()
@ -143,7 +144,7 @@ int s1ap::enb_listen()
sock_fd = socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
if (sock_fd == -1) {
srsran::console("Could not create SCTP socket\n");
return -1;
return SRSRAN_ERROR;
}
// Sets the data_io_event to be able to use sendrecv_info
@ -154,20 +155,21 @@ int s1ap::enb_listen()
if (setsockopt(sock_fd, IPPROTO_SCTP, SCTP_EVENTS, &evnts, sizeof(evnts))) {
close(sock_fd);
srsran::console("Subscribing to sctp_data_io_events failed\n");
return -1;
return SRSRAN_ERROR;
}
// S1-MME bind
bzero(&s1mme_addr, sizeof(s1mme_addr));
s1mme_addr.sin_family = AF_INET;
inet_pton(AF_INET, m_s1ap_args.mme_bind_addr.c_str(), &(s1mme_addr.sin_addr));
s1mme_addr.sin_port = htons(S1MME_PORT);
err = bind(sock_fd, (struct sockaddr*)&s1mme_addr, sizeof(s1mme_addr));
if (err != 0) {
if (not srsran::net_utils::set_sockaddr(&s1mme_addr, m_s1ap_args.mme_bind_addr.c_str(), S1MME_PORT)) {
m_logger.error("Invalid mme_bind_addr: %s", m_s1ap_args.mme_bind_addr.c_str());
srsran::console("Invalid mme_bind_addr: %s\n", m_s1ap_args.mme_bind_addr.c_str());
return SRSRAN_ERROR;
}
if (not srsran::net_utils::bind_addr(sock_fd, s1mme_addr)) {
close(sock_fd);
m_logger.error("Error binding SCTP socket");
srsran::console("Error binding SCTP socket\n");
return -1;
return SRSRAN_ERROR;
}
// Listen for connections
@ -176,7 +178,7 @@ int s1ap::enb_listen()
close(sock_fd);
m_logger.error("Error in SCTP socket listen");
srsran::console("Error in SCTP socket listen\n");
return -1;
return SRSRAN_ERROR;
}
return sock_fd;
@ -556,7 +558,7 @@ uint64_t s1ap::find_imsi_from_m_tmsi(uint32_t m_tmsi)
return it->second;
} else {
m_logger.debug("Could not find IMSI from M-TMSI 0x%x", m_tmsi);
return 0;
return SRSRAN_SUCCESS;
}
}

@ -541,7 +541,10 @@ int spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::map<std::string, uint64
// load our imsi to ip lookup table
for (std::map<std::string, uint64_t>::const_iterator iter = ip_to_imsi.begin(); iter != ip_to_imsi.end(); ++iter) {
struct in_addr in_addr;
in_addr.s_addr = inet_addr(iter->first.c_str());
if (inet_pton(AF_INET, iter->first.c_str(), &in_addr.s_addr) != 1) {
perror("inet_pton");
return SRSRAN_ERROR;
}
if (!m_imsi_to_ip.insert(std::make_pair(iter->second, in_addr)).second) {
m_logger.error(
"SPGW: duplicate imsi %015" PRIu64 " for static ip address %s.", iter->second, iter->first.c_str());
@ -553,7 +556,13 @@ int spgw::gtpc::init_ue_ip(spgw_args_t* args, const std::map<std::string, uint64
// first address is allocated to the epc tun interface, start w/next addr
for (uint32_t n = 1; n < 254; ++n) {
struct in_addr ue_addr;
ue_addr.s_addr = inet_addr(args->sgi_if_addr.c_str()) + htonl(n);
if (inet_pton(AF_INET, args->sgi_if_addr.c_str(), &ue_addr.s_addr) != 1) {
m_logger.error("Invalid sgi_if_addr: %s", args->sgi_if_addr.c_str());
srsran::console("Invalid sgi_if_addr: %s\n", args->sgi_if_addr.c_str());
perror("inet_pton");
return SRSRAN_ERROR;
}
ue_addr.s_addr = ue_addr.s_addr + htonl(n);
std::map<std::string, uint64_t>::const_iterator iter = ip_to_imsi.find(inet_ntoa(ue_addr));
if (iter != ip_to_imsi.end()) {

@ -13,6 +13,7 @@
#include "srsepc/hdr/spgw/gtpu.h"
#include "srsepc/hdr/mme/mme_gtpc.h"
#include "srsran/common/string_helpers.h"
#include "srsran/common/network_utils.h"
#include "srsran/upper/gtpu.h"
#include <algorithm>
#include <arpa/inet.h>
@ -131,9 +132,11 @@ int spgw::gtpu::init_sgi(spgw_args_t* args)
// Set IP of the interface
struct sockaddr_in* addr = (struct sockaddr_in*)&ifr.ifr_addr;
addr->sin_family = AF_INET;
addr->sin_addr.s_addr = inet_addr(args->sgi_if_addr.c_str());
addr->sin_port = 0;
if (not srsran::net_utils::set_sockaddr(addr, args->sgi_if_addr.c_str(), 0)) {
m_logger.error("Invalid sgi_if_addr: %s", args->sgi_if_addr.c_str());
srsran::console("Invalid sgi_if_addr: %s\n", args->sgi_if_addr.c_str());
return SRSRAN_ERROR_CANT_START;
}
if (ioctl(sgi_sock, SIOCSIFADDR, &ifr) < 0) {
m_logger.error(
@ -143,8 +146,11 @@ int spgw::gtpu::init_sgi(spgw_args_t* args)
return SRSRAN_ERROR_CANT_START;
}
ifr.ifr_netmask.sa_family = AF_INET;
((struct sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr("255.255.255.0");
ifr.ifr_netmask.sa_family = AF_INET;
if (inet_pton(ifr.ifr_netmask.sa_family , "255.255.255.0", &((struct sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr) != 1) {
perror("inet_pton");
return false;
}
if (ioctl(sgi_sock, SIOCSIFNETMASK, &ifr) < 0) {
m_logger.error("Failed to set TUN interface Netmask. Error: %s", strerror(errno));
close(m_sgi);
@ -170,7 +176,11 @@ int spgw::gtpu::init_s1u(spgw_args_t* args)
// Bind the socket
m_s1u_addr.sin_family = AF_INET;
m_s1u_addr.sin_addr.s_addr = inet_addr(args->gtpu_bind_addr.c_str());
if (inet_pton(m_s1u_addr.sin_family, args->gtpu_bind_addr.c_str(), &m_s1u_addr.sin_addr.s_addr) != 1) {
m_logger.error("Invalid gtpu_bind_addr: %s", args->gtpu_bind_addr.c_str());
srsran::console("Invalid gtpu_bind_addr: %s\n", args->gtpu_bind_addr.c_str());
return SRSRAN_ERROR_CANT_START;
}
m_s1u_addr.sin_port = htons(GTPU_RX_PORT);
if (bind(m_s1u, (struct sockaddr*)&m_s1u_addr, sizeof(struct sockaddr_in))) {

@ -111,7 +111,12 @@ bool ue_stack_nr::switch_on()
{
// statically setup TUN (will be done through RRC later)
char* err_str = nullptr;
if (gw->setup_if_addr(5, LIBLTE_MME_PDN_TYPE_IPV4, htonl(inet_addr("192.168.1.3")), nullptr, err_str)) {
struct in_addr in_addr;
if (inet_pton(AF_INET, "192.168.1.3", &in_addr.s_addr) != 1) {
perror("inet_pton");
return false;
}
if (gw->setup_if_addr(5, LIBLTE_MME_PDN_TYPE_IPV4, htonl(in_addr.s_addr), nullptr, err_str)) {
printf("Error configuring TUN interface\n");
}
return true;

@ -53,8 +53,11 @@ int gw::init(const gw_args_t& args_, stack_interface_gw* stack_)
return SRSRAN_ERROR;
}
mbsfn_sock_addr.sin_family = AF_INET;
mbsfn_sock_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
mbsfn_sock_addr.sin_family = AF_INET;
if (inet_pton(mbsfn_sock_addr.sin_family, "127.0.0.1", &mbsfn_sock_addr.sin_addr.s_addr) != 1) {
perror("inet_pton");
return false;
}
return SRSRAN_SUCCESS;
}
@ -453,8 +456,13 @@ int gw::setup_if_addr4(uint32_t ip_addr, char* err_str)
close(tun_fd);
return SRSRAN_ERROR_CANT_START;
}
ifr.ifr_netmask.sa_family = AF_INET;
((struct sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr(args.tun_dev_netmask.c_str());
ifr.ifr_netmask.sa_family = AF_INET;
if (inet_pton(ifr.ifr_netmask.sa_family, args.tun_dev_netmask.c_str(), &((struct sockaddr_in*)&ifr.ifr_netmask)->sin_addr.s_addr) != 1) {
logger.error("Invalid tun_dev_netmask: %s", args.tun_dev_netmask.c_str());
srsran::console("Invalid tun_dev_netmask: %s\n", args.tun_dev_netmask.c_str());
perror("inet_pton");
return SRSRAN_ERROR_CANT_START;
}
if (0 > ioctl(sock, SIOCSIFNETMASK, &ifr)) {
err_str = strerror(errno);
logger.debug("Failed to set socket netmask: %s", err_str);

@ -43,7 +43,12 @@ int gw_test()
char* err_str = nullptr;
int rtn = 0;
rtn = gw.setup_if_addr(eps_bearer_id, LIBLTE_MME_PDN_TYPE_IPV4, htonl(inet_addr("192.168.56.32")), nullptr, err_str);
struct in_addr in_addr;
if (inet_pton(AF_INET, "192.168.56.32", &in_addr.s_addr) != 1) {
perror("inet_pton");
return SRSRAN_ERROR;
}
rtn = gw.setup_if_addr(eps_bearer_id, LIBLTE_MME_PDN_TYPE_IPV4, htonl(in_addr.s_addr), nullptr, err_str);
if (rtn != SRSRAN_SUCCESS) {
srslog::fetch_basic_logger("TEST", false)

@ -20,6 +20,7 @@
#include "srsran/common/epoll_helper.h"
#include "srsran/common/standard_streams.h"
#include "srsran/common/network_utils.h"
#include "srsran/srslog/srslog.h"
#include "ttcn3_common.h"
#include <arpa/inet.h>
@ -179,10 +180,10 @@ public:
// Port bind
struct sockaddr_in bind_addr = {};
bind_addr.sin_family = AF_INET;
inet_pton(AF_INET, net_ip.c_str(), &(bind_addr.sin_addr));
bind_addr.sin_port = htons(net_port);
if (not srsran::net_utils::set_sockaddr(&bind_addr, net_ip.c_str(), net_port)) {
srsran::console("Invalid net_ip: %s\n", net_ip.c_str());
return SRSRAN_ERROR;
}
int one = 1;
setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
ret = bind(sock_fd, (struct sockaddr*)&bind_addr, sizeof(bind_addr));

Loading…
Cancel
Save