added HIO_DEV_SCK_SCTP4 and HIO_DEV_SCK_SCTP6
This commit is contained in:
parent
63cdf7b3bb
commit
f42f6286b4
@ -15,6 +15,8 @@ static int g_num_thrs = 2;
|
||||
static hio_svc_htts_t* g_htts[MAX_NUM_THRS];
|
||||
static int g_htts_no = 0;
|
||||
static pthread_mutex_t g_htts_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int g_dev_type4 = HIO_DEV_SCK_TCP4;
|
||||
static int g_dev_type6 = HIO_DEV_SCK_TCP6;
|
||||
|
||||
static int print_qparam (hio_bcs_t* key, hio_bcs_t* val, void* ctx)
|
||||
{
|
||||
@ -477,6 +479,7 @@ static int add_listener (hio_t* hio, hio_bch_t* addrstr)
|
||||
return -1;
|
||||
}
|
||||
bi.options = HIO_DEV_SCK_BIND_REUSEADDR /*| HIO_DEV_SCK_BIND_REUSEPORT |*/;
|
||||
bi.options = HIO_DEV_SCK_BIND_IGNERR;
|
||||
#if defined(USE_SSL)
|
||||
bi.options |= HIO_DEV_SCK_BIND_SSL;
|
||||
bi.ssl_certfile = "localhost.crt";
|
||||
@ -485,8 +488,8 @@ static int add_listener (hio_t* hio, hio_bch_t* addrstr)
|
||||
|
||||
memset (&mi, 0, HIO_SIZEOF(mi));
|
||||
f = hio_skad_family(&bi.localaddr);
|
||||
if (f == HIO_AF_INET) mi.type = HIO_DEV_SCK_TCP4;
|
||||
else if (f == HIO_AF_INET6) mi.type = HIO_DEV_SCK_TCP6;
|
||||
if (f == HIO_AF_INET) mi.type = g_dev_type4;
|
||||
else if (f == HIO_AF_INET6) mi.type = g_dev_type6;
|
||||
else if (f == HIO_AF_UNIX) mi.type = HIO_DEV_SCK_UNIX;
|
||||
else
|
||||
{
|
||||
@ -553,7 +556,13 @@ int main (int argc, char* argv[])
|
||||
// TODO: use getopt() or something similar
|
||||
for (i = 1; i < argc; )
|
||||
{
|
||||
if (strcmp(argv[i], "-t") == 0)
|
||||
if (strcmp(argv[i], "-s") == 0)
|
||||
{
|
||||
i++;
|
||||
g_dev_type4 = HIO_DEV_SCK_SCTP4;
|
||||
g_dev_type6 = HIO_DEV_SCK_SCTP6;
|
||||
}
|
||||
else if (strcmp(argv[i], "-t") == 0)
|
||||
{
|
||||
i++;
|
||||
if (i < argc)
|
||||
|
@ -269,6 +269,12 @@ enum hio_dev_sck_type_t
|
||||
HIO_DEV_SCK_UDP4,
|
||||
HIO_DEV_SCK_UDP6,
|
||||
|
||||
HIO_DEV_SCK_SCTP4, /* one-to-one sctp stream */
|
||||
HIO_DEV_SCK_SCTP6, /* one-to-one sctp stream */
|
||||
|
||||
HIO_DEV_SCK_SCTP4_SP, /* one-to-one sctp seqpacket */
|
||||
HIO_DEV_SCK_SCTP6_SP, /* one-to-one sctp seqpacket */
|
||||
|
||||
/* ICMP at the IPv4 layer */
|
||||
HIO_DEV_SCK_ICMP4,
|
||||
|
||||
|
@ -249,11 +249,31 @@ static struct sck_type_map_t sck_type_map[] =
|
||||
/* HIO_DEV_SCK_UDP6 */
|
||||
{ AF_INET6, SOCK_DGRAM, 0, 0 },
|
||||
|
||||
#if defined(IPPROTO_SCTP)
|
||||
/* HIO_DEV_SCK_SCTP4 */
|
||||
{ AF_INET, SOCK_STREAM, IPPROTO_SCTP, HIO_DEV_CAP_STREAM },
|
||||
|
||||
/* HIO_DEV_SCK_SCTP6 */
|
||||
{ AF_INET6, SOCK_STREAM, IPPROTO_SCTP, HIO_DEV_CAP_STREAM },
|
||||
|
||||
/* HIO_DEV_SCK_SCTP4_SP - not implemented */
|
||||
{ -1, SOCK_SEQPACKET, IPPROTO_SCTP, 0 },
|
||||
|
||||
/* HIO_DEV_SCK_SCTP6_SP - not implemented */
|
||||
{ -1, SOCK_SEQPACKET, IPPROTO_SCTP, 0 },
|
||||
#else
|
||||
{ -1, 0, 0, 0 },
|
||||
{ -1, 0, 0, 0 },
|
||||
{ -1, 0, 0, 0 },
|
||||
{ -1, 0, 0, 0 },
|
||||
#endif
|
||||
|
||||
/* HIO_DEV_SCK_ICMP4 - IP protocol field is 1 byte only. no byte order conversion is needed */
|
||||
{ AF_INET, SOCK_RAW, IPPROTO_ICMP, 0, },
|
||||
{ AF_INET, SOCK_RAW, IPPROTO_ICMP, 0 },
|
||||
|
||||
/* HIO_DEV_SCK_ICMP6 - IP protocol field is 1 byte only. no byte order conversion is needed */
|
||||
{ AF_INET6, SOCK_RAW, IPPROTO_ICMP, 0, },
|
||||
{ AF_INET6, SOCK_RAW, IPPROTO_ICMP, 0 },
|
||||
|
||||
|
||||
#if defined(AF_PACKET) && (HIO_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
/* HIO_DEV_SCK_ARP - Ethernet type is 2 bytes long. Protocol must be specified in the network byte order */
|
||||
@ -1053,17 +1073,21 @@ static int dev_sck_ioctl (hio_dev_t* dev, int cmd, void* arg)
|
||||
/* TODO: should i make it into bnd->options? HIO_DEV_SCK_BIND_IPV6ONLY? applicable to ipv6 though. */
|
||||
int v = 1;
|
||||
if (setsockopt(rdev->hnd, IPPROTO_IPV6, IPV6_V6ONLY, &v, HIO_SIZEOF(v)) == -1)
|
||||
{
|
||||
if (!(bnd->options & HIO_DEV_SCK_BIND_IGNERR))
|
||||
{
|
||||
hio_seterrbfmtwithsyserr (hio, 0, errno, "unable to set IPV6_V6ONLY");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bnd->options & HIO_DEV_SCK_BIND_BROADCAST)
|
||||
{
|
||||
int v = 1;
|
||||
if (setsockopt(rdev->hnd, SOL_SOCKET, SO_BROADCAST, &v, HIO_SIZEOF(v)) == -1)
|
||||
{
|
||||
/* not affected by HIO_DEV_SCK_BIND_IGNERR */
|
||||
hio_seterrbfmtwithsyserr (hio, 0, errno, "unable to set SO_BROADCAST");
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user