-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwhatismyIP.cpp
More file actions
53 lines (45 loc) · 1.41 KB
/
Copy pathwhatismyIP.cpp
File metadata and controls
53 lines (45 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <sys/types.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
#include <iostream>
using namespace std;
int getVideoAddress(std::string *videoAddress);
int main (int argc, const char * argv[]) {
std::string videoAddress;
getVideoAddress(&videoAddress);
std::cout << "Video Address: " + videoAddress << "\n";
return 0;
}
int getVideoAddress(std::string *videoAddress) {
//what is my IP
struct ifaddrs * ifAddrStruct=NULL;
struct ifaddrs * ifa=NULL;
void * tmpAddrPtr=NULL;
getifaddrs(&ifAddrStruct);
char *IPAddress = new char [16];
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
if (!ifa->ifa_addr) {
continue;
}
if (ifa->ifa_addr->sa_family == AF_INET) {
tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
char addressBuffer[INET_ADDRSTRLEN];
inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
if (sizeof(addressBuffer) > 8 && !strstr(ifa->ifa_name, "lo") ) {
strcpy (IPAddress,addressBuffer);
}
}
}
if (ifAddrStruct!=NULL) freeifaddrs(ifAddrStruct);
// Concatenate
std::string head = "rtmp://";
std::string mid = IPAddress;
std::string tail = ":1936/live/stream";
*videoAddress = head + mid + tail;
delete [] IPAddress;
// return videoAddress;
return 0;
}