Commit b80177d1 authored by Raphael Defosseux's avatar Raphael Defosseux

fix(sctp): proper creation of the sctp listener socket

Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@openairinterface.org>
parent f06e392e
...@@ -39,8 +39,10 @@ extern "C" { ...@@ -39,8 +39,10 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include <netdb.h>
#include "bstrlib.h" #include "bstrlib.h"
} }
...@@ -66,13 +68,21 @@ sctp_server::~sctp_server() {} ...@@ -66,13 +68,21 @@ sctp_server::~sctp_server() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int sctp_server::create_socket(const char* address, const uint16_t port_num) { int sctp_server::create_socket(const char* address, const uint16_t port_num) {
if ((socket_ = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) { struct addrinfo* res;
if (getaddrinfo(address, 0, NULL, &res) < 0) {
Logger::sctp().error(
"getaddrinfo on %s: %s:%d", address, strerror(errno), errno);
return -1;
} else {
Logger::sctp().info("getaddrinfo on %s was OK", address);
}
if ((socket_ = socket(res->ai_family, SOCK_STREAM, IPPROTO_SCTP)) < 0) {
Logger::sctp().error("socket: %s:%d", strerror(errno), errno); Logger::sctp().error("socket: %s:%d", strerror(errno), errno);
return -1; return -1;
} }
Logger::sctp().info("Created socket (%d)", socket_); Logger::sctp().info("Created socket (%d)", socket_);
bzero(&serverAddr_, sizeof(serverAddr_)); bzero(&serverAddr_, sizeof(serverAddr_));
serverAddr_.sin_family = AF_INET; serverAddr_.sin_family = res->ai_family;
serverAddr_.sin_addr.s_addr = htonl(INADDR_ANY); serverAddr_.sin_addr.s_addr = htonl(INADDR_ANY);
serverAddr_.sin_port = htons(port_num); serverAddr_.sin_port = htons(port_num);
inet_pton(AF_INET, address, &serverAddr_.sin_addr); inet_pton(AF_INET, address, &serverAddr_.sin_addr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment