2004-09-02 18:20:13 +04:00
|
|
|
#include "ompi_config.h"
|
2004-10-22 20:06:05 +04:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2004-09-02 18:45:01 +04:00
|
|
|
#include <sys/types.h>
|
2004-10-22 20:06:05 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
2004-09-02 18:20:13 +04:00
|
|
|
#include <sys/socket.h>
|
2004-10-22 20:06:05 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
2004-09-02 18:20:13 +04:00
|
|
|
#include <netinet/in.h>
|
2004-10-22 20:06:05 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
2004-09-02 18:20:13 +04:00
|
|
|
#include <arpa/inet.h>
|
2004-10-22 20:06:05 +04:00
|
|
|
#endif
|
2004-09-02 18:20:13 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include "include/constants.h"
|
|
|
|
#include "util/if.h"
|
|
|
|
#include "oob_tcp.h"
|
|
|
|
#include "oob_tcp_addr.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void mca_oob_tcp_addr_construct(mca_oob_tcp_addr_t* addr)
|
|
|
|
{
|
|
|
|
memset(&addr->addr_name, 0, sizeof(addr->addr_name));
|
|
|
|
addr->addr_count = 0;
|
|
|
|
addr->addr_alloc = 0;
|
|
|
|
addr->addr_next = 0;
|
|
|
|
addr->addr_inet = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mca_oob_tcp_addr_destruct(mca_oob_tcp_addr_t* addr)
|
|
|
|
{
|
|
|
|
if(addr->addr_inet != NULL)
|
|
|
|
free(addr->addr_inet);
|
|
|
|
}
|
|
|
|
|
|
|
|
OBJ_CLASS_INSTANCE(
|
|
|
|
mca_oob_tcp_addr_t,
|
|
|
|
ompi_object_t,
|
|
|
|
mca_oob_tcp_addr_construct,
|
|
|
|
mca_oob_tcp_addr_destruct);
|
|
|
|
|
|
|
|
|
|
|
|
void mca_oob_tcp_addr_pack(ompi_buffer_t buffer)
|
|
|
|
{
|
|
|
|
uint32_t count = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ompi_pack(buffer, &mca_oob_name_self, 1, OMPI_NAME);
|
2004-10-01 01:23:10 +04:00
|
|
|
|
2004-09-02 18:20:13 +04:00
|
|
|
for(i=ompi_ifbegin(); i>0; i=ompi_ifnext(i)) {
|
|
|
|
struct sockaddr_in inaddr;
|
|
|
|
ompi_ifindextoaddr(i, (struct sockaddr*)&inaddr, sizeof(inaddr));
|
2004-10-01 01:23:10 +04:00
|
|
|
if(ompi_ifcount() > 1 && inaddr.sin_addr.s_addr == inet_addr("127.0.0.1"))
|
2004-09-02 18:20:13 +04:00
|
|
|
continue;
|
|
|
|
count++;
|
2004-10-01 01:23:10 +04:00
|
|
|
}
|
2004-09-02 18:20:13 +04:00
|
|
|
ompi_pack(buffer, &count, 1, OMPI_INT32);
|
|
|
|
|
|
|
|
for(i=ompi_ifbegin(); i>0; i=ompi_ifnext(i)) {
|
|
|
|
struct sockaddr_in inaddr;
|
|
|
|
ompi_ifindextoaddr(i, (struct sockaddr*)&inaddr, sizeof(inaddr));
|
2004-10-01 01:23:10 +04:00
|
|
|
if(ompi_ifcount() > 1 && inaddr.sin_addr.s_addr == inet_addr("127.0.0.1"))
|
2004-09-02 18:20:13 +04:00
|
|
|
continue;
|
|
|
|
inaddr.sin_port = mca_oob_tcp_component.tcp_listen_port;
|
|
|
|
ompi_pack(buffer,&inaddr,sizeof(inaddr),OMPI_BYTE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mca_oob_tcp_addr_t* mca_oob_tcp_addr_unpack(ompi_buffer_t buffer)
|
|
|
|
{
|
|
|
|
mca_oob_tcp_addr_t* addr = OBJ_NEW(mca_oob_tcp_addr_t);
|
|
|
|
if(NULL == addr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ompi_unpack(buffer, &addr->addr_name, 1, OMPI_NAME);
|
|
|
|
ompi_unpack(buffer, &addr->addr_count, 1, OMPI_INT32);
|
|
|
|
if(addr->addr_count != 0) {
|
2004-10-28 23:40:30 +04:00
|
|
|
addr->addr_inet = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in) * addr->addr_count);
|
2004-09-02 18:20:13 +04:00
|
|
|
if(NULL == addr->addr_inet) {
|
|
|
|
OBJ_RELEASE(addr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
addr->addr_alloc = addr->addr_count;
|
|
|
|
ompi_unpack(buffer, addr->addr_inet, (addr->addr_count * sizeof(struct sockaddr_in)), OMPI_BYTE);
|
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int mca_oob_tcp_addr_get_next(mca_oob_tcp_addr_t* addr, struct sockaddr_in* inaddr)
|
|
|
|
{
|
|
|
|
if(addr == NULL || addr->addr_count == 0)
|
|
|
|
return OMPI_ERROR;
|
|
|
|
*inaddr = addr->addr_inet[addr->addr_next];
|
|
|
|
if(++addr->addr_next >= addr->addr_count)
|
|
|
|
addr->addr_next = 0;
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int mca_oob_tcp_addr_insert(mca_oob_tcp_addr_t* addr, const struct sockaddr_in* inaddr)
|
|
|
|
{
|
|
|
|
if(addr->addr_alloc == 0) {
|
|
|
|
addr->addr_alloc = 2;
|
2004-10-28 23:40:30 +04:00
|
|
|
addr->addr_inet = (struct sockaddr_in *)malloc(addr->addr_alloc * sizeof(struct sockaddr_in));
|
2004-09-02 18:20:13 +04:00
|
|
|
} else if(addr->addr_count == addr->addr_alloc) {
|
|
|
|
addr->addr_alloc <<= 1;
|
2004-10-28 23:40:30 +04:00
|
|
|
addr->addr_inet = (struct sockaddr_in *)realloc(addr->addr_inet, addr->addr_alloc * sizeof(struct sockaddr_in));
|
2004-09-02 18:20:13 +04:00
|
|
|
}
|
|
|
|
if(NULL == addr->addr_inet)
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
memcpy(addr->addr_inet+addr->addr_count, inaddr, sizeof(struct sockaddr_in));
|
|
|
|
addr->addr_count++;
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|