smartsdr-dsp/DSP_API/SmartSDR_Interface/io_utils.c

59 lines
1.9 KiB
C
Raw Permalink Normal View History

///*! \file io_utils.c
// * \brief Module that contains various IO utilities
// *
// * \copyright Copyright 2011-2012 FlexRadio Systems. All Rights Reserved.
// * Unauthorized use, duplication or distribution of this software is
// * strictly prohibited by law.
// *
// * \date 9-NOV-2011
// * \author Terry Gerdes, AB5K
// * \author Stephen Hicks, N5AC
// */
/* *****************************************************************************
*
* Copyright (C) 2014 FlexRadio Systems.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact Information:
* email: gpl<at>flexradiosystems.com
* Mail: FlexRadio Systems, Suite 1-150, 4616 W. Howard LN, Austin, TX 78728
*
* ************************************************************************** */
#include <stdio.h>
#include <sys/types.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>
#include "common.h"
uint32 net_get_ip()
{
struct ifaddrs* ifAddrStruct = NULL;
struct ifaddrs* ifa = NULL;
uint32 ip = 0;
getifaddrs(&ifAddrStruct);
ifa = ifAddrStruct->ifa_next->ifa_next->ifa_next->ifa_next; // skip to 4th interface
ip = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
freeifaddrs(ifAddrStruct);
return ip;
}