diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-08-16 16:53:23 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-08-16 17:06:54 +0200 |
commit | 8c80095017f693a9e96b9118e33786f8887ffe0c (patch) | |
tree | 88a879b9daea3cb71c29f983eca65d6b92910d6e /CommonLibs/Sockets.cpp | |
parent | d49a6aa136efcb9106abfa432e148e643db7ac1e (diff) |
Add -j option to bind to specific address
Before this patch, the binding of the listening sockets was hardcoded to
a local IP.
Change-Id: I9ba184a1251c823e413a9230943ed263e52142ec
Diffstat (limited to 'CommonLibs/Sockets.cpp')
-rw-r--r-- | CommonLibs/Sockets.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/CommonLibs/Sockets.cpp b/CommonLibs/Sockets.cpp index 9030a86..a65d62b 100644 --- a/CommonLibs/Sockets.cpp +++ b/CommonLibs/Sockets.cpp @@ -223,18 +223,18 @@ int DatagramSocket::read(char* buffer, size_t length, unsigned timeout) -UDPSocket::UDPSocket(unsigned short wSrcPort) +UDPSocket::UDPSocket(const char *wSrcIP, unsigned short wSrcPort) :DatagramSocket() { - open(wSrcPort); + open(wSrcPort, wSrcIP); } -UDPSocket::UDPSocket(unsigned short wSrcPort, - const char * wDestIP, unsigned short wDestPort ) +UDPSocket::UDPSocket(const char *wSrcIP, unsigned short wSrcPort, + const char *wDestIP, unsigned short wDestPort) :DatagramSocket() { - open(wSrcPort); + open(wSrcPort, wSrcIP); destination(wDestPort, wDestIP); } @@ -246,7 +246,7 @@ void UDPSocket::destination( unsigned short wDestPort, const char * wDestIP ) } -void UDPSocket::open(unsigned short localPort) +void UDPSocket::open(unsigned short localPort, const char *wlocalIP) { // create mSocketFD = socket(AF_INET,SOCK_DGRAM,0); @@ -265,7 +265,7 @@ void UDPSocket::open(unsigned short localPort) size_t length = sizeof(address); bzero(&address,length); address.sin_family = AF_INET; - address.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + address.sin_addr.s_addr = inet_addr(wlocalIP); address.sin_port = htons(localPort); if (bind(mSocketFD,(struct sockaddr*)&address,length)<0) { perror("bind() failed"); |