From d981b7d8d93294db6c428867bfa1d87277f471c9 Mon Sep 17 00:00:00 2001 From: navid <navid@mycompany.com> Date: Tue, 21 Jul 2015 11:35:17 +0000 Subject: [PATCH] get the IP address of the RRH eth interface (option -i) git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7718 818b1a75-f10b-46b9-bf7c-635c3b92a50f --- targets/RT/USER/rrh_gw.c | 33 +++++++++++++++++++++++++++- targets/SIMU/USER/oaisim.c | 10 +++++++++ targets/SIMU/USER/oaisim_config.c | 4 ++-- targets/SIMU/USER/oaisim_functions.c | 10 +++++++++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/targets/RT/USER/rrh_gw.c b/targets/RT/USER/rrh_gw.c index 8042be7885..d9394a866e 100644 --- a/targets/RT/USER/rrh_gw.c +++ b/targets/RT/USER/rrh_gw.c @@ -113,6 +113,7 @@ unsigned int rt_period; struct itimerspec timerspec; +char* if_name="eth0"; int main(int argc, char **argv) { @@ -188,6 +189,7 @@ static rrh_module_t new_module (unsigned int id, dev_type_t type) { rrh_mod.eth_dev.func_type=RRH_FUNC; /* each module is associated with an ethernet device */ rrh_mod.eth_dev.type=ETH_IF; + get_ip_addreess(if_name); openair0_cfg.my_ip=&rrh_ip[0]; openair0_cfg.my_port=rrh_port; @@ -458,7 +460,7 @@ static void get_options(int argc, char *argv[]) { int opt; - while ((opt = getopt(argc, argv, "xvhlte:n:u:g:r:w:")) != -1) { + while ((opt = getopt(argc, argv, "xvhlte:n:u:g:r:w:i:")) != -1) { switch (opt) { case 'n': @@ -472,6 +474,12 @@ static void get_options(int argc, char *argv[]) { case 'g': glog_level=atoi(optarg); break; + case 'i': + if (optarg) { + if_name=strdup(optarg); + printf("RRH interface name is set to %s\n", if_name); + } + break; case 'r': //rrh_log_level=atoi(optarg); break; @@ -510,6 +518,28 @@ static void get_options(int argc, char *argv[]) { } +int get_ip_addreess(char* if_name){ + + int fd; + struct ifreq ifr; + + fd = socket(AF_INET, SOCK_DGRAM, 0); + + /* I want to get an IPv4 IP address */ + ifr.ifr_addr.sa_family = AF_INET; + + /* I want IP address attached to "eth0" */ + strncpy(ifr.ifr_name, if_name, IFNAMSIZ-1); + + ioctl(fd, SIOCGIFADDR, &ifr); + + close(fd); + + /* display result */ + snprintf(&rrh_ip[0],20,"%s", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); + printf("Got IP address %s from interface %s\n", rrh_ip,if_name); + return 0; +} /*!\fn void print_help(void) * \brief this function @@ -527,6 +557,7 @@ static void print_help(void) { puts("\t -n create eNB module\n"); puts("\t -u create UE module\n"); puts("\t -g define global log level\n"); + puts("\t -i set the RRH interface (default eth0)\n"); puts("\t -r define rrh log level\n"); puts("\t -e define eNB log level\n"); puts("\t -x enable real time bahaviour\n"); diff --git a/targets/SIMU/USER/oaisim.c b/targets/SIMU/USER/oaisim.c index 8e1e3a98c9..cd87d30495 100644 --- a/targets/SIMU/USER/oaisim.c +++ b/targets/SIMU/USER/oaisim.c @@ -26,6 +26,16 @@ Address : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE *******************************************************************************/ +/*! \file oaisim.c +* \brief oaisim top level +* \author Navid Nikaein +* \date 2013-2015 +* \version 1.0 +* \company Eurecom +* \email: openair_tech@eurecom.fr +* \note +* \warning +*/ #include <string.h> #include <math.h> diff --git a/targets/SIMU/USER/oaisim_config.c b/targets/SIMU/USER/oaisim_config.c index f6d94ee31b..2a81a8619d 100644 --- a/targets/SIMU/USER/oaisim_config.c +++ b/targets/SIMU/USER/oaisim_config.c @@ -29,8 +29,8 @@ /*! \file oaisim_config.c * \brief Configuration of oaisim -* \author Navid Nikaein & Andre Gomes (One source) -* \date 2014 +* \author Navid Nikaein +* \date 2013-2015 * \version 1.0 * \company Eurecom * \email: openair_tech@eurecom.fr diff --git a/targets/SIMU/USER/oaisim_functions.c b/targets/SIMU/USER/oaisim_functions.c index faf6878f25..5dfa8f424d 100644 --- a/targets/SIMU/USER/oaisim_functions.c +++ b/targets/SIMU/USER/oaisim_functions.c @@ -26,6 +26,16 @@ Address : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE *******************************************************************************/ +/*! \file oaisim_functions.c +* \brief function primitives of oaisim +* \author Navid Nikaein +* \date 2013-2015 +* \version 1.0 +* \company Eurecom +* \email: openair_tech@eurecom.fr +* \note +* \warning +*/ #include <stdlib.h> -- GitLab