--- libaitio/src/sock.c 2014/05/18 23:35:16 1.15 +++ libaitio/src/sock.c 2016/08/18 09:06:31 1.16 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sock.c,v 1.15 2014/05/18 23:35:16 misho Exp $ +* $Id: sock.c,v 1.16 2016/08/18 09:06:31 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2014 +Copyright 2004 - 2016 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -168,8 +168,13 @@ io_txNet(sched_task_t *task) if (s->sock_type == SOCK_STREAM) wlen = send(TASK_FD(task), buf, len, 0); else - wlen = sendto(TASK_FD(task), buf, len, 0, - &cli->cli_addr.sa, cli->cli_addr.sa.sa_len); +#ifndef __linux__ + wlen = sendto(TASK_FD(task), buf, len, 0, &cli->cli_addr.sa, cli->cli_addr.sa.sa_len); +#else + wlen = sendto(TASK_FD(task), buf, len, 0, &cli->cli_addr.sa, + cli->cli_addr.sa.sa_family == AF_INET ? + sizeof cli->cli_addr.sin : sizeof cli->cli_addr.sin6); +#endif if (wlen < 1) { schedEvent(TASK_ROOT(task), io_closeClient, cli, 0, NULL, 0); break; @@ -452,7 +457,12 @@ ioInitSocket(int role, int type, int proto, const char e_free(s); return NULL; } +#ifndef __linux__ if (bind(s->sock_fd, &s->sock_addr.sa, s->sock_addr.sa.sa_len) == -1) { +#else + if (bind(s->sock_fd, &s->sock_addr.sa, s->sock_addr.sa.sa_family == AF_INET ? + sizeof s->sock_addr.sin : sizeof s->sock_addr.sin6) == -1) { +#endif LOGERR; AIT_FREE_VAL(&s->sock_buf); e_free(s); @@ -549,8 +559,12 @@ ioUpSocket(sock_t * __restrict s, void *arg, int timeo case IO_SOCK_ROLE_CLIENT: memcpy(&s->sock_peer, peer, sizeof s->sock_peer); - if (connect(s->sock_fd, &s->sock_peer.sa, - s->sock_peer.sa.sa_len) == -1) { +#ifndef __linux__ + if (connect(s->sock_fd, &s->sock_peer.sa, s->sock_peer.sa.sa_len) == -1) { +#else + if (connect(s->sock_fd, &s->sock_peer.sa, s->sock_addr.sa.sa_family == AF_INET ? + sizeof s->sock_peer.sin : sizeof s->sock_peer.sin6) == -1) { +#endif LOGERR; return -1; }