int send_packet( const packet *p, const char *why ) { int ret; mbedtls_net_context *dst = p->dst; /* insert corrupted ApplicationData record? */ if( opt.bad_ad && strcmp( p->type, "ApplicationData" ) == 0 ) { unsigned char buf[MAX_MSG_SIZE]; memcpy( buf, p->buf, p->len ); if( p->len <= 13 ) { mbedtls_printf( " ! can't corrupt empty AD record" ); } else { ++buf[13]; print_packet( p, "corrupted" ); } if( ( ret = dispatch_data( dst, buf, p->len ) ) <= 0 ) { mbedtls_printf( " ! dispatch returned %d\n", ret ); return( ret ); } } print_packet( p, why ); if( ( ret = dispatch_data( dst, p->buf, p->len ) ) <= 0 ) { mbedtls_printf( " ! dispatch returned %d\n", ret ); return( ret ); } /* Don't duplicate Application Data, only handshake covered */ if( opt.duplicate != 0 && strcmp( p->type, "ApplicationData" ) != 0 && rand() % opt.duplicate == 0 ) { print_packet( p, "duplicated" ); if( ( ret = dispatch_data( dst, p->buf, p->len ) ) <= 0 ) { mbedtls_printf( " ! dispatch returned %d\n", ret ); return( ret ); } } return( 0 ); }
static void device_job_rx_loop(struct device *dev) { int obj = 0; ssize_t len = 0; struct input_event event[10]; for (;;) { memset(event, 0, sizeof(event)); len = receive_udp_data(event, sizeof(event)); if (len < 0) { DBG("ERROR : RECEIVING DATA\n"); continue; } else { obj = len/sizeof(struct input_event); dispatch_data(event, dev->ev_desc, obj); } } }
static void process_watch(struct wpas_dbus_priv *priv, DBusWatch *watch, eloop_event_type type) { dbus_connection_ref(priv->con); priv->should_dispatch = 0; if (type == EVENT_TYPE_READ) dbus_watch_handle(watch, DBUS_WATCH_READABLE); else if (type == EVENT_TYPE_WRITE) dbus_watch_handle(watch, DBUS_WATCH_WRITABLE); else if (type == EVENT_TYPE_EXCEPTION) dbus_watch_handle(watch, DBUS_WATCH_ERROR); if (priv->should_dispatch) { dispatch_data(priv->con); priv->should_dispatch = 0; } dbus_connection_unref(priv->con); }
/** * dispatch_initial_dbus_messages - Dispatch initial dbus messages after * claiming bus name * @eloop_ctx: the DBusConnection to dispatch on * @timeout_ctx: unused * * If clients are quick to notice that service claimed its bus name, * there may have been messages that came in before initialization was * all finished. Dispatch those here. */ static void dispatch_initial_dbus_messages(void *eloop_ctx, void *timeout_ctx) { DBusConnection *con = eloop_ctx; dispatch_data(con); }