/** Address used by inet protocol. All values are stored in network
* byte order. */
-struct inet_addr {
- struct in_addr addr;
- uint16_t port; /**< TCP listening port */
-};
+typedef struct sockaddr_in inet_addr_t;
/** INET protocol data for ports. */
struct inet_port {
int udp_socket; /**< Socket for sending and receiving broadcasts */
int listen_socket; /* */
int epoll_fd; /**< File descriptor used by epoll() in inet_receive(). */
- struct inet_addr addr; /**< Address of this port */
+ inet_addr_t addr; /**< Address of this port */
int last_recv_fd; /**< Used in inet_recv() to read data longer than receiving buffer */
struct in_addr multicast_addr;
ul_list_head_t new_peers; /**< List of just connected peers which did not send any data yet. */
static CORBA_boolean
inet_serialize_addr(FORB_CDR_Codec *codec, const void *addr)
{
- const struct inet_addr *a = addr;
- CORBA_unsigned_long haddr = ntohl(a->addr.s_addr);
- CORBA_unsigned_short hport = ntohs(a->port);
+ const inet_addr_t *a = addr;
+ CORBA_unsigned_long haddr = ntohl(a->sin_addr.s_addr);
+ CORBA_unsigned_short hport = ntohs(a->sin_port);
CORBA_boolean ret;
ret = CORBA_unsigned_long_serialize(codec, &haddr);
if (!ret)
static CORBA_boolean
inet_deserialize_addr(FORB_CDR_Codec *codec, void **addr)
{
- struct inet_addr *a;
+ inet_addr_t *a;
CORBA_unsigned_long s_addr;
CORBA_unsigned_short port;
CORBA_boolean ret;
if (!ret)
return ret;
ret = CORBA_unsigned_short_deserialize(codec, &port);
- a->addr.s_addr = htonl(s_addr);
- a->port = htons(port);
+ a->sin_family = AF_INET;
+ a->sin_addr.s_addr = htonl(s_addr);
+ a->sin_port = htons(port);
*addr = a;
return ret;
}
inet_connect(forb_peer_t *peer)
{
struct inet_peer *ipeer;
- struct sockaddr_in sa;
- struct inet_addr *addr = peer->addr;
+ inet_addr_t *sa = peer->addr;
int ret;
- if (!addr) {
+ if (!sa) {
ul_logerr("No address to connect\n");
goto err;
}
ul_logerr("socket(): %s\n", strerror(errno));
goto err_free;
}
- sa.sin_family = AF_INET;
- sa.sin_port = addr->port;
- sa.sin_addr = addr->addr;
- ul_logtrash("connect to %s:%u\n", inet_ntoa(sa.sin_addr), ntohs(sa.sin_port));
- ret = connect(ipeer->socket, (struct sockaddr*)&sa, sizeof(sa));
+ ul_logtrash("connect to %s:%u\n", inet_ntoa(sa->sin_addr), ntohs(sa->sin_port));
+ ret = connect(ipeer->socket, (struct sockaddr*)sa, sizeof(*sa));
if (ret) {
ul_logerr("connect error: %s\n", strerror(errno));
goto err_close;
size_t inet_addr2str(char *dest, size_t maxlen, const void *addr)
{
- const struct inet_addr *a = addr;
+ const inet_addr_t *a = addr;
size_t ret = 0;
if (addr) {
- snprintf(dest, maxlen, "%s:%d", inet_ntoa(a->addr), ntohs(a->port));
+ snprintf(dest, maxlen, "%s:%d", inet_ntoa(a->sin_addr), ntohs(a->sin_port));
}
return ret;
}
static void inet_register_cb(forb_port_t *port)
{
- struct inet_addr *ia;
+ inet_addr_t *ia;
ia = malloc(sizeof(*ia));
if (!ia) return;
char *fcb_addr = getenv("FCB_ADDR");
if (!fcb_addr) fcb_addr = "127.0.0.1";
- ia->addr.s_addr = inet_addr(fcb_addr);
- ia->port = htons(FCB_TCP_PORT);
+ ia->sin_family = AF_INET;
+ ia->sin_addr.s_addr = inet_addr(fcb_addr);
+ ia->sin_port = htons(FCB_TCP_PORT);
forb_new_peer_discovered(port, NULL, FCB_SERVER_ID, ia, "");
}
#else
goto err_close_listen;
}
- port_priv->addr.port = addr.sin_port;
+ port_priv->addr.sin_family = AF_INET;
+ port_priv->addr.sin_port = addr.sin_port;
if (listen_on.s_addr == INADDR_ANY) {
- if (get_local_address(port_priv->listen_socket, &port_priv->addr.addr)) {
+ if (get_local_address(port_priv->listen_socket, &port_priv->addr.sin_addr)) {
goto err_close_listen;
}
} else
- port_priv->addr.addr = listen_on;
+ port_priv->addr.sin_addr = listen_on;
/* Initialize epoll descriptor */
port_priv->epoll_fd = epoll_create(10);