fixed some code for BSDs
This commit is contained in:
parent
4396006e7a
commit
e8d5784756
159
stio/configure
vendored
159
stio/configure
vendored
@ -17139,7 +17139,7 @@ fi
|
||||
|
||||
done
|
||||
|
||||
for ac_header in net/if.h net/if_dl.h
|
||||
for ac_header in net/if.h net/if_dl.h netpacket/packet.h
|
||||
do :
|
||||
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
||||
ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "
|
||||
@ -17168,7 +17168,7 @@ fi
|
||||
|
||||
done
|
||||
|
||||
for ac_header in quadmath.h crt_externs.h sys/prctl.h uci.h
|
||||
for ac_header in quadmath.h crt_externs.h sys/prctl.h
|
||||
do :
|
||||
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
||||
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
|
||||
@ -19428,6 +19428,78 @@ cat >>confdefs.h <<_ACEOF
|
||||
_ACEOF
|
||||
|
||||
|
||||
# The cast to long int works around a bug in the HP C Compiler
|
||||
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
|
||||
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
|
||||
# This bug is HP SR number 8606223364.
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of struct sockaddr_ll" >&5
|
||||
$as_echo_n "checking size of struct sockaddr_ll... " >&6; }
|
||||
if ${ac_cv_sizeof_struct_sockaddr_ll+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (struct sockaddr_ll))" "ac_cv_sizeof_struct_sockaddr_ll" "
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
"; then :
|
||||
|
||||
else
|
||||
if test "$ac_cv_type_struct_sockaddr_ll" = yes; then
|
||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
|
||||
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
|
||||
as_fn_error 77 "cannot compute sizeof (struct sockaddr_ll)
|
||||
See \`config.log' for more details" "$LINENO" 5; }
|
||||
else
|
||||
ac_cv_sizeof_struct_sockaddr_ll=0
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_struct_sockaddr_ll" >&5
|
||||
$as_echo "$ac_cv_sizeof_struct_sockaddr_ll" >&6; }
|
||||
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define SIZEOF_STRUCT_SOCKADDR_LL $ac_cv_sizeof_struct_sockaddr_ll
|
||||
_ACEOF
|
||||
|
||||
|
||||
# The cast to long int works around a bug in the HP C Compiler
|
||||
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
|
||||
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
|
||||
# This bug is HP SR number 8606223364.
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of struct sockaddr_dl" >&5
|
||||
$as_echo_n "checking size of struct sockaddr_dl... " >&6; }
|
||||
if ${ac_cv_sizeof_struct_sockaddr_dl+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (struct sockaddr_dl))" "ac_cv_sizeof_struct_sockaddr_dl" "
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
"; then :
|
||||
|
||||
else
|
||||
if test "$ac_cv_type_struct_sockaddr_dl" = yes; then
|
||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
|
||||
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
|
||||
as_fn_error 77 "cannot compute sizeof (struct sockaddr_dl)
|
||||
See \`config.log' for more details" "$LINENO" 5; }
|
||||
else
|
||||
ac_cv_sizeof_struct_sockaddr_dl=0
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_struct_sockaddr_dl" >&5
|
||||
$as_echo "$ac_cv_sizeof_struct_sockaddr_dl" >&6; }
|
||||
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define SIZEOF_STRUCT_SOCKADDR_DL $ac_cv_sizeof_struct_sockaddr_dl
|
||||
_ACEOF
|
||||
|
||||
|
||||
# The cast to long int works around a bug in the HP C Compiler
|
||||
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
|
||||
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
|
||||
@ -19616,6 +19688,79 @@ cat >>confdefs.h <<_ACEOF
|
||||
_ACEOF
|
||||
|
||||
|
||||
# The cast to long int works around a bug in the HP C Compiler
|
||||
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
|
||||
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
|
||||
# This bug is HP SR number 8606223364.
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of struct sockaddr_ll" >&5
|
||||
$as_echo_n "checking size of struct sockaddr_ll... " >&6; }
|
||||
if ${ac_cv_sizeof_struct_sockaddr_ll+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (struct sockaddr_ll))" "ac_cv_sizeof_struct_sockaddr_ll" "
|
||||
#include <sys/socket.h>
|
||||
#include <netpacket/packet.h>
|
||||
"; then :
|
||||
|
||||
else
|
||||
if test "$ac_cv_type_struct_sockaddr_ll" = yes; then
|
||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
|
||||
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
|
||||
as_fn_error 77 "cannot compute sizeof (struct sockaddr_ll)
|
||||
See \`config.log' for more details" "$LINENO" 5; }
|
||||
else
|
||||
ac_cv_sizeof_struct_sockaddr_ll=0
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_struct_sockaddr_ll" >&5
|
||||
$as_echo "$ac_cv_sizeof_struct_sockaddr_ll" >&6; }
|
||||
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define SIZEOF_STRUCT_SOCKADDR_LL $ac_cv_sizeof_struct_sockaddr_ll
|
||||
_ACEOF
|
||||
|
||||
|
||||
# The cast to long int works around a bug in the HP C Compiler
|
||||
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
|
||||
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
|
||||
# This bug is HP SR number 8606223364.
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of struct sockaddr_dl" >&5
|
||||
$as_echo_n "checking size of struct sockaddr_dl... " >&6; }
|
||||
if ${ac_cv_sizeof_struct_sockaddr_dl+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (struct sockaddr_dl))" "ac_cv_sizeof_struct_sockaddr_dl" "
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <net/if_dl.h>
|
||||
"; then :
|
||||
|
||||
else
|
||||
if test "$ac_cv_type_struct_sockaddr_dl" = yes; then
|
||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
|
||||
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
|
||||
as_fn_error 77 "cannot compute sizeof (struct sockaddr_dl)
|
||||
See \`config.log' for more details" "$LINENO" 5; }
|
||||
else
|
||||
ac_cv_sizeof_struct_sockaddr_dl=0
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_struct_sockaddr_dl" >&5
|
||||
$as_echo "$ac_cv_sizeof_struct_sockaddr_dl" >&6; }
|
||||
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define SIZEOF_STRUCT_SOCKADDR_DL $ac_cv_sizeof_struct_sockaddr_dl
|
||||
_ACEOF
|
||||
|
||||
|
||||
# The cast to long int works around a bug in the HP C Compiler
|
||||
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
|
||||
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
|
||||
@ -20015,6 +20160,16 @@ cat >>confdefs.h <<_ACEOF
|
||||
_ACEOF
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define STIO_SIZEOF_STRUCT_SOCKADDR_LL ${ac_cv_sizeof_struct_sockaddr_ll}
|
||||
_ACEOF
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define STIO_SIZEOF_STRUCT_SOCKADDR_DL ${ac_cv_sizeof_struct_sockaddr_dl}
|
||||
_ACEOF
|
||||
|
||||
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define STIO_SIZEOF_SOCKLEN_T ${ac_cv_sizeof_socklen_t}
|
||||
_ACEOF
|
||||
|
@ -133,11 +133,11 @@ AC_CHECK_HEADERS([sys/resource.h sys/wait.h sys/syscall.h sys/ioctl.h])
|
||||
AC_CHECK_HEADERS([sys/sendfile.h sys/epoll.h sys/event.h sys/poll.h])
|
||||
AC_CHECK_HEADERS([sys/sysctl.h sys/socket.h sys/sockio.h sys/un.h])
|
||||
AC_CHECK_HEADERS([ifaddrs.h tiuser.h linux/netfilter_ipv4.h netinet/sctp.h])
|
||||
AC_CHECK_HEADERS([net/if.h net/if_dl.h], [], [], [
|
||||
AC_CHECK_HEADERS([net/if.h net/if_dl.h netpacket/packet.h], [], [], [
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>])
|
||||
AC_CHECK_HEADERS([sys/stropts.h sys/macstat.h linux/ethtool.h linux/sockios.h])
|
||||
AC_CHECK_HEADERS([quadmath.h crt_externs.h sys/prctl.h uci.h])
|
||||
AC_CHECK_HEADERS([quadmath.h crt_externs.h sys/prctl.h])
|
||||
|
||||
dnl check data types
|
||||
dnl AC_CHECK_TYPE([wchar_t],
|
||||
@ -409,6 +409,12 @@ then
|
||||
AC_CHECK_SIZEOF(struct sockaddr_un,,[
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>])
|
||||
AC_CHECK_SIZEOF(struct sockaddr_ll,,[
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>])
|
||||
AC_CHECK_SIZEOF(struct sockaddr_dl,,[
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>])
|
||||
AC_CHECK_SIZEOF(socklen_t,, [
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>])
|
||||
@ -431,6 +437,13 @@ else
|
||||
AC_CHECK_SIZEOF(struct sockaddr_un,,[
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>])
|
||||
AC_CHECK_SIZEOF(struct sockaddr_ll,,[
|
||||
#include <sys/socket.h>
|
||||
#include <netpacket/packet.h>])
|
||||
AC_CHECK_SIZEOF(struct sockaddr_dl,,[
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <net/if_dl.h>])
|
||||
AC_CHECK_SIZEOF(socklen_t,, [
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>])
|
||||
@ -573,6 +586,8 @@ AC_DEFINE_UNQUOTED(STIO_MBLEN_MAX, ${ax_cv_numvalof_MB_LEN_MAX}, [MB_LEN_MAX])
|
||||
AC_DEFINE_UNQUOTED(STIO_SIZEOF_STRUCT_SOCKADDR_IN, ${ac_cv_sizeof_struct_sockaddr_in}, [sizeof(struct sockaddr_in)])
|
||||
AC_DEFINE_UNQUOTED(STIO_SIZEOF_STRUCT_SOCKADDR_IN6, ${ac_cv_sizeof_struct_sockaddr_in6}, [sizeof(struct sockaddr_in6)])
|
||||
AC_DEFINE_UNQUOTED(STIO_SIZEOF_STRUCT_SOCKADDR_UN, ${ac_cv_sizeof_struct_sockaddr_un}, [sizeof(struct sockaddr_un)])
|
||||
AC_DEFINE_UNQUOTED(STIO_SIZEOF_STRUCT_SOCKADDR_LL, ${ac_cv_sizeof_struct_sockaddr_ll}, [sizeof(struct sockaddr_ll)])
|
||||
AC_DEFINE_UNQUOTED(STIO_SIZEOF_STRUCT_SOCKADDR_DL, ${ac_cv_sizeof_struct_sockaddr_dl}, [sizeof(struct sockaddr_dl)])
|
||||
AC_DEFINE_UNQUOTED(STIO_SIZEOF_SOCKLEN_T, ${ac_cv_sizeof_socklen_t}, [sizeof(socklen_t)])
|
||||
|
||||
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <netpacket/packet.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <assert.h>
|
||||
@ -279,12 +278,14 @@ printf ("PROCESS WROTE DATA...\n");
|
||||
static int arp_sck_on_read (stio_dev_sck_t* dev, const void* data, stio_iolen_t dlen, const stio_sckaddr_t* srcaddr)
|
||||
{
|
||||
stio_etharp_pkt_t* eap;
|
||||
struct sockaddr_ll* sll = (struct sockaddr_ll*)srcaddr;
|
||||
|
||||
|
||||
if (dlen < STIO_SIZEOF(*eap)) return 0; /* drop */
|
||||
|
||||
eap = (stio_etharp_pkt_t*)data;
|
||||
printf ("ARP ON IFINDEX %d OPCODE: %d", sll->sll_ifindex, ntohs(eap->arphdr.opcode));
|
||||
|
||||
printf ("ARP ON IFINDEX %d OPCODE: %d", stio_getsckaddrifindex(srcaddr), ntohs(eap->arphdr.opcode));
|
||||
|
||||
printf (" SHA: %02X:%02X:%02X:%02X:%02X:%02X", eap->arppld.sha[0], eap->arppld.sha[1], eap->arppld.sha[2], eap->arppld.sha[3], eap->arppld.sha[4], eap->arppld.sha[5]);
|
||||
printf (" SPA: %d.%d.%d.%d", eap->arppld.spa[0], eap->arppld.spa[1], eap->arppld.spa[2], eap->arppld.spa[3]);
|
||||
printf (" THA: %02X:%02X:%02X:%02X:%02X:%02X", eap->arppld.tha[0], eap->arppld.tha[1], eap->arppld.tha[2], eap->arppld.tha[3], eap->arppld.tha[4], eap->arppld.tha[5]);
|
||||
@ -452,7 +453,7 @@ static int icmp_sck_on_read (stio_dev_sck_t* dev, const void* data, stio_iolen_t
|
||||
iphdr = (stio_iphdr_t*)data;
|
||||
icmphdr = (stio_icmphdr_t*)((stio_uint8_t*)data + (iphdr->ihl * 4));
|
||||
|
||||
/* TODO": check srcaddr against target */
|
||||
/* TODO: check srcaddr against target */
|
||||
|
||||
if (icmphdr->type == STIO_ICMP_ECHO_REPLY &&
|
||||
stio_ntoh16(icmphdr->u.echo.seq) == icmpxtn->icmp_seq) /* TODO: more check.. echo.id.. */
|
||||
|
@ -340,6 +340,9 @@
|
||||
/* Define to 1 if you have the <netinet/sctp.h> header file. */
|
||||
#undef HAVE_NETINET_SCTP_H
|
||||
|
||||
/* Define to 1 if you have the <netpacket/packet.h> header file. */
|
||||
#undef HAVE_NETPACKET_PACKET_H
|
||||
|
||||
/* Define to 1 if you have the <net/if_dl.h> header file. */
|
||||
#undef HAVE_NET_IF_DL_H
|
||||
|
||||
@ -639,9 +642,6 @@
|
||||
/* Define to 1 if you have the `t_connect' function. */
|
||||
#undef HAVE_T_CONNECT
|
||||
|
||||
/* Define to 1 if you have the <uci.h> header file. */
|
||||
#undef HAVE_UCI_H
|
||||
|
||||
/* Define to 1 if you have the <ucontext.h> header file. */
|
||||
#undef HAVE_UCONTEXT_H
|
||||
|
||||
@ -772,12 +772,18 @@
|
||||
/* The size of `socklen_t', as computed by sizeof. */
|
||||
#undef SIZEOF_SOCKLEN_T
|
||||
|
||||
/* The size of `struct sockaddr_dl', as computed by sizeof. */
|
||||
#undef SIZEOF_STRUCT_SOCKADDR_DL
|
||||
|
||||
/* The size of `struct sockaddr_in', as computed by sizeof. */
|
||||
#undef SIZEOF_STRUCT_SOCKADDR_IN
|
||||
|
||||
/* The size of `struct sockaddr_in6', as computed by sizeof. */
|
||||
#undef SIZEOF_STRUCT_SOCKADDR_IN6
|
||||
|
||||
/* The size of `struct sockaddr_ll', as computed by sizeof. */
|
||||
#undef SIZEOF_STRUCT_SOCKADDR_LL
|
||||
|
||||
/* The size of `struct sockaddr_un', as computed by sizeof. */
|
||||
#undef SIZEOF_STRUCT_SOCKADDR_UN
|
||||
|
||||
@ -892,12 +898,18 @@
|
||||
/* sizeof(socklen_t) */
|
||||
#undef STIO_SIZEOF_SOCKLEN_T
|
||||
|
||||
/* sizeof(struct sockaddr_dl) */
|
||||
#undef STIO_SIZEOF_STRUCT_SOCKADDR_DL
|
||||
|
||||
/* sizeof(struct sockaddr_in) */
|
||||
#undef STIO_SIZEOF_STRUCT_SOCKADDR_IN
|
||||
|
||||
/* sizeof(struct sockaddr_in6) */
|
||||
#undef STIO_SIZEOF_STRUCT_SOCKADDR_IN6
|
||||
|
||||
/* sizeof(struct sockaddr_ll) */
|
||||
#undef STIO_SIZEOF_STRUCT_SOCKADDR_LL
|
||||
|
||||
/* sizeof(struct sockaddr_un) */
|
||||
#undef STIO_SIZEOF_STRUCT_SOCKADDR_UN
|
||||
|
||||
|
@ -35,7 +35,15 @@
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netpacket/packet.h>
|
||||
|
||||
#if defined(HAVE_NETPACKET_PACKET_H)
|
||||
# include <netpacket/packet.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_NET_IF_DL_H)
|
||||
# include <net/if_dl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__linux__)
|
||||
# include <limits.h>
|
||||
@ -137,10 +145,17 @@ int stio_getsckaddrinfo (stio_t* stio, const stio_sckaddr_t* addr, stio_scklen_t
|
||||
if (family) *family = AF_INET6;
|
||||
return 0;
|
||||
|
||||
#if defined(AF_PACKET) && (STIO_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
case AF_PACKET:
|
||||
if (len) *len = STIO_SIZEOF(struct sockaddr_ll);
|
||||
if (family) *family = AF_PACKET;
|
||||
return 0;
|
||||
#elif defined(AF_LINK) && (STIO_SIZEOF_STRUCT_SOCKADDR_DL > 0)
|
||||
case AF_LINK:
|
||||
if (len) *len = STIO_SIZEOF(struct sockaddr_dl);
|
||||
if (family) *family = AF_LINK;
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
/* TODO: more address type */
|
||||
}
|
||||
@ -165,6 +180,25 @@ stio_uint16_t stio_getsckaddrport (const stio_sckaddr_t* addr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stio_getsckaddrifindex (const stio_sckaddr_t* addr)
|
||||
{
|
||||
struct sockaddr* saddr = (struct sockaddr*)addr;
|
||||
|
||||
#if defined(AF_PACKET) && (STIO_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
if (saddr->sa_family == AF_PACKET)
|
||||
{
|
||||
return ((struct sockaddr_ll*)addr)->sll_ifindex;
|
||||
}
|
||||
|
||||
#elif defined(AF_LINK) && (STIO_SIZEOF_STRUCT_SOCKADDR_DL > 0)
|
||||
if (saddr->sa_family == AF_LINK)
|
||||
{
|
||||
return ((struct sockaddr_dl*)addr)->sdl_index;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stio_equalsckaddrs (stio_t* stio, const stio_sckaddr_t* addr1, const stio_sckaddr_t* addr2)
|
||||
{
|
||||
@ -201,6 +235,7 @@ void stio_sckaddr_initforip6 (stio_sckaddr_t* sckaddr, stio_uint16_t port, stio_
|
||||
|
||||
void stio_sckaddr_initforeth (stio_sckaddr_t* sckaddr, int ifindex, stio_ethaddr_t* ethaddr)
|
||||
{
|
||||
#if defined(AF_PACKET) && (STIO_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
struct sockaddr_ll* sll = (struct sockaddr_ll*)sckaddr;
|
||||
STIO_MEMSET (sll, 0, STIO_SIZEOF(*sll));
|
||||
sll->sll_family = AF_PACKET;
|
||||
@ -210,6 +245,20 @@ void stio_sckaddr_initforeth (stio_sckaddr_t* sckaddr, int ifindex, stio_ethaddr
|
||||
sll->sll_halen = STIO_ETHADDR_LEN;
|
||||
STIO_MEMCPY (sll->sll_addr, ethaddr, STIO_ETHADDR_LEN);
|
||||
}
|
||||
|
||||
#elif defined(AF_LINK) && (STIO_SIZEOF_STRUCT_SOCKADDR_DL > 0)
|
||||
struct sockaddr_dl* sll = (struct sockaddr_dl*)sckaddr;
|
||||
STIO_MEMSET (sll, 0, STIO_SIZEOF(*sll));
|
||||
sll->sdl_family = AF_LINK;
|
||||
sll->sdl_index = ifindex;
|
||||
if (ethaddr)
|
||||
{
|
||||
sll->sdl_alen = STIO_ETHADDR_LEN;
|
||||
STIO_MEMCPY (sll->sdl_data, ethaddr, STIO_ETHADDR_LEN);
|
||||
}
|
||||
#else
|
||||
# error UNSUPPORTED DATALINK SOCKET ADDRESS
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
@ -260,12 +309,24 @@ static struct sck_type_map_t sck_type_map[] =
|
||||
/* STIO_DEV_SCK_UDP6 */
|
||||
{ AF_INET6, SOCK_DGRAM, 0, 0 },
|
||||
|
||||
|
||||
#if defined(AF_PACKET) && (STIO_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
/* STIO_DEV_SCK_ARP - Ethernet type is 2 bytes long. Protocol must be specified in the network byte order */
|
||||
{ AF_PACKET, SOCK_RAW, STIO_CONST_HTON16(STIO_ETHHDR_PROTO_ARP), 0 },
|
||||
|
||||
/* STIO_DEV_SCK_DGRAM */
|
||||
{ AF_PACKET, SOCK_DGRAM, STIO_CONST_HTON16(STIO_ETHHDR_PROTO_ARP), 0 },
|
||||
|
||||
#elif defined(AF_LINK) && (STIO_SIZEOF_STRUCT_SOCKADDR_DL > 0)
|
||||
/* STIO_DEV_SCK_ARP */
|
||||
{ AF_LINK, SOCK_RAW, STIO_CONST_HTON16(STIO_ETHHDR_PROTO_ARP), 0 },
|
||||
|
||||
/* STIO_DEV_SCK_DGRAM */
|
||||
{ AF_LINK, SOCK_DGRAM, STIO_CONST_HTON16(STIO_ETHHDR_PROTO_ARP), 0 },
|
||||
#else
|
||||
# error UNSUPPORTED DATA LINK ADDRESS
|
||||
#endif
|
||||
|
||||
/* STIO_DEV_SCK_ICMP4 - IP protocol field is 1 byte only. no byte order conversion is needed */
|
||||
{ AF_INET, SOCK_RAW, IPPROTO_ICMP, 0, },
|
||||
|
||||
|
@ -496,6 +496,14 @@ STIO_EXPORT stio_uint16_t stio_getsckaddrport (
|
||||
const stio_sckaddr_t* addr
|
||||
);
|
||||
|
||||
/*
|
||||
* The stio_getsckaddrifindex() function returns an interface number.
|
||||
* If the address doesn't support the interface number, it returns 0. */
|
||||
STIO_EXPORT int stio_getsckaddrifindex (
|
||||
const stio_sckaddr_t* addr
|
||||
);
|
||||
|
||||
|
||||
STIO_EXPORT void stio_sckaddr_initforip4 (
|
||||
stio_sckaddr_t* sckaddr,
|
||||
stio_uint16_t port,
|
||||
|
@ -264,7 +264,7 @@ static int mux_control (stio_dev_t* dev, int cmd, stio_syshnd_t hnd, int dev_cap
|
||||
struct stio_mux_t
|
||||
{
|
||||
int hnd;
|
||||
struct epoll_event revs[100];
|
||||
struct epoll_event revs[100]; /* TODO: is it a good size? */
|
||||
};
|
||||
|
||||
static int mux_open (stio_t* stio)
|
||||
@ -500,9 +500,8 @@ static STIO_INLINE void handle_event (stio_dev_t* dev, int events, int rdhup)
|
||||
if (dev && (events & STIO_DEV_EVENT_PRI))
|
||||
{
|
||||
/* urgent data */
|
||||
/* TODO: urgent data.... */
|
||||
/* TODO: implement urgent data handling */
|
||||
/*x = dev->dev_mth->urgread (dev, stio->bugbuf, &len);*/
|
||||
printf ("has urgent data...\n");
|
||||
}
|
||||
|
||||
if (dev && (events & STIO_DEV_EVENT_OUT))
|
||||
@ -1118,7 +1117,6 @@ int stio_dev_ioctl (stio_dev_t* dev, int cmd, void* arg)
|
||||
|
||||
int stio_dev_watch (stio_dev_t* dev, stio_dev_watch_cmd_t cmd, int events)
|
||||
{
|
||||
/*struct epoll_event ev;*/
|
||||
int mux_cmd;
|
||||
int dev_capa;
|
||||
|
||||
@ -1165,33 +1163,19 @@ int stio_dev_watch (stio_dev_t* dev, stio_dev_watch_cmd_t cmd, int events)
|
||||
/* this function honors STIO_DEV_EVENT_IN and STIO_DEV_EVENT_OUT only
|
||||
* as valid input event bits. it intends to provide simple abstraction
|
||||
* by reducing the variety of event bits that the caller has to handle. */
|
||||
/*ev.events = EPOLLHUP | EPOLLERR; */
|
||||
|
||||
if ((events & STIO_DEV_EVENT_IN) && !(dev->dev_capa & (STIO_DEV_CAPA_IN_CLOSED | STIO_DEV_CAPA_IN_DISABLED)))
|
||||
{
|
||||
if (dev->dev_capa & STIO_DEV_CAPA_IN)
|
||||
{
|
||||
/*ev.events |= EPOLLIN;
|
||||
#if defined(EPOLLRDHUP)
|
||||
ev.events |= EPOLLRDHUP;
|
||||
#endif*/
|
||||
if (dev->dev_capa & STIO_DEV_CAPA_PRI)
|
||||
{
|
||||
/*ev.events |= EPOLLPRI;*/
|
||||
dev_capa |= STIO_DEV_CAPA_PRI_WATCHED;
|
||||
}
|
||||
|
||||
if (dev->dev_capa & STIO_DEV_CAPA_PRI) dev_capa |= STIO_DEV_CAPA_PRI_WATCHED;
|
||||
dev_capa |= STIO_DEV_CAPA_IN_WATCHED;
|
||||
}
|
||||
}
|
||||
|
||||
if ((events & STIO_DEV_EVENT_OUT) && !(dev->dev_capa & STIO_DEV_CAPA_OUT_CLOSED))
|
||||
{
|
||||
if (dev->dev_capa & STIO_DEV_CAPA_OUT)
|
||||
{
|
||||
/*ev.events |= EPOLLOUT;*/
|
||||
dev_capa |= STIO_DEV_CAPA_OUT_WATCHED;
|
||||
}
|
||||
if (dev->dev_capa & STIO_DEV_CAPA_OUT) dev_capa |= STIO_DEV_CAPA_OUT_WATCHED;
|
||||
}
|
||||
|
||||
if (mux_cmd == MUX_CMD_UPDATE && (dev_capa & DEV_CAPA_ALL_WATCHED) == (dev->dev_capa & DEV_CAPA_ALL_WATCHED))
|
||||
|
@ -71,10 +71,10 @@ struct stio_devaddr_t
|
||||
# define STIO_CONST_NTOH32(x) STIO_CONST_SWAP32(x)
|
||||
# define STIO_CONST_HTON32(x) STIO_CONST_SWAP32(x)
|
||||
#elif defined(STIO_ENDIAN_BIG)
|
||||
# define STIO_CONST_NTOH16(x)
|
||||
# define STIO_CONST_HTON16(x)
|
||||
# define STIO_CONST_NTOH32(x)
|
||||
# define STIO_CONST_HTON32(x)
|
||||
# define STIO_CONST_NTOH16(x) (x)
|
||||
# define STIO_CONST_HTON16(x) (x)
|
||||
# define STIO_CONST_NTOH32(x) (x)
|
||||
# define STIO_CONST_HTON32(x) (x)
|
||||
#else
|
||||
# error UNKNOWN ENDIAN
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user