changed packed definitions

This commit is contained in:
hyung-hwan 2016-04-02 15:52:12 +00:00
parent e122618f71
commit 1e5c54cae0
4 changed files with 63 additions and 38 deletions

View File

@ -130,9 +130,8 @@ am__DEPENDENCIES_1 =
am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
libstio_la_DEPENDENCIES = $(am__DEPENDENCIES_2) libstio_la_DEPENDENCIES = $(am__DEPENDENCIES_2)
am_libstio_la_OBJECTS = libstio_la-stio.lo libstio_la-stio-pro.lo \ am_libstio_la_OBJECTS = libstio_la-stio.lo libstio_la-stio-pro.lo \
libstio_la-stio-sck.lo libstio_la-stio-tcp.lo \ libstio_la-stio-sck.lo libstio_la-stio-tim.lo \
libstio_la-stio-tim.lo libstio_la-stio-tmr.lo \ libstio_la-stio-tmr.lo
libstio_la-stio-udp.lo
libstio_la_OBJECTS = $(am_libstio_la_OBJECTS) libstio_la_OBJECTS = $(am_libstio_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@) AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
@ -382,8 +381,6 @@ pkginclude_HEADERS = \
stio-cmn.h \ stio-cmn.h \
stio-pro.h \ stio-pro.h \
stio-sck.h \ stio-sck.h \
stio-tcp.h \
stio-udp.h \
stio.h stio.h
pkglib_LTLIBRARIES = libstio.la pkglib_LTLIBRARIES = libstio.la
@ -392,10 +389,8 @@ libstio_la_SOURCES = \
stio.c \ stio.c \
stio-pro.c \ stio-pro.c \
stio-sck.c \ stio-sck.c \
stio-tcp.c \
stio-tim.c \ stio-tim.c \
stio-tmr.c \ stio-tmr.c
stio-udp.c
libstio_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) libstio_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
libstio_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) libstio_la_LDFLAGS = $(LDFLAGS_LIB_COMMON)
@ -554,10 +549,8 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-pro.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-pro.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-sck.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-sck.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-tcp.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-tim.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-tim.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-tmr.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-tmr.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-udp.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stio-main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stio-main.Po@am__quote@
@ -603,13 +596,6 @@ libstio_la-stio-sck.lo: stio-sck.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio-sck.lo `test -f 'stio-sck.c' || echo '$(srcdir)/'`stio-sck.c @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio-sck.lo `test -f 'stio-sck.c' || echo '$(srcdir)/'`stio-sck.c
libstio_la-stio-tcp.lo: stio-tcp.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstio_la-stio-tcp.lo -MD -MP -MF $(DEPDIR)/libstio_la-stio-tcp.Tpo -c -o libstio_la-stio-tcp.lo `test -f 'stio-tcp.c' || echo '$(srcdir)/'`stio-tcp.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstio_la-stio-tcp.Tpo $(DEPDIR)/libstio_la-stio-tcp.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stio-tcp.c' object='libstio_la-stio-tcp.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio-tcp.lo `test -f 'stio-tcp.c' || echo '$(srcdir)/'`stio-tcp.c
libstio_la-stio-tim.lo: stio-tim.c libstio_la-stio-tim.lo: stio-tim.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstio_la-stio-tim.lo -MD -MP -MF $(DEPDIR)/libstio_la-stio-tim.Tpo -c -o libstio_la-stio-tim.lo `test -f 'stio-tim.c' || echo '$(srcdir)/'`stio-tim.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstio_la-stio-tim.lo -MD -MP -MF $(DEPDIR)/libstio_la-stio-tim.Tpo -c -o libstio_la-stio-tim.lo `test -f 'stio-tim.c' || echo '$(srcdir)/'`stio-tim.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstio_la-stio-tim.Tpo $(DEPDIR)/libstio_la-stio-tim.Plo @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstio_la-stio-tim.Tpo $(DEPDIR)/libstio_la-stio-tim.Plo
@ -624,13 +610,6 @@ libstio_la-stio-tmr.lo: stio-tmr.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio-tmr.lo `test -f 'stio-tmr.c' || echo '$(srcdir)/'`stio-tmr.c @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio-tmr.lo `test -f 'stio-tmr.c' || echo '$(srcdir)/'`stio-tmr.c
libstio_la-stio-udp.lo: stio-udp.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstio_la-stio-udp.lo -MD -MP -MF $(DEPDIR)/libstio_la-stio-udp.Tpo -c -o libstio_la-stio-udp.lo `test -f 'stio-udp.c' || echo '$(srcdir)/'`stio-udp.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstio_la-stio-udp.Tpo $(DEPDIR)/libstio_la-stio-udp.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stio-udp.c' object='libstio_la-stio-udp.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio-udp.lo `test -f 'stio-udp.c' || echo '$(srcdir)/'`stio-udp.c
stio-main.o: main.c stio-main.o: main.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(stio_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stio-main.o -MD -MP -MF $(DEPDIR)/stio-main.Tpo -c -o stio-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(stio_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stio-main.o -MD -MP -MF $(DEPDIR)/stio-main.Tpo -c -o stio-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/stio-main.Tpo $(DEPDIR)/stio-main.Po @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/stio-main.Tpo $(DEPDIR)/stio-main.Po

View File

@ -404,6 +404,26 @@ static int dev_sck_ioctl (stio_dev_t* dev, int cmd, void* arg)
stio_sckfam_t fam; stio_sckfam_t fam;
int x; int x;
if (bnd->options & STIO_DEV_SCK_BIND_BROADCAST)
{
int v = 1;
if (setsockopt (rdev->sck, SOL_SOCKET, SO_BROADCAST, &v, STIO_SIZEOF(v)) == -1)
{
rdev->stio->errnum = stio_syserrtoerrnum(errno);
return -1;
}
}
if (bnd->options & STIO_DEV_SCK_BIND_REUSEADDR)
{
int v = 1;
if (setsockopt (rdev->sck, SOL_SOCKET, SO_REUSEADDR, &v, STIO_SIZEOF(v)) == -1)
{
rdev->stio->errnum = stio_syserrtoerrnum(errno);
return -1;
}
}
if (stio_getsckadrinfo (dev->stio, &bnd->addr, &sl, &fam) <= -1) return -1; if (stio_getsckadrinfo (dev->stio, &bnd->addr, &sl, &fam) <= -1) return -1;
/* the socket is already non-blocking */ /* the socket is already non-blocking */

View File

@ -142,11 +142,19 @@ struct stio_dev_sck_make_t
stio_dev_sck_on_read_t on_read; stio_dev_sck_on_read_t on_read;
}; };
enum stio_dev_sck_bind_option_t
{
STIO_DEV_SCK_BIND_BROADCAST = (1 << 0),
STIO_DEV_SCK_BIND_REUSEADDR = (1 << 1)
/* TODO: more options --- TRANSPARENT...SO_RCVBUF, SO_SNDBUF, SO_RCVTIMEO, SO_SNDTIMEO, SO_KEEPALIVE */
};
typedef enum stio_dev_sck_bind_option_t stio_dev_sck_bind_option_t;
typedef struct stio_dev_sck_bind_t stio_dev_sck_bind_t; typedef struct stio_dev_sck_bind_t stio_dev_sck_bind_t;
struct stio_dev_sck_bind_t struct stio_dev_sck_bind_t
{ {
int options;
stio_sckadr_t addr; stio_sckadr_t addr;
/*int opts;*/ /* TODO: REUSEADDR , TRANSPARENT, etc or someting?? */
/* TODO: add device name for BIND_TO_DEVICE */ /* TODO: add device name for BIND_TO_DEVICE */
}; };

View File

@ -286,9 +286,6 @@ enum stio_dev_event_t
typedef enum stio_dev_event_t stio_dev_event_t; typedef enum stio_dev_event_t stio_dev_event_t;
/* ========================================================================= */ /* ========================================================================= */
/* TOOD: move these to a separte file */ /* TOOD: move these to a separte file */
@ -305,28 +302,44 @@ typedef enum stio_dev_event_t stio_dev_event_t;
#define STIO_IP4ADR_LEN 4 #define STIO_IP4ADR_LEN 4
#define STIO_IP6ADR_LEN 16 #define STIO_IP6ADR_LEN 16
#if defined(__GNUC__)
# define STIO_PACKED __attribute__((__packed__))
#else
# define STIO_PACKED
# STIO_PACK_PUSH pack(push)
# STIO_PACK_PUSH pack(push)
# STIO_PACK(x) pack(x)
#endif
#if defined(__GNUC__)
/* nothing */
#else
#pragma pack(push) #pragma pack(push)
#pragma pack(1) #pragma pack(1)
struct stio_ethadr_t #endif
struct STIO_PACKED stio_ethadr_t
{ {
stio_uint8_t v[STIO_ETHADR_LEN]; stio_uint8_t v[STIO_ETHADR_LEN];
}; };
typedef struct stio_ethadr_t stio_ethadr_t; typedef struct stio_ethadr_t stio_ethadr_t;
struct stio_ip4adr_t struct STIO_PACKED stio_ip4adr_t
{ {
stio_uint8_t v[STIO_IP4ADR_LEN]; stio_uint8_t v[STIO_IP4ADR_LEN];
}; };
typedef struct stio_ip4adr_t stio_ip4adr_t; typedef struct stio_ip4adr_t stio_ip4adr_t;
struct stio_ip6adr_t struct STIO_PACKED stio_ip6adr_t
{ {
stio_uint8_t v[STIO_IP6ADR_LEN]; stio_uint8_t v[STIO_IP6ADR_LEN];
}; };
typedef struct stio_ip6adr_t stio_ip6adr_t; typedef struct stio_ip6adr_t stio_ip6adr_t;
struct stio_ethhdr_t struct STIO_PACKED stio_ethhdr_t
{ {
stio_uint8_t dest[STIO_ETHADR_LEN]; stio_uint8_t dest[STIO_ETHADR_LEN];
stio_uint8_t source[STIO_ETHADR_LEN]; stio_uint8_t source[STIO_ETHADR_LEN];
@ -334,7 +347,7 @@ struct stio_ethhdr_t
}; };
typedef struct stio_ethhdr_t stio_ethhdr_t; typedef struct stio_ethhdr_t stio_ethhdr_t;
struct stio_arphdr_t struct STIO_PACKED stio_arphdr_t
{ {
stio_uint16_t htype; /* hardware type (ethernet: 0x0001) */ stio_uint16_t htype; /* hardware type (ethernet: 0x0001) */
stio_uint16_t ptype; /* protocol type (ipv4: 0x0800) */ stio_uint16_t ptype; /* protocol type (ipv4: 0x0800) */
@ -345,7 +358,7 @@ struct stio_arphdr_t
typedef struct stio_arphdr_t stio_arphdr_t; typedef struct stio_arphdr_t stio_arphdr_t;
/* arp payload for ipv4 over ethernet */ /* arp payload for ipv4 over ethernet */
struct stio_etharp_t struct STIO_PACKED stio_etharp_t
{ {
stio_uint8_t sha[STIO_ETHADR_LEN]; /* source hardware address */ stio_uint8_t sha[STIO_ETHADR_LEN]; /* source hardware address */
stio_uint8_t spa[STIO_IP4ADR_LEN]; /* source protocol address */ stio_uint8_t spa[STIO_IP4ADR_LEN]; /* source protocol address */
@ -354,14 +367,19 @@ struct stio_etharp_t
}; };
typedef struct stio_etharp_t stio_etharp_t; typedef struct stio_etharp_t stio_etharp_t;
struct stio_etharp_pkt_t struct STIO_PACKED stio_etharp_pkt_t
{ {
stio_ethhdr_t ethhdr; stio_ethhdr_t ethhdr;
stio_arphdr_t arphdr; stio_arphdr_t arphdr;
stio_etharp_t arppld; stio_etharp_t arppld;
}; };
typedef struct stio_etharp_pkt_t stio_etharp_pkt_t; typedef struct stio_etharp_pkt_t stio_etharp_pkt_t;
#if defined(__GNUC__)
/* nothing */
#else
#pragma pack(pop) #pragma pack(pop)
#endif
/* ========================================================================= */ /* ========================================================================= */